Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICBC Registration Query Fixes #295

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions python/common/test_splunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def test_splunk_logs_icbc_get_driver_event():
@responses.activate
def test_splunk_logs_icbc_get_vehicle_event():
username = 'someuser@bceid'
plate_number = 'RXC234'
registration_number = '10006241'
expected_payload = {
'event': 'icbc_get_vehicle',
'source': 'be78d6',
'queried_plate': plate_number
'queried_registration_number': registration_number
}

responses.add(responses.GET,
Expand All @@ -82,7 +82,7 @@ def test_splunk_logs_icbc_get_vehicle_event():

is_okay, args = splunk_get_vehicle(splunk_data=expected_payload,
config=Config,
plate_number=plate_number,
registration_number=registration_number,
username=username,
user_guid='')
log_to_splunk(**args)
Expand All @@ -93,5 +93,5 @@ def test_splunk_logs_icbc_get_vehicle_event():
"event": 'icbc_get_vehicle',
"user_guid": '',
"username": "someuser@bceid",
'queried_plate': plate_number
'queried_registration_number': registration_number
}, "source": "be78d6"}
2 changes: 1 addition & 1 deletion python/prohibition_web_svc/blueprints/icbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_vehicle(registration_number):
{"try": splunk.log_to_splunk, "fail": []}
],
required_permission='vehicle-get',
registration_number=registration_number.upper(),
registration_number=registration_number,
request=request,
config=Config)
return kwargs.get('response')
Expand Down
2 changes: 1 addition & 1 deletion python/prohibition_web_svc/middleware/icbc_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ def splunk_get_vehicle(**kwargs) -> tuple:
"event": "icbc_get_vehicle",
"username": kwargs.get('username'),
"user_guid": kwargs.get('user_guid'),
"queried_plate": kwargs.get('plate_number')
"queried_registration_number": kwargs.get('registration_number')
}
return True, kwargs
90 changes: 45 additions & 45 deletions python/prohibition_web_svc/tests/test_icbc_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_authorized_user_gets_vehicle_not_found(as_guest, monkeypatch, roles):
'{}/vehicles?{}'.format(
Config.ICBC_API_ROOT,
urllib.parse.urlencode({
"plateNumber": "AAAAA",
"registrationNumber": "00000000",
# "effectiveDate": datetime.now().astimezone().replace(microsecond=0).isoformat()
})
),
Expand All @@ -146,7 +146,7 @@ def test_authorized_user_gets_vehicle_not_found(as_guest, monkeypatch, roles):
responses.add(responses.POST, "{}:{}/services/collector".format(
Config.SPLUNK_HOST, Config.SPLUNK_PORT), status=200)

resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/AAAAA",
resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/00000000",
follow_redirects=True,
content_type="application/json",
headers=_get_keycloak_auth_header(_get_keycloak_access_token()))
Expand All @@ -161,7 +161,7 @@ def test_authorized_user_gets_vehicle_not_found(as_guest, monkeypatch, roles):
'event': 'icbc_get_vehicle',
'username': 'larry@idir',
'user_guid': 'larry@idir',
'queried_plate': 'AAAAA',
'queried_registration_number': '00000000',
},
'source': 'be78d6'
})
Expand All @@ -176,7 +176,7 @@ def test_authorized_user_gets_vehicle(as_guest, monkeypatch, roles):
'{}/vehicles?{}'.format(
Config.ICBC_API_ROOT,
urllib.parse.urlencode({
"plateNumber": "LD626J",
"registrationNumber": "03371224",
# "effectiveDate": datetime.now().astimezone().replace(microsecond=0).isoformat()
})
),
Expand All @@ -186,61 +186,61 @@ def test_authorized_user_gets_vehicle(as_guest, monkeypatch, roles):
responses.add(responses.POST, "{}:{}/services/collector".format(
Config.SPLUNK_HOST, Config.SPLUNK_PORT), status=200)

resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/LD626J",
resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/03371224",
follow_redirects=True,
content_type="application/json",
headers=_get_keycloak_auth_header(_get_keycloak_access_token()))
assert resp.status_code == 200
assert 'plateNumber' in resp.json[0]
assert resp.json[0]['plateNumber'] == "LD626J"
assert 'registrationNumber' in resp.json[0]
assert resp.json[0]['registrationNumber'] == "03371224"
assert responses.calls[0].request.headers['loginUserId'] == 'larry@idir'
assert responses.calls[1].request.body.decode() == json.dumps({
'event': {
'event': 'icbc_get_vehicle',
'username': 'larry@idir',
'user_guid': 'larry@idir',
'queried_plate': 'LD626J',
'queried_registration_number': '03371224',
},
'source': 'be78d6'
})


@responses.activate
def test_request_for_licence_plate_using_lowercase_automatically_converted_to_upper(as_guest, monkeypatch, roles):
monkeypatch.setattr(middleware, "get_keycloak_certificates", _mock_keycloak_certificates)
monkeypatch.setattr(middleware, "decode_keycloak_access_token", _get_authorized_user)

responses.add(responses.GET,
'{}/vehicles?{}'.format(
Config.ICBC_API_ROOT,
urllib.parse.urlencode({
"plateNumber": "LD626J",
# "effectiveDate": datetime.now().astimezone().replace(microsecond=0).isoformat()
})
),
json=sample_vehicle_response(),
status=200)

responses.add(responses.POST, "{}:{}/services/collector".format(
Config.SPLUNK_HOST, Config.SPLUNK_PORT), status=200)

resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/ld626j",
follow_redirects=True,
content_type="application/json",
headers=_get_keycloak_auth_header(_get_keycloak_access_token()))
assert resp.status_code == 200
assert 'plateNumber' in resp.json[0]
assert resp.json[0]['plateNumber'] == "LD626J"
assert responses.calls[0].request.headers['loginUserId'] == 'larry@idir'
assert responses.calls[1].request.body.decode() == json.dumps({
'event': {
'event': 'icbc_get_vehicle',
'username': 'larry@idir',
'user_guid': 'larry@idir',
'queried_plate': 'LD626J',
},
'source': 'be78d6'
})
# @responses.activate
# def test_request_for_licence_plate_using_lowercase_automatically_converted_to_upper(as_guest, monkeypatch, roles):
# monkeypatch.setattr(middleware, "get_keycloak_certificates", _mock_keycloak_certificates)
# monkeypatch.setattr(middleware, "decode_keycloak_access_token", _get_authorized_user)

# responses.add(responses.GET,
# '{}/vehicles?{}'.format(
# Config.ICBC_API_ROOT,
# urllib.parse.urlencode({
# "plateNumber": "LD626J",
# # "effectiveDate": datetime.now().astimezone().replace(microsecond=0).isoformat()
# })
# ),
# json=sample_vehicle_response(),
# status=200)

# responses.add(responses.POST, "{}:{}/services/collector".format(
# Config.SPLUNK_HOST, Config.SPLUNK_PORT), status=200)

# resp = as_guest.get(Config.URL_PREFIX + "/api/v1/icbc/vehicles/ld626j",
# follow_redirects=True,
# content_type="application/json",
# headers=_get_keycloak_auth_header(_get_keycloak_access_token()))
# assert resp.status_code == 200
# assert 'plateNumber' in resp.json[0]
# assert resp.json[0]['plateNumber'] == "LD626J"
# assert responses.calls[0].request.headers['loginUserId'] == 'larry@idir'
# assert responses.calls[1].request.body.decode() == json.dumps({
# 'event': {
# 'event': 'icbc_get_vehicle',
# 'username': 'larry@idir',
# 'user_guid': 'larry@idir',
# 'queried_registration_number': 'LD626J',
# },
# 'source': 'be78d6'
# })


def test_unauthorized_user_cannot_get_vehicle(as_guest, monkeypatch, roles):
Expand Down Expand Up @@ -372,7 +372,7 @@ def _vehicle_not_found() -> dict:
"code": 404,
"message": "Not Found",
"description": "vehicle not found",
"request_uri": "/vehicles?plateNumber=LD626J",
"request_uri": "/vehicles?registrationNumber=0000000",
"request_id": "716243aa-ca18-441d-aa3e-e6e8776ca825"
}
}
Expand Down
Loading