oras-project / rust-oci-client

A Rust crate to interact with OCI registries
Apache License 2.0
90 stars 47 forks source link

[Bug] `Client::pull_blob` returns `Ok(...)` even when the blob wasn't found #64

Open aochagavia opened 1 year ago

aochagavia commented 1 year ago

Steps to reproduce

The following test reproduces the issue (you can paste it under client::test and run it with cargo test --features test-registry test_pull_blob_not_found):

#[tokio::test]
#[cfg(feature = "test-registry")]
async fn test_pull_blob_not_found() {
    // initialize the registry
    let docker = clients::Cli::default();
    let test_container = docker.run(registry_image());
    let port = test_container.get_host_port_ipv4(5000);

    let c = Client::new(ClientConfig {
        protocol: ClientProtocol::HttpsExcept(vec![format!("localhost:{}", port)]),
        ..Default::default()
    });

    // Layer is not found at `image-repository`
    let image_reference: Reference = format!("localhost:{}/image-repository", port).parse().unwrap();
    let mut buf = Vec::new();
    let dummy_digest = sha256_digest(&[]);
    let pull_result = c.pull_blob(&image_reference, &dummy_digest, &mut buf).await;

    // The result is OK, but the response body does not correspond to the contents of the blob
    assert!(pull_result.is_ok());
    assert!(String::from_utf8(buf).unwrap().starts_with("{\"errors\":[{\"code\":\"BLOB_UNKNOWN\""));
}

Expected result

As a user of the library, I intuitively expect pull_blob to return Ok only when the blob was found, and Err otherwise.

thomastaylor312 commented 1 year ago

Sorry for the delay here. Was swamped with GH notifications. This is definitely a bug!