Skip to content

Commit 381e141

Browse files
committed
Auth functions now take strings
1 parent 95e7b5f commit 381e141

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

tests/mock_vws/fixtures/prepared_requests.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def _add_target(
4949

5050
content = bytes(json.dumps(data), encoding='utf-8')
5151

52-
access_key = vuforia_database.server_access_key
53-
secret_key = vuforia_database.server_secret_key
52+
access_key = vuforia_database.server_access_key.decode()
53+
secret_key = vuforia_database.server_secret_key.decode()
5454
authorization_string = authorization_header(
5555
access_key=access_key,
5656
secret_key=secret_key,
@@ -102,8 +102,8 @@ def _delete_target(
102102
method = DELETE
103103
content = b''
104104

105-
access_key = vuforia_database.server_access_key
106-
secret_key = vuforia_database.server_secret_key
105+
access_key = vuforia_database.server_access_key.decode()
106+
secret_key = vuforia_database.server_secret_key.decode()
107107
authorization_string = authorization_header(
108108
access_key=access_key,
109109
secret_key=secret_key,
@@ -147,8 +147,8 @@ def _database_summary(vuforia_database: VuforiaDatabase) -> Endpoint:
147147

148148
content = b''
149149

150-
access_key = vuforia_database.server_access_key
151-
secret_key = vuforia_database.server_secret_key
150+
access_key = vuforia_database.server_access_key.decode()
151+
secret_key = vuforia_database.server_secret_key.decode()
152152
authorization_string = authorization_header(
153153
access_key=access_key,
154154
secret_key=secret_key,
@@ -201,8 +201,8 @@ def _get_duplicates(
201201

202202
content = b''
203203

204-
access_key = vuforia_database.server_access_key
205-
secret_key = vuforia_database.server_secret_key
204+
access_key = vuforia_database.server_access_key.decode()
205+
secret_key = vuforia_database.server_secret_key.decode()
206206
authorization_string = authorization_header(
207207
access_key=access_key,
208208
secret_key=secret_key,
@@ -254,8 +254,8 @@ def _get_target(
254254

255255
content = b''
256256

257-
access_key = vuforia_database.server_access_key
258-
secret_key = vuforia_database.server_secret_key
257+
access_key = vuforia_database.server_access_key.decode()
258+
secret_key = vuforia_database.server_secret_key.decode()
259259
authorization_string = authorization_header(
260260
access_key=access_key,
261261
secret_key=secret_key,
@@ -300,8 +300,8 @@ def _target_list(vuforia_database: VuforiaDatabase) -> Endpoint:
300300

301301
content = b''
302302

303-
access_key = vuforia_database.server_access_key
304-
secret_key = vuforia_database.server_secret_key
303+
access_key = vuforia_database.server_access_key.decode()
304+
secret_key = vuforia_database.server_secret_key.decode()
305305
authorization_string = authorization_header(
306306
access_key=access_key,
307307
secret_key=secret_key,
@@ -353,8 +353,8 @@ def _target_summary(
353353

354354
content = b''
355355

356-
access_key = vuforia_database.server_access_key
357-
secret_key = vuforia_database.server_secret_key
356+
access_key = vuforia_database.server_access_key.decode()
357+
secret_key = vuforia_database.server_secret_key.decode()
358358
authorization_string = authorization_header(
359359
access_key=access_key,
360360
secret_key=secret_key,
@@ -408,8 +408,8 @@ def _update_target(
408408
date = rfc_1123_date()
409409
method = PUT
410410

411-
access_key = vuforia_database.server_access_key
412-
secret_key = vuforia_database.server_secret_key
411+
access_key = vuforia_database.server_access_key.decode()
412+
secret_key = vuforia_database.server_secret_key.decode()
413413
authorization_string = authorization_header(
414414
access_key=access_key,
415415
secret_key=secret_key,
@@ -460,8 +460,8 @@ def _query(
460460

461461
content, content_type_header = encode_multipart_formdata(files)
462462

463-
access_key = vuforia_database.client_access_key
464-
secret_key = vuforia_database.client_secret_key
463+
access_key = vuforia_database.client_access_key.decode()
464+
secret_key = vuforia_database.client_secret_key.decode()
465465
authorization_string = authorization_header(
466466
access_key=access_key,
467467
secret_key=secret_key,

tests/mock_vws/test_query.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def test_incorrect_no_boundary(
7575
content, _ = encode_multipart_formdata(body)
7676
method = POST
7777

78-
access_key = vuforia_database.client_access_key
79-
secret_key = vuforia_database.client_secret_key
78+
access_key = vuforia_database.client_access_key.decode()
79+
secret_key = vuforia_database.client_secret_key.decode()
8080
authorization_string = authorization_header(
8181
access_key=access_key,
8282
secret_key=secret_key,
@@ -126,8 +126,8 @@ def test_incorrect_with_boundary(
126126

127127
content_type = 'text/html'
128128

129-
access_key = vuforia_database.client_access_key
130-
secret_key = vuforia_database.client_secret_key
129+
access_key = vuforia_database.client_access_key.decode()
130+
secret_key = vuforia_database.client_secret_key.decode()
131131
authorization_string = authorization_header(
132132
access_key=access_key,
133133
secret_key=secret_key,
@@ -185,8 +185,8 @@ def test_no_boundary(
185185
content, _ = encode_multipart_formdata(body)
186186
method = POST
187187

188-
access_key = vuforia_database.client_access_key
189-
secret_key = vuforia_database.client_secret_key
188+
access_key = vuforia_database.client_access_key.decode()
189+
secret_key = vuforia_database.client_secret_key.decode()
190190
authorization_string = authorization_header(
191191
access_key=access_key,
192192
secret_key=secret_key,
@@ -237,8 +237,8 @@ def test_bogus_boundary(
237237
content, _ = encode_multipart_formdata(body)
238238
method = POST
239239

240-
access_key = vuforia_database.client_access_key
241-
secret_key = vuforia_database.client_secret_key
240+
access_key = vuforia_database.client_access_key.decode()
241+
secret_key = vuforia_database.client_secret_key.decode()
242242
authorization_string = authorization_header(
243243
access_key=access_key,
244244
secret_key=secret_key,
@@ -290,8 +290,8 @@ def test_extra_section(
290290
content, content_type_header = encode_multipart_formdata(body)
291291
method = POST
292292

293-
access_key = vuforia_database.client_access_key
294-
secret_key = vuforia_database.client_secret_key
293+
access_key = vuforia_database.client_access_key.decode()
294+
secret_key = vuforia_database.client_secret_key.decode()
295295
authorization_string = authorization_header(
296296
access_key=access_key,
297297
secret_key=secret_key,
@@ -891,8 +891,8 @@ def test_valid(
891891
content, content_type_header = encode_multipart_formdata(body)
892892
method = POST
893893

894-
access_key = vuforia_database.client_access_key
895-
secret_key = vuforia_database.client_secret_key
894+
access_key = vuforia_database.client_access_key.decode()
895+
secret_key = vuforia_database.client_secret_key.decode()
896896
authorization_string = authorization_header(
897897
access_key=access_key,
898898
secret_key=secret_key,
@@ -936,8 +936,8 @@ def test_invalid(
936936
content, content_type_header = encode_multipart_formdata(body)
937937
method = POST
938938

939-
access_key = vuforia_database.client_access_key
940-
secret_key = vuforia_database.client_secret_key
939+
access_key = vuforia_database.client_access_key.decode()
940+
secret_key = vuforia_database.client_secret_key.decode()
941941
authorization_string = authorization_header(
942942
access_key=access_key,
943943
secret_key=secret_key,
@@ -1737,8 +1737,8 @@ def test_date_formats(
17371737
content, content_type_header = encode_multipart_formdata(body)
17381738
method = POST
17391739

1740-
access_key = vuforia_database.client_access_key
1741-
secret_key = vuforia_database.client_secret_key
1740+
access_key = vuforia_database.client_access_key.decode()
1741+
secret_key = vuforia_database.client_secret_key.decode()
17421742
authorization_string = authorization_header(
17431743
access_key=access_key,
17441744
secret_key=secret_key,

tests/mock_vws/utils/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ class Endpoint:
3333
successful_headers_result_code: ResultCodes
3434
successful_headers_status_code: int
3535
auth_header_content_type: str
36-
access_key: bytes
37-
secret_key: bytes
36+
access_key: str
37+
secret_key: str
3838

3939
def __init__(
4040
self,
4141
prepared_request: requests.PreparedRequest,
4242
successful_headers_result_code: ResultCodes,
4343
successful_headers_status_code: int,
44-
access_key: bytes,
45-
secret_key: bytes,
44+
access_key: str,
45+
secret_key: str,
4646
) -> None:
4747
"""
4848
Args:
@@ -99,8 +99,8 @@ def add_target_to_vws(
9999
content = bytes(json.dumps(data), encoding='utf-8')
100100

101101
authorization_string = authorization_header(
102-
access_key=vuforia_database.server_access_key,
103-
secret_key=vuforia_database.server_secret_key,
102+
access_key=vuforia_database.server_access_key.decode(),
103+
secret_key=vuforia_database.server_secret_key.decode(),
104104
method=POST,
105105
content=content,
106106
content_type=content_type,
@@ -228,8 +228,8 @@ def target_api_request(
228228
content_type = 'application/json'
229229

230230
signature_string = authorization_header(
231-
access_key=server_access_key,
232-
secret_key=server_secret_key,
231+
access_key=server_access_key.decode(),
232+
secret_key=server_secret_key.decode(),
233233
method=method,
234234
content=content,
235235
content_type=content_type,
@@ -306,8 +306,8 @@ def update_target(
306306
content = bytes(json.dumps(data), encoding='utf-8')
307307

308308
authorization_string = authorization_header(
309-
access_key=vuforia_database.server_access_key,
310-
secret_key=vuforia_database.server_secret_key,
309+
access_key=vuforia_database.server_access_key.decode(),
310+
secret_key=vuforia_database.server_secret_key.decode(),
311311
method=PUT,
312312
content=content,
313313
content_type=content_type,
@@ -399,8 +399,8 @@ def query(
399399
content, content_type_header = encode_multipart_formdata(body)
400400
method = POST
401401

402-
access_key = vuforia_database.client_access_key
403-
secret_key = vuforia_database.client_secret_key
402+
access_key = vuforia_database.client_access_key.decode()
403+
secret_key = vuforia_database.client_secret_key.decode()
404404
authorization_string = authorization_header(
405405
access_key=access_key,
406406
secret_key=secret_key,

tests/mock_vws/utils/authorization.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def rfc_1123_date() -> str:
2828

2929

3030
def authorization_header( # pylint: disable=too-many-arguments
31-
access_key: bytes,
32-
secret_key: bytes,
31+
access_key: str,
32+
secret_key: str,
3333
method: str,
3434
content: bytes,
3535
content_type: str,
@@ -74,11 +74,11 @@ def authorization_header( # pylint: disable=too-many-arguments
7474
]
7575
string_to_sign = '\n'.join(components_to_sign)
7676
signature = compute_hmac_base64(
77-
key=secret_key,
77+
key=secret_key.encode(),
7878
data=bytes(
7979
string_to_sign,
8080
encoding='utf-8',
8181
),
8282
)
83-
auth_header = b'VWS %s:%s' % (access_key, signature)
83+
auth_header = b'VWS %s:%s' % (access_key.encode(), signature)
8484
return auth_header

0 commit comments

Comments
 (0)