Skip to content

Commit

Permalink
Add unit tests for UpdateLayerInfos with encryption/decryption
Browse files Browse the repository at this point in the history
Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Sep 6, 2023
1 parent 8ba8048 commit 9668bb9
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
39 changes: 39 additions & 0 deletions manifest/fixtures/ociv1.encrypted.manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"config": {
"mediaType": "application/vnd.oci.image.config.v1+json",
"digest": "sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7",
"size": 7023
},
"layers": [
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip+encrypted",
"digest": "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"size": 32654,
"annotations": {
"org.opencontainers.image.enc.…": "layer1"
}
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip+encrypted",
"digest": "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"size": 16724,
"annotations": {
"org.opencontainers.image.enc.…": "layer2"
}
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip+encrypted",
"digest": "sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"size": 73109,
"annotations": {
"org.opencontainers.image.enc.…": "layer2"
}
}
],
"annotations": {
"com.example.key1": "value1",
"com.example.key2": "value2"
}
}
62 changes: 62 additions & 0 deletions manifest/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,68 @@ func TestOCI1UpdateLayerInfos(t *testing.T) {
},
expectedFixture: "ociv1.nondistributable.manifest.json",
},
{
name: "uncompressed → gzip encrypted",
sourceFixture: "ociv1.uncompressed.manifest.json",
updates: []types.BlobInfo{
{
Digest: "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
Size: 32654,
Annotations: map[string]string{"org.opencontainers.image.enc.…": "layer1"},
MediaType: imgspecv1.MediaTypeImageLayer,
CompressionOperation: types.Compress,
CompressionAlgorithm: &compression.Gzip,
CryptoOperation: types.Encrypt,
},
{
Digest: "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
Size: 16724,
Annotations: map[string]string{"org.opencontainers.image.enc.…": "layer2"},
MediaType: imgspecv1.MediaTypeImageLayer,
CompressionOperation: types.Compress,
CompressionAlgorithm: &compression.Gzip,
CryptoOperation: types.Encrypt,
},
{
Digest: "sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
Size: 73109,
Annotations: map[string]string{"org.opencontainers.image.enc.…": "layer2"},
MediaType: imgspecv1.MediaTypeImageLayer,
CompressionOperation: types.Compress,
CompressionAlgorithm: &compression.Gzip,
CryptoOperation: types.Encrypt,
},
},
expectedFixture: "ociv1.encrypted.manifest.json",
},
{
name: "gzip encrypted → uncompressed decrypted",
sourceFixture: "ociv1.encrypted.manifest.json",
updates: []types.BlobInfo{
{
Digest: "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f",
Size: 32654,
MediaType: "application/vnd.oci.image.layer.v1.tar+gzip+encrypted",
CompressionOperation: types.Decompress,
CryptoOperation: types.Decrypt,
},
{
Digest: "sha256:3c3a4604a545cdc127456d94e421cd355bca5b528f4a9c1905b15da2eb4a4c6b",
Size: 16724,
MediaType: "application/vnd.oci.image.layer.v1.tar+gzip+encrypted",
CompressionOperation: types.Decompress,
CryptoOperation: types.Decrypt,
},
{
Digest: "sha256:ec4b8955958665577945c89419d1af06b5f7636b4ac3da7f12184802ad867736",
Size: 73109,
MediaType: "application/vnd.oci.image.layer.v1.tar+gzip+encrypted",
CompressionOperation: types.Decompress,
CryptoOperation: types.Decrypt,
},
},
expectedFixture: "ociv1.uncompressed.manifest.json",
},
} {
manifest := manifestOCI1FromFixture(t, c.sourceFixture)

Expand Down

0 comments on commit 9668bb9

Please sign in to comment.