diff --git a/pkg/archive/archive_linux_test.go b/pkg/archive/archive_linux_test.go index 5159e81f16..4402f66dde 100644 --- a/pkg/archive/archive_linux_test.go +++ b/pkg/archive/archive_linux_test.go @@ -1,6 +1,9 @@ package archive // import "github.com/docker/docker/pkg/archive" import ( + "archive/tar" + "bytes" + "io" "os" "path/filepath" "syscall" @@ -8,8 +11,10 @@ import ( "github.com/containerd/containerd/pkg/userns" "github.com/docker/docker/pkg/system" + "github.com/google/go-cmp/cmp/cmpopts" "golang.org/x/sys/unix" "gotest.tools/v3/assert" + is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/skip" ) @@ -103,11 +108,39 @@ func TestOverlayTarUntar(t *testing.T) { Compression: Uncompressed, WhiteoutFormat: OverlayWhiteoutFormat, } - archive, err := TarWithOptions(src, options) + reader, err := TarWithOptions(src, options) + assert.NilError(t, err) + archive, err := io.ReadAll(reader) + reader.Close() assert.NilError(t, err) - defer archive.Close() - err = Untar(archive, dst, options) + // The archive should encode opaque directories and file whiteouts + // in AUFS format. + entries := make(map[string]struct{}) + rdr := tar.NewReader(bytes.NewReader(archive)) + for { + h, err := rdr.Next() + if err == io.EOF { + break + } + assert.NilError(t, err) + assert.Check(t, is.Equal(h.Devmajor, int64(0)), "unexpected device file in archive") + assert.Check(t, is.DeepEqual(h.PAXRecords, map[string]string(nil), cmpopts.EquateEmpty())) + entries[h.Name] = struct{}{} + } + + assert.DeepEqual(t, entries, map[string]struct{}{ + "d1/": {}, + "d1/" + WhiteoutOpaqueDir: {}, + "d1/f1": {}, + "d2/": {}, + "d2/" + WhiteoutOpaqueDir: {}, + "d2/f1": {}, + "d3/": {}, + "d3/" + WhiteoutPrefix + "f1": {}, + }) + + err = Untar(bytes.NewReader(archive), dst, options) assert.NilError(t, err) checkFileMode(t, filepath.Join(dst, "d1"), 0o700|os.ModeDir) diff --git a/pkg/archive/archive_unix_test.go b/pkg/archive/archive_unix_test.go index e80051695d..6f9816c7ee 100644 --- a/pkg/archive/archive_unix_test.go +++ b/pkg/archive/archive_unix_test.go @@ -254,6 +254,27 @@ func TestTarUntarWithXattr(t *testing.T) { out, err := exec.Command("setcap", "cap_block_suspend+ep", filepath.Join(origin, "2")).CombinedOutput() assert.NilError(t, err, string(out)) + tarball, err := Tar(origin, Uncompressed) + assert.NilError(t, err) + defer tarball.Close() + rdr := tar.NewReader(tarball) + for { + h, err := rdr.Next() + if err == io.EOF { + break + } + assert.NilError(t, err) + capability, hasxattr := h.PAXRecords["SCHILY.xattr.security.capability"] + switch h.Name { + case "2": + if assert.Check(t, hasxattr, "tar entry %q should have the 'security.capability' xattr", h.Name) { + assert.Check(t, len(capability) > 0, "tar entry %q has a blank 'security.capability' xattr value") + } + default: + assert.Check(t, !hasxattr, "tar entry %q should not have the 'security.capability' xattr", h.Name) + } + } + for _, c := range []Compression{ Uncompressed, Gzip,