28
28
ORG_URL_NAME = "fakeorg"
29
29
PROJECT_NAME = "fakeproject"
30
30
ACTOR_ID = "00000000-0000-1000-8000-000000000002"
31
+ ACTOR = "fakeuser"
32
+ INGREDIENT = "fakeingredientname"
31
33
# This follows the format of the subject that ActiveState sends us. We don't
32
34
# validate the format when verifying the JWT. That should happen when the
33
35
# Publisher is configured. We just need to make sure that the subject matches
34
36
#
35
37
# Technically, the branch should only be present if a branch was provided in the JWT
36
38
# claims
37
- SUBJECT = "org:fake_org_id :project:fake_project_id "
39
+ SUBJECT = f "org:{ ORG_URL_NAME } :project:{ PROJECT_NAME } "
38
40
39
41
40
42
def test_lookup_strategies ():
@@ -47,8 +49,9 @@ def test_lookup_strategies():
47
49
48
50
def new_signed_claims (
49
51
sub : str = SUBJECT ,
50
- actor : str = "fakeuser" ,
52
+ actor : str = ACTOR ,
51
53
actor_id : str = ACTOR_ID ,
54
+ ingredient : str = INGREDIENT ,
52
55
organization : str = ORG_URL_NAME ,
53
56
org_id : str = "fakeorgid" ,
54
57
project : str = PROJECT_NAME ,
@@ -62,14 +65,14 @@ def new_signed_claims(
62
65
"sub" : sub ,
63
66
"actor" : actor ,
64
67
"actor_id" : actor_id ,
68
+ "ingredient" : ingredient ,
65
69
"organization_id" : org_id ,
66
70
"organization" : organization ,
67
71
"project_visibility" : project_visibility ,
68
72
"project_id" : project_id ,
69
73
"project_path" : project_path ,
70
- "project_name" : project ,
71
- "builder" : "fakebuilder" ,
72
- "ingredient" : "fakeingredient" ,
74
+ "project" : project ,
75
+ "builder" : "pypi-publisher" ,
73
76
}
74
77
)
75
78
if branch_id :
@@ -109,6 +112,8 @@ def test_activestate_publisher_all_known_claims(self):
109
112
"organization" ,
110
113
"project" ,
111
114
"actor_id" ,
115
+ "actor" ,
116
+ "builder" ,
112
117
"sub" ,
113
118
# optional verifiable claims
114
119
"branch_id" ,
@@ -120,15 +125,14 @@ def test_activestate_publisher_all_known_claims(self):
120
125
"aud" ,
121
126
# unchecked claims
122
127
"project_visibility" ,
123
- "project_name" ,
124
128
"project_path" ,
125
- "organization" ,
129
+ "ingredient" ,
130
+ "organization_id" ,
131
+ "project_id" ,
126
132
}
127
133
128
134
def test_activestate_publisher_unaccounted_claims (self , monkeypatch ):
129
- publisher = ActiveStatePublisher (
130
- sub = SUBJECT ,
131
- )
135
+ publisher = ActiveStatePublisher ()
132
136
133
137
scope = pretend .stub ()
134
138
sentry_sdk = pretend .stub (
@@ -161,21 +165,25 @@ def test_activestate_publisher_unaccounted_claims(self, monkeypatch):
161
165
("organization" , False ),
162
166
("project" , False ),
163
167
("actor_id" , False ),
164
- ("branch_id" , True ),
165
- ("organization" , True ),
168
+ ("actor" , False ),
169
+ ("builder" , False ),
170
+ ("ingredient" , True ),
171
+ ("organization_id" , True ),
172
+ ("project_id" , True ),
166
173
("project_visibility" , True ),
167
- ("project_name" , True ),
168
174
("project_path" , True ),
175
+ ("branch_id" , True ),
169
176
],
170
177
)
171
178
def test_activestate_publisher_missing_claims (
172
179
self , monkeypatch , claim_to_drop : str , valid : bool
173
180
):
174
181
publisher = ActiveStatePublisher (
175
- sub = SUBJECT ,
176
182
organization = ORG_URL_NAME ,
177
183
project = PROJECT_NAME ,
178
184
actor_id = ACTOR_ID ,
185
+ actor = ACTOR ,
186
+ ingredient = INGREDIENT ,
179
187
)
180
188
181
189
scope = pretend .stub ()
@@ -216,10 +224,11 @@ def test_activestate_publisher_org_id_verified(
216
224
self , expect : str , actual : str , valid : bool
217
225
):
218
226
publisher = ActiveStatePublisher (
219
- sub = SUBJECT ,
220
227
organization = actual ,
221
228
project = PROJECT_NAME ,
222
229
actor_id = ACTOR_ID ,
230
+ actor = ACTOR ,
231
+ ingredient = INGREDIENT ,
223
232
)
224
233
225
234
signed_claims = new_signed_claims (organization = expect )
@@ -236,10 +245,11 @@ def test_activestate_publisher_project_id_verified(
236
245
self , expect : str , actual : str , valid : bool
237
246
):
238
247
publisher = ActiveStatePublisher (
239
- sub = SUBJECT ,
240
248
organization = ORG_URL_NAME ,
241
249
project = actual ,
242
250
actor_id = ACTOR_ID ,
251
+ actor = ACTOR ,
252
+ ingredient = INGREDIENT ,
243
253
)
244
254
245
255
signed_claims = new_signed_claims (project = expect )
@@ -256,10 +266,11 @@ def test_activestate_publisher_user_id_verified(
256
266
self , expect : str , actual : str , valid : bool
257
267
):
258
268
publisher = ActiveStatePublisher (
259
- sub = SUBJECT ,
260
269
organization = ORG_URL_NAME ,
261
270
project = PROJECT_NAME ,
262
271
actor_id = actual ,
272
+ actor = ACTOR ,
273
+ ingredient = INGREDIENT ,
263
274
)
264
275
265
276
signed_claims = new_signed_claims (actor_id = expect )
@@ -296,7 +307,8 @@ def test_activestate_publisher_user_id_verified(
296
307
)
297
308
def test_activestate_publisher_sub (self , expected : str , actual : str , valid : bool ):
298
309
check = ActiveStatePublisher .__required_verifiable_claims__ ["sub" ]
299
- assert check (expected , actual , pretend .stub ()) is valid
310
+ signed_claims = new_signed_claims (sub = actual )
311
+ assert check (expected , actual , signed_claims ) is valid
300
312
301
313
302
314
class TestPendingActiveStatePublisher :
0 commit comments