Skip to content

Commit

Permalink
fix: SCHILY.xattrs should be SCHILY.xattr
Browse files Browse the repository at this point in the history
from golang code
https://github.com/golang/go/blob/bad6b6fa9190e9079a6d6958859856a66f0fab87/src/archive/tar/common.go#L110

add unit test for tar xattr

Fixes: #2863

Signed-off-by: Ace-Tang <aceapril@126.com>
  • Loading branch information
Ace-Tang committed Dec 13, 2018
1 parent 4ccff37 commit 6f944e4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion archive/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const (
// readdir calls to this directory do not follow to lower layers.
whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"

paxSchilyXattr = "SCHILY.xattrs."
paxSchilyXattr = "SCHILY.xattr."
)

// Apply applies a tar stream of an OCI style diff tar.
Expand Down
46 changes: 46 additions & 0 deletions archive/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"archive/tar"
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"os"
Expand All @@ -33,6 +34,7 @@ import (
_ "crypto/sha256"

"github.com/containerd/containerd/archive/tartest"
"github.com/containerd/containerd/pkg/testutil"
"github.com/containerd/continuity/fs"
"github.com/containerd/continuity/fs/fstest"
"github.com/pkg/errors"
Expand Down Expand Up @@ -183,6 +185,50 @@ func TestSymlinks(t *testing.T) {
}
}

func TestTarWithXattr(t *testing.T) {
testutil.RequiresRoot(t)

fileXattrExist := func(f1, xattrKey, xattrValue string) func(string) error {
return func(root string) error {
values, err := getxattr(filepath.Join(root, f1), xattrKey)
if err != nil {
return err
}
if xattrValue != string(values) {
return fmt.Errorf("file xattrs expect to be %s, actually get %s", xattrValue, values)
}
return nil
}
}

tests := []struct {
name string
key string
value string
err error
}{
{
name: "WithXattrsUser",
key: "user.key",
value: "value",
},
{
// security related xattrs need root permission to test
name: "WithXattrSelinux",
key: "security.selinux",
value: "unconfined_u:object_r:default_t:s0\x00",
},
}
for _, at := range tests {
tc := tartest.TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC()).WithXattrs(map[string]string{
at.key: at.value,
})
w := tartest.TarAll(tc.File("/file", []byte{}, 0755))
validator := fileXattrExist("file", at.key, at.value)
t.Run(at.name, makeWriterToTarTest(w, nil, validator, at.err))
}
}

func TestBreakouts(t *testing.T) {
tc := tartest.TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC())
expected := "unbroken"
Expand Down

0 comments on commit 6f944e4

Please sign in to comment.