Skip to content

Commit 7a95c9e

Browse files
committed
storage: add ut for anonymous authorization
Signed-off-by: Yan Song <[email protected]>
1 parent 6283405 commit 7a95c9e

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

storage/src/backend/registry.rs

+29-17
Original file line numberDiff line numberDiff line change
@@ -286,32 +286,33 @@ struct RegistryReader {
286286
}
287287

288288
impl RegistryReader {
289-
/// Request registry server with `authorization` header
289+
/// Request registry server with authorization workflow, it has two authentication modes:
290290
///
291-
/// Bearer token authenticate workflow:
291+
/// # Bearer token authenticate workflow:
292292
///
293-
/// Request: POST https://my-registry.com/test/repo/blobs/uploads
293+
/// Request: GET https://my-registry.com/namespace/repo/blobs/sha256:<blob_id>
294294
/// Response: status: 401 Unauthorized
295-
/// header: www-authenticate: Bearer realm="https://auth.my-registry.com/token",service="my-registry.com",scope="repository:test/repo:pull,push"
295+
/// header: www-authenticate: Bearer realm="https://auth.my-registry.com/token",service="my-registry.com",scope="repository:namespace/repo:pull,push"
296296
///
297297
/// Request: POST https://auth.my-registry.com/token
298-
/// body: "service=my-registry.com&scope=repository:test/repo:pull,push&grant_type=password&username=x&password=x&client_id=nydus-registry-client"
298+
/// body: "service=my-registry.com&scope=repository:namespace/repo:pull,push&grant_type=password&username=x&password=x&client_id=nydus-registry-client"
299299
/// Response: status: 200 Ok
300300
/// body: { "token": "<token>" }
301301
///
302-
/// Request: POST https://my-registry.com/test/repo/blobs/uploads
302+
/// Request: GET https://my-registry.com/namespace/repo/blobs/sha256:<blob_id>
303303
/// header: authorization: Bearer <token>
304-
/// Response: status: 200 Ok
304+
/// Response: status: 200/301/307
305+
///
305306
///
306-
/// Basic authenticate workflow:
307+
/// # Basic authenticate workflow:
307308
///
308-
/// Request: POST https://my-registry.com/test/repo/blobs/uploads
309+
/// Request: GET https://my-registry.com/namespace/repo/blobs/sha256:<blob_id>
309310
/// Response: status: 401 Unauthorized
310311
/// header: www-authenticate: Basic
311312
///
312-
/// Request: POST https://my-registry.com/test/repo/blobs/uploads
313+
/// Request: GET https://my-registry.com/namespace/repo/blobs/sha256:<blob_id>
313314
/// header: authorization: Basic base64(<username:password>)
314-
/// Response: status: 200 Ok
315+
/// Response: status: 200/301/307
315316
fn request<R: Read + Send + 'static>(
316317
&self,
317318
method: Method,
@@ -377,17 +378,16 @@ impl RegistryReader {
377378
respond(resp, catch_status).map_err(RegistryError::Request)
378379
}
379380

380-
/// Read data from registry server
381-
///
382-
/// Step:
381+
/// Read data from registry server, steps:
383382
///
384383
/// Request: GET /blobs/sha256:<blob_id>
385-
/// Response: status: 307 Temporary Redirect
384+
/// Response: status: 301/307
386385
/// header: location: https://raw-blob-storage-host.com/signature=x
387386
///
388387
/// Request: GET https://raw-blob-storage-host.com/signature=x
389-
/// Response: status: 200 Ok / 403 Forbidden
390-
/// If responding 403, we need to repeat step one
388+
/// Response: status: 200/403
389+
///
390+
/// If responding with 403, we need to go authorization workflow
391391
fn _try_read(
392392
&self,
393393
mut buf: &mut [u8],
@@ -748,4 +748,16 @@ mod tests {
748748
assert_eq!(trim(Some(" te st ".to_owned())), Some("te st".to_owned()));
749749
assert_eq!(trim(Some("te st".to_owned())), Some("te st".to_owned()));
750750
}
751+
752+
#[test]
753+
fn test_ghcr() {
754+
let config =
755+
serde_json::json!({"scheme":"https","host":"ghcr.io","repo":"changweige/python"});
756+
let registry = Registry::new(config, Some("registry")).unwrap();
757+
758+
let reader = registry
759+
.get_reader("b91a341ac9a53528c4d96806e1c07c3307a95ede5841f2a13ac4972c7699b067")
760+
.unwrap();
761+
let _ = reader.blob_size().unwrap();
762+
}
751763
}

0 commit comments

Comments
 (0)