aboutsummaryrefslogtreecommitdiff
path: root/filesystem/mountpoint_test.go
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2022-01-18 23:43:35 -0800
committerEric Biggers <ebiggers@google.com>2022-01-26 23:22:55 -0800
commitc2fb96c60d7678110bca14ff0a213243bd97cb08 (patch)
treea323c2a033216353b96b19e3db36b19071fcfb97 /filesystem/mountpoint_test.go
parent51c421d91172e87df30bd344b3fd3142bc388718 (diff)
filesystem: fall back to path-only links if UUID cannot be determined
This is needed to allow creating protector links to btrfs filesystems. Update https://github.com/google/fscrypt/issues/339
Diffstat (limited to 'filesystem/mountpoint_test.go')
-rw-r--r--filesystem/mountpoint_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/filesystem/mountpoint_test.go b/filesystem/mountpoint_test.go
index a4688ed..749e5e3 100644
--- a/filesystem/mountpoint_test.go
+++ b/filesystem/mountpoint_test.go
@@ -411,6 +411,40 @@ func TestGetMountFromLink(t *testing.T) {
}
}
+// Test that makeLink() is including the expected information in links.
+func TestMakeLink(t *testing.T) {
+ mnt, err := getTestMount(t)
+ if err != nil {
+ t.Skip(err)
+ }
+ link, err := makeLink(mnt)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // Normally, both UUID and PATH should be included.
+ if !strings.Contains(link, "UUID=") {
+ t.Fatal("Link doesn't contain UUID")
+ }
+ if !strings.Contains(link, "PATH=") {
+ t.Fatal("Link doesn't contain PATH")
+ }
+
+ // Without a valid device number, only PATH should be included.
+ mntCopy := *mnt
+ mntCopy.DeviceNumber = 0
+ link, err = makeLink(&mntCopy)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if strings.Contains(link, "UUID=") {
+ t.Fatal("Link shouldn't contain UUID")
+ }
+ if !strings.Contains(link, "PATH=") {
+ t.Fatal("Link doesn't contain PATH")
+ }
+}
+
// Test that old filesystem links that contain a UUID only still work.
func TestGetMountFromLegacyLink(t *testing.T) {
mnt, err := getTestMount(t)
@@ -456,6 +490,16 @@ func TestGetMountFromLinkFallback(t *testing.T) {
t.Fatal("Link doesn't point to the same Mount")
}
+ // only PATH given at all (should succeed)
+ link = fmt.Sprintf("PATH=%s\n", mnt.Path)
+ linkedMnt, err = getMountFromLink(link)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if linkedMnt != mnt {
+ t.Fatal("Link doesn't point to the same Mount")
+ }
+
// only UUID valid (should succeed)
link = fmt.Sprintf("UUID=%s\nPATH=%s\n", goodUUID, badPath)
if linkedMnt, err = getMountFromLink(link); err != nil {