fix: SCHILY.xattrs should be SCHILY.xattr

from golang code
bad6b6fa91/src/archive/tar/common.go (L110)

add unit test for tar xattr

Fixes: #2863

Signed-off-by: Ace-Tang <aceapril@126.com>
This commit is contained in:
Ace-Tang 2018-12-12 14:09:50 +08:00
parent 4ccff37c7e
commit 6f944e4190
2 changed files with 47 additions and 1 deletions

View File

@ -100,7 +100,7 @@ const (
// readdir calls to this directory do not follow to lower layers. // readdir calls to this directory do not follow to lower layers.
whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq" whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"
paxSchilyXattr = "SCHILY.xattrs." paxSchilyXattr = "SCHILY.xattr."
) )
// Apply applies a tar stream of an OCI style diff tar. // Apply applies a tar stream of an OCI style diff tar.

View File

@ -22,6 +22,7 @@ import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"context" "context"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -33,6 +34,7 @@ import (
_ "crypto/sha256" _ "crypto/sha256"
"github.com/containerd/containerd/archive/tartest" "github.com/containerd/containerd/archive/tartest"
"github.com/containerd/containerd/pkg/testutil"
"github.com/containerd/continuity/fs" "github.com/containerd/continuity/fs"
"github.com/containerd/continuity/fs/fstest" "github.com/containerd/continuity/fs/fstest"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -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) { func TestBreakouts(t *testing.T) {
tc := tartest.TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC()) tc := tartest.TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC())
expected := "unbroken" expected := "unbroken"