@@ -113,15 +113,21 @@ def test_init(self):
113
113
metrics = pretend .stub ()
114
114
session = pretend .stub ()
115
115
token = "api_token"
116
+ url = "http://foo"
116
117
cache = utils .PublicKeysCache (cache_time = 12 )
117
118
118
119
verifier = utils .GitHubTokenScanningPayloadVerifier (
119
- session = session , metrics = metrics , api_token = token , public_keys_cache = cache
120
+ api_url = url ,
121
+ session = session ,
122
+ metrics = metrics ,
123
+ api_token = token ,
124
+ public_keys_cache = cache ,
120
125
)
121
126
122
127
assert verifier ._session is session
123
128
assert verifier ._metrics is metrics
124
129
assert verifier ._api_token == token
130
+ assert verifier ._api_url == url
125
131
assert verifier ._public_keys_cache is cache
126
132
127
133
def test_verify_cache_miss (self ):
@@ -147,6 +153,7 @@ def test_verify_cache_miss(self):
147
153
metrics = pretend .stub (increment = pretend .call_recorder (lambda str : None ))
148
154
cache = utils .PublicKeysCache (cache_time = 12 )
149
155
verifier = utils .GitHubTokenScanningPayloadVerifier (
156
+ api_url = "http://foo" ,
150
157
session = session ,
151
158
metrics = metrics ,
152
159
api_token = "api-token" ,
@@ -188,6 +195,7 @@ def test_verify_cache_hit(self):
188
195
}
189
196
]
190
197
verifier = utils .GitHubTokenScanningPayloadVerifier (
198
+ api_url = "http://foo" ,
191
199
session = session ,
192
200
metrics = metrics ,
193
201
api_token = "api-token" ,
@@ -218,6 +226,7 @@ def test_verify_error(self):
218
226
metrics = pretend .stub (increment = pretend .call_recorder (lambda str : None ))
219
227
cache = utils .PublicKeysCache (cache_time = 12 )
220
228
verifier = utils .GitHubTokenScanningPayloadVerifier (
229
+ api_url = "http://foo" ,
221
230
session = pretend .stub (),
222
231
metrics = metrics ,
223
232
api_token = "api-token" ,
@@ -236,6 +245,7 @@ def test_verify_error(self):
236
245
237
246
def test_headers_auth_no_token (self ):
238
247
headers = utils .GitHubTokenScanningPayloadVerifier (
248
+ api_url = "http://foo" ,
239
249
session = pretend .stub (),
240
250
metrics = pretend .stub (),
241
251
api_token = None ,
@@ -245,6 +255,7 @@ def test_headers_auth_no_token(self):
245
255
246
256
def test_headers_auth_token (self ):
247
257
headers = utils .GitHubTokenScanningPayloadVerifier (
258
+ api_url = "http://foo" ,
248
259
session = pretend .stub (),
249
260
metrics = pretend .stub (),
250
261
api_token = "api-token" ,
@@ -273,6 +284,7 @@ def test_retrieve_public_key_payload(self):
273
284
metrics = pretend .stub (increment = pretend .call_recorder (lambda str : None ))
274
285
275
286
verifier = utils .GitHubTokenScanningPayloadVerifier (
287
+ api_url = "http://foo" ,
276
288
session = session ,
277
289
metrics = metrics ,
278
290
api_token = "api-token" ,
@@ -281,7 +293,7 @@ def test_retrieve_public_key_payload(self):
281
293
assert verifier ._retrieve_public_key_payload () == meta_payload
282
294
assert session .get .calls == [
283
295
pretend .call (
284
- "https ://api.github.com/meta/public_keys/token_scanning " ,
296
+ "http ://foo " ,
285
297
headers = {"Authorization" : "token api-token" },
286
298
)
287
299
]
@@ -294,7 +306,10 @@ def test_get_cached_public_key_cache_hit(self):
294
306
cache .set (now = time .time (), value = cache_value )
295
307
296
308
verifier = utils .GitHubTokenScanningPayloadVerifier (
297
- session = session , metrics = metrics , public_keys_cache = cache
309
+ api_url = "http://foo" ,
310
+ session = session ,
311
+ metrics = metrics ,
312
+ public_keys_cache = cache ,
298
313
)
299
314
300
315
assert verifier ._get_cached_public_keys () is cache_value
@@ -305,7 +320,10 @@ def test_get_cached_public_key_cache_miss_no_cache(self):
305
320
cache = utils .PublicKeysCache (cache_time = 12 )
306
321
307
322
verifier = utils .GitHubTokenScanningPayloadVerifier (
308
- session = session , metrics = metrics , public_keys_cache = cache
323
+ api_url = "http://foo" ,
324
+ session = session ,
325
+ metrics = metrics ,
326
+ public_keys_cache = cache ,
309
327
)
310
328
311
329
with pytest .raises (utils .CacheMiss ):
@@ -321,7 +339,10 @@ def test_retrieve_public_key_payload_http_error(self):
321
339
get = lambda * a , ** k : response ,
322
340
)
323
341
verifier = utils .GitHubTokenScanningPayloadVerifier (
324
- session = session , metrics = pretend .stub (), public_keys_cache = pretend .stub ()
342
+ api_url = "http://foo" ,
343
+ session = session ,
344
+ metrics = pretend .stub (),
345
+ public_keys_cache = pretend .stub (),
325
346
)
326
347
with pytest .raises (utils .GitHubPublicKeyMetaAPIError ) as exc :
327
348
verifier ._retrieve_public_key_payload ()
@@ -337,7 +358,10 @@ def test_retrieve_public_key_payload_json_error(self):
337
358
)
338
359
session = pretend .stub (get = lambda * a , ** k : response )
339
360
verifier = utils .GitHubTokenScanningPayloadVerifier (
340
- session = session , metrics = pretend .stub (), public_keys_cache = pretend .stub ()
361
+ api_url = "http://foo" ,
362
+ session = session ,
363
+ metrics = pretend .stub (),
364
+ public_keys_cache = pretend .stub (),
341
365
)
342
366
with pytest .raises (utils .GitHubPublicKeyMetaAPIError ) as exc :
343
367
verifier ._retrieve_public_key_payload ()
@@ -349,7 +373,10 @@ def test_retrieve_public_key_payload_connection_error(self):
349
373
session = pretend .stub (get = pretend .raiser (requests .ConnectionError ))
350
374
351
375
verifier = utils .GitHubTokenScanningPayloadVerifier (
352
- session = session , metrics = pretend .stub (), public_keys_cache = pretend .stub ()
376
+ api_url = "http://foo" ,
377
+ session = session ,
378
+ metrics = pretend .stub (),
379
+ public_keys_cache = pretend .stub (),
353
380
)
354
381
355
382
with pytest .raises (utils .GitHubPublicKeyMetaAPIError ) as exc :
@@ -374,7 +401,10 @@ def test_extract_public_keys(self):
374
401
}
375
402
cache = utils .PublicKeysCache (cache_time = 12 )
376
403
verifier = utils .GitHubTokenScanningPayloadVerifier (
377
- session = pretend .stub (), metrics = pretend .stub (), public_keys_cache = cache
404
+ api_url = "http://foo" ,
405
+ session = pretend .stub (),
406
+ metrics = pretend .stub (),
407
+ public_keys_cache = cache ,
378
408
)
379
409
380
410
keys = verifier ._extract_public_keys (pubkey_api_data = meta_payload )
@@ -414,7 +444,10 @@ def test_extract_public_keys(self):
414
444
def test_extract_public_keys_error (self , payload , expected ):
415
445
cache = utils .PublicKeysCache (cache_time = 12 )
416
446
verifier = utils .GitHubTokenScanningPayloadVerifier (
417
- session = pretend .stub (), metrics = pretend .stub (), public_keys_cache = cache
447
+ api_url = "http://foo" ,
448
+ session = pretend .stub (),
449
+ metrics = pretend .stub (),
450
+ public_keys_cache = cache ,
418
451
)
419
452
420
453
with pytest .raises (utils .GitHubPublicKeyMetaAPIError ) as exc :
@@ -426,6 +459,7 @@ def test_extract_public_keys_error(self, payload, expected):
426
459
427
460
def test_check_public_key (self ):
428
461
verifier = utils .GitHubTokenScanningPayloadVerifier (
462
+ api_url = "http://foo" ,
429
463
session = pretend .stub (),
430
464
metrics = pretend .stub (),
431
465
public_keys_cache = pretend .stub (),
@@ -439,6 +473,7 @@ def test_check_public_key(self):
439
473
440
474
def test_check_public_key_error (self ):
441
475
verifier = utils .GitHubTokenScanningPayloadVerifier (
476
+ api_url = "http://foo" ,
442
477
session = pretend .stub (),
443
478
metrics = pretend .stub (),
444
479
public_keys_cache = pretend .stub (),
@@ -452,6 +487,7 @@ def test_check_public_key_error(self):
452
487
453
488
def test_check_signature (self ):
454
489
verifier = utils .GitHubTokenScanningPayloadVerifier (
490
+ api_url = "http://foo" ,
455
491
session = pretend .stub (),
456
492
metrics = pretend .stub (),
457
493
public_keys_cache = pretend .stub (),
@@ -481,6 +517,7 @@ def test_check_signature(self):
481
517
482
518
def test_check_signature_invalid_signature (self ):
483
519
verifier = utils .GitHubTokenScanningPayloadVerifier (
520
+ api_url = "http://foo" ,
484
521
session = pretend .stub (),
485
522
metrics = pretend .stub (),
486
523
public_keys_cache = pretend .stub (),
@@ -512,6 +549,7 @@ def test_check_signature_invalid_signature(self):
512
549
513
550
def test_check_signature_invalid_crypto (self ):
514
551
verifier = utils .GitHubTokenScanningPayloadVerifier (
552
+ api_url = "http://foo" ,
515
553
session = pretend .stub (),
516
554
metrics = pretend .stub (),
517
555
public_keys_cache = pretend .stub (),
0 commit comments