65
65
from warehouse .subscriptions import services as subscription_services
66
66
from warehouse .subscriptions .interfaces import IBillingService , ISubscriptionService
67
67
68
+ from .common .constants import REMOTE_ADDR , REMOTE_ADDR_HASHED
68
69
from .common .db import Session
69
70
from .common .db .accounts import EmailFactory , UserFactory
70
71
from .common .db .ip_addresses import IpAddressFactory
@@ -119,28 +120,6 @@ def metrics():
119
120
)
120
121
121
122
122
- @pytest .fixture
123
- def remote_addr ():
124
- return "1.2.3.4"
125
-
126
-
127
- @pytest .fixture
128
- def remote_addr_hashed ():
129
- """
130
- Static output of `hashlib.sha256(remote_addr.encode("utf8")).hexdigest()`
131
- Created statically to prevent needing to calculate it every run.
132
- """
133
- return "6694f83c9f476da31f5df6bcc520034e7e57d421d247b9d34f49edbfc84a764c"
134
-
135
-
136
- @pytest .fixture
137
- def remote_addr_salted ():
138
- """
139
- Output of `hashlib.sha256((remote_addr + "pepa").encode("utf8")).hexdigest()`
140
- """
141
- return "a69a49383d81404e4b1df297c7baa28e1cd6c4ee1495ed5d0ab165a63a147763"
142
-
143
-
144
123
@pytest .fixture
145
124
def jinja ():
146
125
dir_name = os .path .join (os .path .dirname (warehouse .__file__ ))
@@ -212,12 +191,12 @@ def pyramid_services(
212
191
213
192
214
193
@pytest .fixture
215
- def pyramid_request (pyramid_services , jinja , remote_addr , remote_addr_hashed ):
194
+ def pyramid_request (pyramid_services , jinja ):
216
195
pyramid .testing .setUp ()
217
196
dummy_request = pyramid .testing .DummyRequest ()
218
197
dummy_request .find_service = pyramid_services .find_service
219
- dummy_request .remote_addr = remote_addr
220
- dummy_request .remote_addr_hashed = remote_addr_hashed
198
+ dummy_request .remote_addr = REMOTE_ADDR
199
+ dummy_request .remote_addr_hashed = REMOTE_ADDR_HASHED
221
200
dummy_request .authentication_method = pretend .stub ()
222
201
dummy_request ._unauthenticated_userid = None
223
202
dummy_request .user = None
@@ -436,9 +415,9 @@ def db_session(app_config):
436
415
437
416
438
417
@pytest .fixture
439
- def user_service (db_session , metrics , remote_addr ):
418
+ def user_service (db_session , metrics ):
440
419
return account_services .DatabaseUserService (
441
- db_session , metrics = metrics , remote_addr = remote_addr
420
+ db_session , metrics = metrics , remote_addr = REMOTE_ADDR
442
421
)
443
422
444
423
@@ -462,91 +441,6 @@ def github_oidc_service(db_session):
462
441
)
463
442
464
443
465
- @pytest .fixture
466
- def dummy_github_oidc_jwt ():
467
- # {
468
- # "jti": "6e67b1cb-2b8d-4be5-91cb-757edb2ec970",
469
- # "sub": "repo:foo/bar",
470
- # "aud": "pypi",
471
- # "ref": "fake",
472
- # "sha": "fake",
473
- # "repository": "foo/bar",
474
- # "repository_owner": "foo",
475
- # "repository_owner_id": "123",
476
- # "run_id": "fake",
477
- # "run_number": "fake",
478
- # "run_attempt": "1",
479
- # "repository_id": "fake",
480
- # "actor_id": "fake",
481
- # "actor": "foo",
482
- # "workflow": "fake",
483
- # "head_ref": "fake",
484
- # "base_ref": "fake",
485
- # "event_name": "fake",
486
- # "ref_type": "fake",
487
- # "environment": "fake",
488
- # "job_workflow_ref": "foo/bar/.github/workflows/example.yml@fake",
489
- # "iss": "https://token.actions.githubusercontent.com",
490
- # "nbf": 1650663265,
491
- # "exp": 1650664165,
492
- # "iat": 1650663865
493
- # }
494
- return (
495
- "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2ZTY3YjFjYi0yYjhkLTRiZ"
496
- "TUtOTFjYi03NTdlZGIyZWM5NzAiLCJzdWIiOiJyZXBvOmZvby9iYXIiLCJhdWQiOiJweXB"
497
- "pIiwicmVmIjoiZmFrZSIsInNoYSI6ImZha2UiLCJyZXBvc2l0b3J5IjoiZm9vL2JhciIsI"
498
- "nJlcG9zaXRvcnlfb3duZXIiOiJmb28iLCJyZXBvc2l0b3J5X293bmVyX2lkIjoiMTIzIiw"
499
- "icnVuX2lkIjoiZmFrZSIsInJ1bl9udW1iZXIiOiJmYWtlIiwicnVuX2F0dGVtcHQiOiIxI"
500
- "iwicmVwb3NpdG9yeV9pZCI6ImZha2UiLCJhY3Rvcl9pZCI6ImZha2UiLCJhY3RvciI6ImZ"
501
- "vbyIsIndvcmtmbG93IjoiZmFrZSIsImhlYWRfcmVmIjoiZmFrZSIsImJhc2VfcmVmIjoiZ"
502
- "mFrZSIsImV2ZW50X25hbWUiOiJmYWtlIiwicmVmX3R5cGUiOiJmYWtlIiwiZW52aXJvbm1"
503
- "lbnQiOiJmYWtlIiwiam9iX3dvcmtmbG93X3JlZiI6ImZvby9iYXIvLmdpdGh1Yi93b3JrZ"
504
- "mxvd3MvZXhhbXBsZS55bWxAZmFrZSIsImlzcyI6Imh0dHBzOi8vdG9rZW4uYWN0aW9ucy5"
505
- "naXRodWJ1c2VyY29udGVudC5jb20iLCJuYmYiOjE2NTA2NjMyNjUsImV4cCI6MTY1MDY2N"
506
- "DE2NSwiaWF0IjoxNjUwNjYzODY1fQ.f-FMv5FF5sdxAWeUilYDt9NoE7Et0vbdNhK32c2o"
507
- "C-E"
508
- )
509
-
510
-
511
- @pytest .fixture
512
- def dummy_activestate_oidc_jwt ():
513
- # {
514
- # "jti": "6e67b1cb-2b8d-4be5-91cb-757edb2ec970",
515
- # "sub": "org:fakeorg:project:fakeproject",
516
- # "aud": "pypi",
517
- # "actor_id": "fake",
518
- # "actor": "foo",
519
- # "oraganization_id": "7e67b1cb-2b8d-4be5-91cb-757edb2ec970",
520
- # "organization": "fakeorg",
521
- # "project_visibility": "private",
522
- # "project_id": "8e67b1cb-2b8d-4be5-91cb-757edb2ec970",
523
- # "project_path": "fakeorg/fakeproject",
524
- # "project": "fakeproject",
525
- # "builder": "pypi_builder",
526
- # "ingredient_name": "fakeingredient",
527
- # "artifact_id": "9e67b1cb-2b8d-4be5-91cb-757edb2ec970",
528
- # "iss":"https://platform.activestate.com/api/v1/oauth/oidc",
529
- # "nbf": 1650663265,
530
- # "exp": 1650664165,
531
- # "iat": 1650663865
532
- # }
533
- return (
534
- "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2ZTY3YjFjYi0yYjhkLTRi"
535
- "ZTUtOTFjYi03NTdlZGIyZWM5NzAiLCJzdWIiOiJvcmc6ZmFrZW9yZzpwcm9qZWN0OmZha"
536
- "2Vwcm9qZWN0IiwiYXVkIjoicHlwaSIsImFjdG9yX2lkIjoiZmFrZSIsImFjdG9yIjoiZm"
537
- "9vIiwib3JhZ2FuaXphdGlvbl9pZCI6IjdlNjdiMWNiLTJiOGQtNGJlNS05MWNiLTc1N2V"
538
- "kYjJlYzk3MCIsIm9yZ2FuaXphdGlvbiI6ImZha2VvcmciLCJwcm9qZWN0X3Zpc2liaWxp"
539
- "dHkiOiJwcml2YXRlIiwicHJvamVjdF9pZCI6IjhlNjdiMWNiLTJiOGQtNGJlNS05MWNiL"
540
- "Tc1N2VkYjJlYzk3MCIsInByb2plY3RfcGF0aCI6ImZha2VvcmcvZmFrZXByb2plY3QiLC"
541
- "Jwcm9qZWN0IjoiZmFrZXByb2plY3QiLCJidWlsZGVyIjoicHlwaV9idWlsZGVyIiwiaW5"
542
- "ncmVkaWVudF9uYW1lIjoiZmFrZWluZ3JlZGllbnQiLCJhcnRpZmFjdF9pZCI6IjllNjdi"
543
- "MWNiLTJiOGQtNGJlNS05MWNiLTc1N2VkYjJlYzk3MCIsImlzcyI6Imh0dHBzOi8vcGxhd"
544
- "GZvcm0uYWN0aXZlc3RhdGUuY29tL2FwaS92MS9vYXV0aC9vaWRjIiwibmJmIjoxNjUwNj"
545
- "YzMjY1LCJleHAiOjE2NTA2NjQxNjUsImlhdCI6MTY1MDY2Mzg2NX0.R4q-vWAFXHrBSBK"
546
- "AZuHHIsGOkqlirPxEtLfjLIDiLr0"
547
- )
548
-
549
-
550
444
@pytest .fixture
551
445
def activestate_oidc_service (db_session ):
552
446
# We pretend to be a verifier for GitHub OIDC JWTs, for the purposes of testing.
@@ -743,7 +637,7 @@ def tm():
743
637
744
638
745
639
@pytest .fixture
746
- def webtest (app_config_dbsession_from_env , remote_addr , tm ):
640
+ def webtest (app_config_dbsession_from_env , tm ):
747
641
"""
748
642
This fixture yields a test app with an alternative Pyramid configuration,
749
643
injecting the database session and transaction manager into the app.
@@ -768,7 +662,7 @@ def webtest(app_config_dbsession_from_env, remote_addr, tm):
768
662
"warehouse.db_session" : _db_session ,
769
663
"tm.active" : True , # disable pyramid_tm
770
664
"tm.manager" : tm , # pass in our own tm for the app to use
771
- "REMOTE_ADDR" : remote_addr , # set the same address for all requests
665
+ "REMOTE_ADDR" : REMOTE_ADDR , # set the same address for all requests
772
666
},
773
667
)
774
668
yield testapp
0 commit comments