14
14
import pytest
15
15
16
16
from tests .common .db .oidc import GitHubPublisherFactory , PendingGitHubPublisherFactory
17
- from warehouse .oidc import models
18
-
19
-
20
- def test_check_claim_binary ():
21
- wrapped = models ._check_claim_binary (str .__eq__ )
22
-
23
- assert wrapped ("foo" , "bar" , pretend .stub ()) is False
24
- assert wrapped ("foo" , "foo" , pretend .stub ()) is True
17
+ from warehouse .oidc .models import _core , github
25
18
26
19
27
20
@pytest .mark .parametrize ("claim" , ["" , "repo" , "repo:" ])
28
21
def test_check_sub (claim ):
29
- assert models ._check_sub (pretend .stub (), claim , pretend .stub ()) is False
30
-
31
-
32
- class TestOIDCPublisher :
33
- def test_oidc_publisher_not_default_verifiable (self ):
34
- publisher = models .OIDCPublisher (projects = [])
35
-
36
- assert not publisher .verify_claims (signed_claims = {})
22
+ assert github ._check_sub (pretend .stub (), claim , pretend .stub ()) is False
37
23
38
24
39
25
class TestGitHubPublisher :
40
26
def test_github_publisher_all_known_claims (self ):
41
- assert models .GitHubPublisher .all_known_claims () == {
27
+ assert github .GitHubPublisher .all_known_claims () == {
42
28
# verifiable claims
43
29
"sub" ,
44
30
"repository" ,
@@ -78,7 +64,7 @@ def test_github_publisher_all_known_claims(self):
78
64
}
79
65
80
66
def test_github_publisher_computed_properties (self ):
81
- publisher = models .GitHubPublisher (
67
+ publisher = github .GitHubPublisher (
82
68
repository_name = "fakerepo" ,
83
69
repository_owner = "fakeowner" ,
84
70
repository_owner_id = "fakeid" ,
@@ -93,7 +79,7 @@ def test_github_publisher_computed_properties(self):
93
79
assert publisher .publisher_url == "https://github.com/fakeowner/fakerepo"
94
80
95
81
def test_github_publisher_unaccounted_claims (self , monkeypatch ):
96
- publisher = models .GitHubPublisher (
82
+ publisher = github .GitHubPublisher (
97
83
repository_name = "fakerepo" ,
98
84
repository_owner = "fakeowner" ,
99
85
repository_owner_id = "fakeid" ,
@@ -109,12 +95,12 @@ def test_github_publisher_unaccounted_claims(self, monkeypatch):
109
95
)
110
96
),
111
97
)
112
- monkeypatch .setattr (models , "sentry_sdk" , sentry_sdk )
98
+ monkeypatch .setattr (_core , "sentry_sdk" , sentry_sdk )
113
99
114
100
# We don't care if these actually verify, only that they're present.
115
101
signed_claims = {
116
102
claim_name : "fake"
117
- for claim_name in models .GitHubPublisher .all_known_claims ()
103
+ for claim_name in github .GitHubPublisher .all_known_claims ()
118
104
}
119
105
signed_claims ["fake-claim" ] = "fake"
120
106
signed_claims ["another-fake-claim" ] = "also-fake"
@@ -128,7 +114,7 @@ def test_github_publisher_unaccounted_claims(self, monkeypatch):
128
114
assert scope .fingerprint == ["another-fake-claim" , "fake-claim" ]
129
115
130
116
def test_github_publisher_missing_claims (self , monkeypatch ):
131
- publisher = models .GitHubPublisher (
117
+ publisher = github .GitHubPublisher (
132
118
repository_name = "fakerepo" ,
133
119
repository_owner = "fakeowner" ,
134
120
repository_owner_id = "fakeid" ,
@@ -144,11 +130,11 @@ def test_github_publisher_missing_claims(self, monkeypatch):
144
130
)
145
131
),
146
132
)
147
- monkeypatch .setattr (models , "sentry_sdk" , sentry_sdk )
133
+ monkeypatch .setattr (_core , "sentry_sdk" , sentry_sdk )
148
134
149
135
signed_claims = {
150
136
claim_name : "fake"
151
- for claim_name in models .GitHubPublisher .all_known_claims ()
137
+ for claim_name in github .GitHubPublisher .all_known_claims ()
152
138
}
153
139
# Pop the first signed claim, so that it's the first one to fail.
154
140
signed_claims .pop ("sub" )
@@ -161,7 +147,7 @@ def test_github_publisher_missing_claims(self, monkeypatch):
161
147
assert scope .fingerprint == ["sub" ]
162
148
163
149
def test_github_publisher_missing_optional_claims (self , monkeypatch ):
164
- publisher = models .GitHubPublisher (
150
+ publisher = github .GitHubPublisher (
165
151
repository_name = "fakerepo" ,
166
152
repository_owner = "fakeowner" ,
167
153
repository_owner_id = "fakeid" ,
@@ -170,11 +156,11 @@ def test_github_publisher_missing_optional_claims(self, monkeypatch):
170
156
)
171
157
172
158
sentry_sdk = pretend .stub (capture_message = pretend .call_recorder (lambda s : None ))
173
- monkeypatch .setattr (models , "sentry_sdk" , sentry_sdk )
159
+ monkeypatch .setattr (_core , "sentry_sdk" , sentry_sdk )
174
160
175
161
signed_claims = {
176
162
claim_name : getattr (publisher , claim_name )
177
- for claim_name in models .GitHubPublisher .__required_verifiable_claims__
163
+ for claim_name in github .GitHubPublisher .__required_verifiable_claims__
178
164
}
179
165
signed_claims ["ref" ] = "ref"
180
166
signed_claims ["job_workflow_ref" ] = publisher .job_workflow_ref + "@ref"
@@ -185,10 +171,10 @@ def test_github_publisher_missing_optional_claims(self, monkeypatch):
185
171
@pytest .mark .parametrize ("environment" , [None , "some-environment" ])
186
172
@pytest .mark .parametrize (
187
173
"missing_claims" ,
188
- [set (), models .GitHubPublisher .__optional_verifiable_claims__ .keys ()],
174
+ [set (), github .GitHubPublisher .__optional_verifiable_claims__ .keys ()],
189
175
)
190
176
def test_github_publisher_verifies (self , monkeypatch , environment , missing_claims ):
191
- publisher = models .GitHubPublisher (
177
+ publisher = github .GitHubPublisher (
192
178
repository_name = "fakerepo" ,
193
179
repository_owner = "fakeowner" ,
194
180
repository_owner_id = "fakeid" ,
@@ -214,7 +200,7 @@ def test_github_publisher_verifies(self, monkeypatch, environment, missing_claim
214
200
215
201
signed_claims = {
216
202
claim_name : "fake"
217
- for claim_name in models .GitHubPublisher .all_known_claims ()
203
+ for claim_name in github .GitHubPublisher .all_known_claims ()
218
204
if claim_name not in missing_claims
219
205
}
220
206
assert publisher .verify_claims (signed_claims = signed_claims )
@@ -271,14 +257,14 @@ def test_github_publisher_verifies(self, monkeypatch, environment, missing_claim
271
257
],
272
258
)
273
259
def test_github_publisher_job_workflow_ref (self , claim , ref , valid ):
274
- publisher = models .GitHubPublisher (
260
+ publisher = github .GitHubPublisher (
275
261
repository_name = "bar" ,
276
262
repository_owner = "foo" ,
277
263
repository_owner_id = pretend .stub (),
278
264
workflow_filename = "baz.yml" ,
279
265
)
280
266
281
- check = models .GitHubPublisher .__required_verifiable_claims__ [
267
+ check = github .GitHubPublisher .__required_verifiable_claims__ [
282
268
"job_workflow_ref"
283
269
]
284
270
assert check (publisher .job_workflow_ref , claim , {"ref" : ref }) is valid
@@ -294,7 +280,7 @@ def test_github_publisher_job_workflow_ref(self, claim, ref, valid):
294
280
],
295
281
)
296
282
def test_github_publisher_sub_claim (self , truth , claim , valid ):
297
- check = models .GitHubPublisher .__required_verifiable_claims__ ["sub" ]
283
+ check = github .GitHubPublisher .__required_verifiable_claims__ ["sub" ]
298
284
assert check (truth , claim , pretend .stub ()) is valid
299
285
300
286
@pytest .mark .parametrize (
@@ -309,15 +295,15 @@ def test_github_publisher_sub_claim(self, truth, claim, valid):
309
295
],
310
296
)
311
297
def test_github_publisher_environment_claim (self , truth , claim , valid ):
312
- check = models .GitHubPublisher .__optional_verifiable_claims__ ["environment" ]
298
+ check = github .GitHubPublisher .__optional_verifiable_claims__ ["environment" ]
313
299
assert check (truth , claim , pretend .stub ()) is valid
314
300
315
301
316
302
class TestPendingGitHubPublisher :
317
303
def test_reify_does_not_exist_yet (self , db_request ):
318
304
pending_publisher = PendingGitHubPublisherFactory .create ()
319
305
assert (
320
- db_request .db .query (models .GitHubPublisher )
306
+ db_request .db .query (github .GitHubPublisher )
321
307
.filter_by (
322
308
repository_name = pending_publisher .repository_name ,
323
309
repository_owner = pending_publisher .repository_owner ,
@@ -332,7 +318,7 @@ def test_reify_does_not_exist_yet(self, db_request):
332
318
333
319
# If an OIDC publisher for this pending publisher does not already exist,
334
320
# a new one is created and the pending publisher is marked for deletion.
335
- assert isinstance (publisher , models .GitHubPublisher )
321
+ assert isinstance (publisher , github .GitHubPublisher )
336
322
assert pending_publisher in db_request .db .deleted
337
323
assert publisher .repository_name == pending_publisher .repository_name
338
324
assert publisher .repository_owner == pending_publisher .repository_owner
0 commit comments