Skip to content

Commit 2e6df31

Browse files
Removed fixtures and added comments to constants
1 parent 143eec9 commit 2e6df31

File tree

5 files changed

+65
-115
lines changed

5 files changed

+65
-115
lines changed

tests/common/constants.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,46 @@
1414

1515
REMOTE_ADDR = "1.2.3.4"
1616

17+
"""
18+
Static output of `hashlib.sha256(remote_addr.encode("utf8")).hexdigest()`
19+
Created statically to prevent needing to calculate it every run.
20+
"""
1721
REMOTE_ADDR_HASHED = "6694f83c9f476da31f5df6bcc520034e7e57d421d247b9d34f49edbfc84a764c"
1822

23+
"""
24+
Output of `hashlib.sha256((remote_addr + "pepa").encode("utf8")).hexdigest()`
25+
"""
1926
REMOTE_ADDR_SALTED = "a69a49383d81404e4b1df297c7baa28e1cd6c4ee1495ed5d0ab165a63a147763"
2027

28+
"""
29+
{
30+
"jti": "6e67b1cb-2b8d-4be5-91cb-757edb2ec970",
31+
"sub": "repo:foo/bar",
32+
"aud": "pypi",
33+
"ref": "fake",
34+
"sha": "fake",
35+
"repository": "foo/bar",
36+
"repository_owner": "foo",
37+
"repository_owner_id": "123",
38+
"run_id": "fake",
39+
"run_number": "fake",
40+
"run_attempt": "1",
41+
"repository_id": "fake",
42+
"actor_id": "fake",
43+
"actor": "foo",
44+
"workflow": "fake",
45+
"head_ref": "fake",
46+
"base_ref": "fake",
47+
"event_name": "fake",
48+
"ref_type": "fake",
49+
"environment": "fake",
50+
"job_workflow_ref": "foo/bar/.github/workflows/example.yml@fake",
51+
"iss": "https://token.actions.githubusercontent.com",
52+
"nbf": 1650663265,
53+
"exp": 1650664165,
54+
"iat": 1650663865
55+
}
56+
"""
2157
DUMMY_GITHUB_OIDC_JWT = (
2258
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2ZTY3YjFjYi0yYjhkLTRiZ"
2359
"TUtOTFjYi03NTdlZGIyZWM5NzAiLCJzdWIiOiJyZXBvOmZvby9iYXIiLCJhdWQiOiJweXB"
@@ -34,6 +70,28 @@
3470
"C-E"
3571
)
3672

73+
"""
74+
{
75+
"jti": "6e67b1cb-2b8d-4be5-91cb-757edb2ec970",
76+
"sub": "org:fakeorg:project:fakeproject",
77+
"aud": "pypi",
78+
"actor_id": "fake",
79+
"actor": "foo",
80+
"oraganization_id": "7e67b1cb-2b8d-4be5-91cb-757edb2ec970",
81+
"organization": "fakeorg",
82+
"project_visibility": "private",
83+
"project_id": "8e67b1cb-2b8d-4be5-91cb-757edb2ec970",
84+
"project_path": "fakeorg/fakeproject",
85+
"project": "fakeproject",
86+
"builder": "pypi_builder",
87+
"ingredient_name": "fakeingredient",
88+
"artifact_id": "9e67b1cb-2b8d-4be5-91cb-757edb2ec970",
89+
"iss":"https://platform.activestate.com/api/v1/oauth/oidc",
90+
"nbf": 1650663265,
91+
"exp": 1650664165,
92+
"iat": 1650663865
93+
}
94+
"""
3795
DUMMY_ACTIVESTATE_OIDC_JWT = (
3896
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2ZTY3YjFjYi0yYjhkLTRi"
3997
"ZTUtOTFjYi03NTdlZGIyZWM5NzAiLCJzdWIiOiJvcmc6ZmFrZW9yZzpwcm9qZWN0OmZha"

tests/conftest.py

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,6 @@ def metrics():
120120
)
121121

122122

123-
@pytest.fixture
124-
def remote_addr():
125-
return "1.2.3.4"
126-
127-
128-
@pytest.fixture
129-
def remote_addr_hashed():
130-
"""
131-
Static output of `hashlib.sha256(remote_addr.encode("utf8")).hexdigest()`
132-
Created statically to prevent needing to calculate it every run.
133-
"""
134-
return "6694f83c9f476da31f5df6bcc520034e7e57d421d247b9d34f49edbfc84a764c"
135-
136-
137-
@pytest.fixture
138-
def remote_addr_salted():
139-
"""
140-
Output of `hashlib.sha256((remote_addr + "pepa").encode("utf8")).hexdigest()`
141-
"""
142-
return "a69a49383d81404e4b1df297c7baa28e1cd6c4ee1495ed5d0ab165a63a147763"
143-
144-
145123
@pytest.fixture
146124
def jinja():
147125
dir_name = os.path.join(os.path.dirname(warehouse.__file__))
@@ -463,91 +441,6 @@ def github_oidc_service(db_session):
463441
)
464442

