24
24
GooglePublisherFactory ,
25
25
)
26
26
from warehouse .oidc import errors , utils
27
+ from warehouse .oidc .models import (
28
+ ActiveStatePublisher ,
29
+ GitHubPublisher ,
30
+ GitLabPublisher ,
31
+ GooglePublisher ,
32
+ )
33
+ from warehouse .oidc .utils import OIDC_PUBLISHER_CLASSES
27
34
from warehouse .utils .security_policy import principals_for
28
35
29
36
@@ -34,6 +41,35 @@ def test_find_publisher_by_issuer_bad_issuer_url():
34
41
)
35
42
36
43
44
+ @pytest .mark .parametrize (
45
+ ("issuer_url" , "publisher_cls_dict" ), OIDC_PUBLISHER_CLASSES .items ()
46
+ )
47
+ def test_find_publisher_by_issuer_checks_claims_existence (
48
+ monkeypatch , issuer_url , publisher_cls_dict
49
+ ):
50
+ publisher_cls = pretend .stub (
51
+ check_claims_existence = pretend .call_recorder (lambda x : None ),
52
+ lookup_by_claims = pretend .call_recorder (lambda x , y : None ),
53
+ )
54
+ monkeypatch .setattr (
55
+ utils ,
56
+ "OIDC_PUBLISHER_CLASSES" ,
57
+ {issuer_url : {False : publisher_cls , True : publisher_cls }},
58
+ )
59
+
60
+ signed_claims = {
61
+ claim_name : "fake"
62
+ for claim_name in publisher_cls_dict [False ].all_known_claims ()
63
+ }
64
+ session = pretend .stub ()
65
+ utils .find_publisher_by_issuer (session , issuer_url , signed_claims )
66
+
67
+ assert publisher_cls .check_claims_existence .calls == [pretend .call (signed_claims )]
68
+ assert publisher_cls .lookup_by_claims .calls == [
69
+ pretend .call (session , signed_claims )
70
+ ]
71
+
72
+
37
73
@pytest .mark .parametrize (
38
74
("environment" , "expected_id" ),
39
75
[
@@ -62,10 +98,15 @@ def test_find_publisher_by_issuer_github(db_request, environment, expected_id):
62
98
)
63
99
64
100
signed_claims = {
65
- "repository" : "foo/bar" ,
66
- "job_workflow_ref" : "foo/bar/.github/workflows/ci.yml@refs/heads/main" ,
67
- "repository_owner_id" : "1234" ,
101
+ claim_name : "fake" for claim_name in GitHubPublisher .all_known_claims ()
68
102
}
103
+ signed_claims .update (
104
+ {
105
+ "repository" : "foo/bar" ,
106
+ "job_workflow_ref" : "foo/bar/.github/workflows/ci.yml@refs/heads/main" ,
107
+ "repository_owner_id" : "1234" ,
108
+ }
109
+ )
69
110
if environment :
70
111
signed_claims ["environment" ] = environment
71
112
@@ -104,9 +145,15 @@ def test_find_publisher_by_issuer_gitlab(db_request, environment, expected_id):
104
145
)
105
146
106
147
signed_claims = {
107
- "project_path" : "foo/bar" ,
108
- "ci_config_ref_uri" : "gitlab.com/foo/bar//workflows/ci.yml@refs/heads/main" ,
148
+ claim_name : "fake" for claim_name in GitLabPublisher .all_known_claims ()
109
149
}
150
+
151
+ signed_claims .update (
152
+ {
153
+ "project_path" : "foo/bar" ,
154
+ "ci_config_ref_uri" : "gitlab.com/foo/bar//workflows/ci.yml@refs/heads/main" ,
155
+ }
156
+ )
110
157
if environment :
111
158
signed_claims ["environment" ] = environment
112
159
@@ -140,10 +187,16 @@ def test_find_publisher_by_issuer_google(db_request, sub, expected_id):
140
187
)
141
188
142
189
signed_claims = {
143
-
144
- "sub" : sub ,
190
+ claim_name : "fake" for claim_name in GooglePublisher .all_known_claims ()
145
191
}
146
192
193
+ signed_claims .update (
194
+ {
195
+
196
+ "sub" : sub ,
197
+ }
198
+ )
199
+
147
200
assert (
148
201
utils .find_publisher_by_issuer (
149
202
db_request .db ,
@@ -227,13 +280,19 @@ def test_find_publisher_by_issuer_activestate(
227
280
)
228
281
229
282
signed_claims = {
230
- "sub" : sub ,
231
- "organization" : organization ,
232
- "project" : project ,
233
- "actor_id" : actor_id ,
234
- "actor" : actor ,
283
+ claim_name : "fake" for claim_name in ActiveStatePublisher .all_known_claims ()
235
284
}
236
285
286
+ signed_claims .update (
287
+ {
288
+ "sub" : sub ,
289
+ "organization" : organization ,
290
+ "project" : project ,
291
+ "actor_id" : actor_id ,
292
+ "actor" : actor ,
293
+ }
294
+ )
295
+
237
296
assert (
238
297
utils .find_publisher_by_issuer (
239
298
db_request .db ,
0 commit comments