tests: xattr: set on 0200 file, list on 0000 file

https://github.com/rfjakob/gocryptfs/issues/308
This commit is contained in:
Jakob Unterwurzacher 2019-01-02 20:45:55 +01:00
parent bb7f919674
commit d269c28d16

View File

@ -97,7 +97,7 @@ func setGetRmList(fn string) error {
// Test xattr set, get, rm on a regular file.
func TestSetGetRmRegularFile(t *testing.T) {
fn := test_helpers.DefaultPlainDir + "/TestSetGetRmRegularFile"
err := ioutil.WriteFile(fn, nil, 0700)
err := ioutil.WriteFile(fn, []byte("12345"), 0700)
if err != nil {
t.Fatalf("creating empty file failed: %v", err)
}
@ -105,6 +105,10 @@ func TestSetGetRmRegularFile(t *testing.T) {
if err != nil {
t.Error(err)
}
fi, _ := os.Lstat(fn)
if fi.Size() != 5 {
t.Errorf("file size has changed!? size=%d", fi.Size())
}
}
// Test xattr set, get, rm on a fifo. This should not hang.
@ -276,3 +280,29 @@ func TestBase64XattrRead(t *testing.T) {
}
}
}
// Listing xattrs should work even when we don't have read access
func TestList0000File(t *testing.T) {
fn := test_helpers.DefaultPlainDir + "/TestList0000File"
err := ioutil.WriteFile(fn, nil, 0000)
if err != nil {
t.Fatalf("creating empty file failed: %v", err)
}
_, err = xattr.LList(fn)
if err != nil {
t.Error(err)
}
}
// Setting xattrs should work even when we don't have read access
func TestSet0200File(t *testing.T) {
fn := test_helpers.DefaultPlainDir + "/TestSet0200File"
err := ioutil.WriteFile(fn, nil, 0200)
if err != nil {
t.Fatalf("creating empty file failed: %v", err)
}
err = xattr.LSet(fn, "user.foo", []byte("bar"))
if err != nil {
t.Error(err)
}
}