465443

466-
@pytest.fixture
467-
def dummy_github_oidc_jwt():
468-
# {
469-
# "jti": "6e67b1cb-2b8d-4be5-91cb-757edb2ec970",
470-
# "sub": "repo:foo/bar",
471-
# "aud": "pypi",
472-
# "ref": "fake",
473-
# "sha": "fake",
474-
# "repository": "foo/bar",
475-
# "repository_owner": "foo",
476-
# "repository_owner_id": "123",
477-
# "run_id": "fake",
478-
# "run_number": "fake",
479-
# "run_attempt": "1",
480-
# "repository_id": "fake",
481-
# "actor_id": "fake",
482-
# "actor": "foo",
483-
# "workflow": "fake",
484-
# "head_ref": "fake",
485-
# "base_ref": "fake",
486-
# "event_name": "fake",
487-
# "ref_type": "fake",
488-
# "environment": "fake",
489-
# "job_workflow_ref": "foo/bar/.github/workflows/example.yml@fake",
490-
# "iss": "https://token.actions.githubusercontent.com",
491-
# "nbf": 1650663265,
492-
# "exp": 1650664165,
493-
# "iat": 1650663865
494-
# }
495-
return (
496-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2ZTY3YjFjYi0yYjhkLTRiZ"
497-
"TUtOTFjYi03NTdlZGIyZWM5NzAiLCJzdWIiOiJyZXBvOmZvby9iYXIiLCJhdWQiOiJweXB"
498-
"pIiwicmVmIjoiZmFrZSIsInNoYSI6ImZha2UiLCJyZXBvc2l0b3J5IjoiZm9vL2JhciIsI"
499-
"nJlcG9zaXRvcnlfb3duZXIiOiJmb28iLCJyZXBvc2l0b3J5X293bmVyX2lkIjoiMTIzIiw"
500-
"icnVuX2lkIjoiZmFrZSIsInJ1bl9udW1iZXIiOiJmYWtlIiwicnVuX2F0dGVtcHQiOiIxI"
501-
"iwicmVwb3NpdG9yeV9pZCI6ImZha2UiLCJhY3Rvcl9pZCI6ImZha2UiLCJhY3RvciI6ImZ"
502-
"vbyIsIndvcmtmbG93IjoiZmFrZSIsImhlYWRfcmVmIjoiZmFrZSIsImJhc2VfcmVmIjoiZ"
503-
"mFrZSIsImV2ZW50X25hbWUiOiJmYWtlIiwicmVmX3R5cGUiOiJmYWtlIiwiZW52aXJvbm1"
504-
"lbnQiOiJmYWtlIiwiam9iX3dvcmtmbG93X3JlZiI6ImZvby9iYXIvLmdpdGh1Yi93b3JrZ"
505-
"mxvd3MvZXhhbXBsZS55bWxAZmFrZSIsImlzcyI6Imh0dHBzOi8vdG9rZW4uYWN0aW9ucy5"
506-
"naXRodWJ1c2VyY29udGVudC5jb20iLCJuYmYiOjE2NTA2NjMyNjUsImV4cCI6MTY1MDY2N"
507-
"DE2NSwiaWF0IjoxNjUwNjYzODY1fQ.f-FMv5FF5sdxAWeUilYDt9NoE7Et0vbdNhK32c2o"
508-
"C-E"
509-
)
510-
511-
512-
@pytest.fixture
513-
def dummy_activestate_oidc_jwt():
514-
# {
515-
# "jti": "6e67b1cb-2b8d-4be5-91cb-757edb2ec970",
516-
# "sub": "org:fakeorg:project:fakeproject",
517-
# "aud": "pypi",
518-
# "actor_id": "fake",
519-
# "actor": "foo",
520-
# "oraganization_id": "7e67b1cb-2b8d-4be5-91cb-757edb2ec970",
521-
# "organization": "fakeorg",
522-
# "project_visibility": "private",
523-
# "project_id": "8e67b1cb-2b8d-4be5-91cb-757edb2ec970",
524-
# "project_path": "fakeorg/fakeproject",
525-
# "project": "fakeproject",
526-
# "builder": "pypi_builder",
527-
# "ingredient_name": "fakeingredient",
528-
# "artifact_id": "9e67b1cb-2b8d-4be5-91cb-757edb2ec970",
529-
# "iss":"https://platform.activestate.com/api/v1/oauth/oidc",
530-
# "nbf": 1650663265,
531-
# "exp": 1650664165,
532-
# "iat": 1650663865
533-
# }
534-
return (
535-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2ZTY3YjFjYi0yYjhkLTRi"
536-
"ZTUtOTFjYi03NTdlZGIyZWM5NzAiLCJzdWIiOiJvcmc6ZmFrZW9yZzpwcm9qZWN0OmZha"
537-
"2Vwcm9qZWN0IiwiYXVkIjoicHlwaSIsImFjdG9yX2lkIjoiZmFrZSIsImFjdG9yIjoiZm"
538-
"9vIiwib3JhZ2FuaXphdGlvbl9pZCI6IjdlNjdiMWNiLTJiOGQtNGJlNS05MWNiLTc1N2V"
539-
"kYjJlYzk3MCIsIm9yZ2FuaXphdGlvbiI6ImZha2VvcmciLCJwcm9qZWN0X3Zpc2liaWxp"
540-
"dHkiOiJwcml2YXRlIiwicHJvamVjdF9pZCI6IjhlNjdiMWNiLTJiOGQtNGJlNS05MWNiL"
541-
"Tc1N2VkYjJlYzk3MCIsInByb2plY3RfcGF0aCI6ImZha2VvcmcvZmFrZXByb2plY3QiLC"
542-
"Jwcm9qZWN0IjoiZmFrZXByb2plY3QiLCJidWlsZGVyIjoicHlwaV9idWlsZGVyIiwiaW5"
543-
"ncmVkaWVudF9uYW1lIjoiZmFrZWluZ3JlZGllbnQiLCJhcnRpZmFjdF9pZCI6IjllNjdi"
544-
"MWNiLTJiOGQtNGJlNS05MWNiLTc1N2VkYjJlYzk3MCIsImlzcyI6Imh0dHBzOi8vcGxhd"
545-
"GZvcm0uYWN0aXZlc3RhdGUuY29tL2FwaS92MS9vYXV0aC9vaWRjIiwibmJmIjoxNjUwNj"
546-
"YzMjY1LCJleHAiOjE2NTA2NjQxNjUsImlhdCI6MTY1MDY2Mzg2NX0.R4q-vWAFXHrBSBK"
547-
"AZuHHIsGOkqlirPxEtLfjLIDiLr0"
548-
)
549-
550-
551444
@pytest.fixture
552445
def activestate_oidc_service(db_session):
553446
# We pretend to be a verifier for GitHub OIDC JWTs, for the purposes of testing.

