Skip to content

Commit 6f944e4

Browse files
committed
1 parent 4ccff37 commit 6f944e4

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

archive/tar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const (
100100
// readdir calls to this directory do not follow to lower layers.
101101
whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"
102102

103-
paxSchilyXattr = "SCHILY.xattrs."
103+
paxSchilyXattr = "SCHILY.xattr."
104104
)
105105

106106
// Apply applies a tar stream of an OCI style diff tar.

archive/tar_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"archive/tar"
2323
"bytes"
2424
"context"
25+
"fmt"
2526
"io"
2627
"io/ioutil"
2728
"os"
@@ -33,6 +34,7 @@ import (
3334
_ "crypto/sha256"
3435

3536
"github.com/containerd/containerd/archive/tartest"
37+
"github.com/containerd/containerd/pkg/testutil"
3638
"github.com/containerd/continuity/fs"
3739
"github.com/containerd/continuity/fs/fstest"
3840
"github.com/pkg/errors"
@@ -183,6 +185,50 @@ func TestSymlinks(t *testing.T) {
183185
}
184186
}
185187

188+
func TestTarWithXattr(t *testing.T) {
189+
testutil.RequiresRoot(t)
190+
191+
fileXattrExist := func(f1, xattrKey, xattrValue string) func(string) error {
192+
return func(root string) error {
193+
values, err := getxattr(filepath.Join(root, f1), xattrKey)
194+
if err != nil {
195+
return err
196+
}
197+
if xattrValue != string(values) {
198+
return fmt.Errorf("file xattrs expect to be %s, actually get %s", xattrValue, values)
199+
}
200+
return nil
201+
}
202+
}
203+
204+
tests := []struct {
205+
name string
206+
key string
207+
value string
208+
err error
209+
}{
210+
{
211+
name: "WithXattrsUser",
212+
key: "user.key",
213+
value: "value",
214+
},
215+
{
216+
// security related xattrs need root permission to test
217+
name: "WithXattrSelinux",
218+
key: "security.selinux",
219+
value: "unconfined_u:object_r:default_t:s0\x00",
220+
},
221+
}
222+
for _, at := range tests {
223+
tc := tartest.TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC()).WithXattrs(map[string]string{
224+
at.key: at.value,
225+
})
226+
w := tartest.TarAll(tc.File("/file", []byte{}, 0755))
227+
validator := fileXattrExist("file", at.key, at.value)
228+
t.Run(at.name, makeWriterToTarTest(w, nil, validator, at.err))
229+
}
230+
}
231+
186232
func TestBreakouts(t *testing.T) {
187233
tc := tartest.TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC())
188234
expected := "unbroken"

0 commit comments

Comments
 (0)