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