tests/unit/accounts/test_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def test_add_email_rate_limited(self, user_service, metrics):
406406
)
407407
]
408408

409-
def test_add_email_bypass_ratelimit(self, user_service, metrics, remote_addr):
409+
def test_add_email_bypass_ratelimit(self, user_service, metrics):
410410
resets = pretend.stub()
411411
limiter = pretend.stub(
412412
hit=pretend.call_recorder(lambda ip: None),

tests/unit/oidc/test_views.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from warehouse.packaging.models import Project
4242
from warehouse.rate_limiting.interfaces import IRateLimiter
4343

44-
from ...common.constants import DUMMY_GITHUB_OIDC_JWT
44+
from ...common.constants import DUMMY_ACTIVESTATE_OIDC_JWT, DUMMY_GITHUB_OIDC_JWT
4545

4646

4747
def test_ratelimiters():
@@ -86,14 +86,13 @@ def test_oidc_audience():
8686

8787

8888
@pytest.mark.parametrize(
89-
("token_fixture_name", "service_name"),
89+
("token", "service_name"),
9090
[
91-
("dummy_github_oidc_jwt", "github"),
92-
("dummy_activestate_oidc_jwt", "activestate"),
91+
(DUMMY_GITHUB_OIDC_JWT, "github"),
92+
(DUMMY_ACTIVESTATE_OIDC_JWT, "activestate"),
9393
],
9494
)
95-
def test_mint_token_from_oidc_not_enabled(token_fixture_name, service_name, request):
96-
token = request.getfixturevalue(token_fixture_name)
95+
def test_mint_token_from_oidc_not_enabled(token, service_name, request):
9796
request = pretend.stub(
9897
body=json.dumps({"token": token}),
9998
response=pretend.stub(status=None),

tests/unit/subscriptions/test_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class TestStripeSubscriptionService:
452452
def test_verify_service(self):
453453
assert verifyClass(ISubscriptionService, services.StripeSubscriptionService)
454454

455-
def test_service_creation(self, remote_addr):
455+
def test_service_creation(self):
456456
session = pretend.stub()
457457
service = services.StripeSubscriptionService(session)
458458

0 commit comments

Comments
 (0)