@@ -91,6 +91,8 @@ func TestAccessController(t *testing.T) {
91
91
92
92
tests := map [string ]struct {
93
93
access []auth.Access
94
+ uri string
95
+ method string
94
96
basicToken string
95
97
openshiftResponses []response
96
98
expectedError error
@@ -263,6 +265,92 @@ func TestAccessController(t *testing.T) {
263
265
"POST /oapi/v1/subjectaccessreviews" ,
264
266
},
265
267
},
268
+ "cross-repo mount" : {
269
+ access : []auth.Access {
270
+ {
271
+ Resource : auth.Resource {
272
+ Type : "repository" ,
273
+ Name : "crossrepo/source" ,
274
+ },
275
+ Action : "pull" ,
276
+ },
277
+ {
278
+ Resource : auth.Resource {
279
+ Type : "repository" ,
280
+ Name : "foo/destination" ,
281
+ },
282
+ Action : "push" ,
283
+ },
284
+ },
285
+ uri : "/v2/crossrepo/destination/blobs/uploads/?from=crossrepo/source&mount=sha256:da71393503ec9136cf62056c233f5d25b878e372c840170d91d65f8cdf94def2" ,
286
+ method : "POST" ,
287
+ basicToken : "b3BlbnNoaWZ0OmF3ZXNvbWU=" ,
288
+ openshiftResponses : []response {
289
+ {200 , runtime .EncodeOrDie (kapi .Codecs .LegacyCodec (registered .GroupOrDie (kapi .GroupName ).GroupVersions [0 ]), & api.SubjectAccessReviewResponse {Namespace : "crossrepo" , Allowed : true , Reason : "authorized!" })},
290
+ },
291
+ expectedError : nil ,
292
+ expectedChallenge : false ,
293
+ expectedActions : []string {"POST /oapi/v1/namespaces/foo/localsubjectaccessreviews" },
294
+ },
295
+ "cross-repo mount missing from attribute" : {
296
+ access : []auth.Access {
297
+ {
298
+ Resource : auth.Resource {
299
+ Type : "repository" ,
300
+ Name : "crossrepo/source" ,
301
+ },
302
+ Action : "pull" ,
303
+ },
304
+ {
305
+ Resource : auth.Resource {
306
+ Type : "repository" ,
307
+ Name : "foo/destination" ,
308
+ },
309
+ Action : "push" ,
310
+ },
311
+ },
312
+ uri : "/v2/foo/destination/blobs/uploads/?mount=sha256:da71393503ec9136cf62056c233f5d25b878e372c840170d91d65f8cdf94def2" ,
313
+ method : "POST" ,
314
+ basicToken : "b3BlbnNoaWZ0OmF3ZXNvbWU=" ,
315
+ openshiftResponses : []response {
316
+ {200 , runtime .EncodeOrDie (kapi .Codecs .LegacyCodec (registered .GroupOrDie (kapi .GroupName ).GroupVersions [0 ]), & api.SubjectAccessReviewResponse {Namespace : "crossrepo" , Allowed : false , Reason : "no!" })},
317
+ {200 , runtime .EncodeOrDie (kapi .Codecs .LegacyCodec (registered .GroupOrDie (kapi .GroupName ).GroupVersions [0 ]), & api.SubjectAccessReviewResponse {Namespace : "foo" , Allowed : true , Reason : "authorized!" })},
318
+ },
319
+ expectedError : ErrOpenShiftAccessDenied ,
320
+ expectedChallenge : true ,
321
+ expectedActions : []string {"POST /oapi/v1/namespaces/crossrepo/localsubjectaccessreviews" },
322
+ },
323
+ "cross-repo mount with unexpected method" : {
324
+ access : []auth.Access {
325
+ {
326
+ Resource : auth.Resource {
327
+ Type : "repository" ,
328
+ Name : "crossrepo/source" ,
329
+ },
330
+ Action : "pull" ,
331
+ },
332
+ {
333
+ Resource : auth.Resource {
334
+ Type : "repository" ,
335
+ Name : "foo/destination" ,
336
+ },
337
+ Action : "push" ,
338
+ },
339
+ },
340
+ uri : "/v2/crossrepo/destination/blobs/uploads/?from=crossrepo/source&mount=sha256:da71393503ec9136cf62056c233f5d25b878e372c840170d91d65f8cdf94def2" ,
341
+ method : "PUT" ,
342
+ basicToken : "b3BlbnNoaWZ0OmF3ZXNvbWU=" ,
343
+ openshiftResponses : []response {
344
+ {200 , runtime .EncodeOrDie (kapi .Codecs .LegacyCodec (registered .GroupOrDie (kapi .GroupName ).GroupVersions [0 ]), & api.SubjectAccessReviewResponse {Namespace : "crossrepo" , Allowed : true , Reason : "authorized!" })},
345
+ {200 , runtime .EncodeOrDie (kapi .Codecs .LegacyCodec (registered .GroupOrDie (kapi .GroupName ).GroupVersions [0 ]), & api.SubjectAccessReviewResponse {Namespace : "foo" , Allowed : false , Reason : "authorized!" })},
346
+ },
347
+ expectedError : ErrOpenShiftAccessDenied ,
348
+ expectedChallenge : true ,
349
+ expectedActions : []string {
350
+ "POST /oapi/v1/namespaces/crossrepo/localsubjectaccessreviews" ,
351
+ "POST /oapi/v1/namespaces/foo/localsubjectaccessreviews" ,
352
+ },
353
+ },
266
354
}
267
355
268
356
for k , test := range tests {
@@ -274,7 +362,11 @@ func TestAccessController(t *testing.T) {
274
362
if len (test .basicToken ) > 0 {
275
363
req .Header .Set ("Authorization" , fmt .Sprintf ("Basic %s" , test .basicToken ))
276
364
}
277
- ctx := context .WithValue (context .Background (), "http.request" , req )
365
+ ctx := context .WithValues (context .Background (), map [string ]interface {}{
366
+ "http.request" : req ,
367
+ "http.request.uri" : test .uri ,
368
+ "http.request.method" : test .method ,
369
+ })
278
370
279
371
server , actions := simulateOpenShiftMaster (test .openshiftResponses )
280
372
DefaultRegistryClient = NewRegistryClient (& clientcmd.Config {
0 commit comments