lib/fs: Let xattr test avoid non-test attributes (fixes #8601) (#8628)

SELinux for example adds security.* attributes by default that we are
not allowed to touch, which causes the test to fail.
This commit is contained in:
Jakob Borg 2022-11-03 11:57:30 +01:00 committed by GitHub
parent 922946683d
commit bf1e418e4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 8 deletions

View File

@ -591,12 +591,12 @@ func TestXattr(t *testing.T) {
}
// Set the xattrs, read them back and compare
if err := tfs.SetXattr("/test", attrs, noopXattrFilter{}); errors.Is(err, ErrXattrsNotSupported) || errors.Is(err, syscall.EOPNOTSUPP) {
if err := tfs.SetXattr("/test", attrs, testXattrFilter{}); errors.Is(err, ErrXattrsNotSupported) || errors.Is(err, syscall.EOPNOTSUPP) {
t.Skip("xattrs not supported")
} else if err != nil {
t.Fatal(err)
}
res, err := tfs.GetXattr("/test", noopXattrFilter{})
res, err := tfs.GetXattr("/test", testXattrFilter{})
if err != nil {
t.Fatal(err)
}
@ -631,10 +631,10 @@ func TestXattr(t *testing.T) {
sort.Slice(attrs, func(i, j int) bool { return attrs[i].Name < attrs[j].Name })
// Set the xattrs, read them back and compare
if err := tfs.SetXattr("/test", attrs, noopXattrFilter{}); err != nil {
if err := tfs.SetXattr("/test", attrs, testXattrFilter{}); err != nil {
t.Fatal(err)
}
res, err = tfs.GetXattr("/test", noopXattrFilter{})
res, err = tfs.GetXattr("/test", testXattrFilter{})
if err != nil {
t.Fatal(err)
}
@ -666,8 +666,10 @@ func TestWalkInfiniteRecursion(t *testing.T) {
testWalkInfiniteRecursion(t, FilesystemTypeBasic, dir)
}
type noopXattrFilter struct{}
type testXattrFilter struct{}
func (noopXattrFilter) Permit(string) bool { return true }
func (noopXattrFilter) GetMaxSingleEntrySize() int { return 0 }
func (noopXattrFilter) GetMaxTotalSize() int { return 0 }
// Permit only xattrs generated by our test, avoiding issues with SELinux etc.
func (testXattrFilter) Permit(name string) bool { return strings.HasPrefix(name, "user.test-") }
func (testXattrFilter) GetMaxSingleEntrySize() int { return 0 }
func (testXattrFilter) GetMaxTotalSize() int { return 0 }