2016-09-25 15:05:09 +02:00
|
|
|
package reverse_test
|
|
|
|
|
|
|
|
import (
|
2016-09-25 15:32:46 +02:00
|
|
|
"bytes"
|
2021-08-20 17:06:18 +02:00
|
|
|
"fmt"
|
2016-09-25 15:05:09 +02:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-08-23 15:05:15 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/v2/tests/test_helpers"
|
2016-09-25 15:05:09 +02:00
|
|
|
)
|
|
|
|
|
2016-11-10 23:32:51 +01:00
|
|
|
var x240 = string(bytes.Repeat([]byte("x"), 240))
|
2021-08-20 17:06:18 +02:00
|
|
|
|
|
|
|
// plaintextnames is true when the currently running test has -plaintextnames active
|
2016-10-08 20:57:38 +02:00
|
|
|
var plaintextnames bool
|
2016-09-25 15:05:09 +02:00
|
|
|
|
2021-08-20 17:06:18 +02:00
|
|
|
// deterministic_names is true when the currently running test has -deterministic-names active
|
|
|
|
var deterministic_names bool
|
|
|
|
|
2017-02-16 21:20:29 +01:00
|
|
|
// dirA is a normal directory
|
|
|
|
var dirA string
|
|
|
|
|
|
|
|
// dirB is the reverse mount backed by dirA
|
|
|
|
var dirB string
|
|
|
|
|
|
|
|
// dirC is a forward mount backed by dirB
|
|
|
|
var dirC string
|
|
|
|
|
|
|
|
// Create directory "dirA", mount it reverse to "dirB", mount it forward
|
|
|
|
// to "dirC".
|
2016-09-25 15:05:09 +02:00
|
|
|
func TestMain(m *testing.M) {
|
2016-10-08 20:57:38 +02:00
|
|
|
var r int
|
2021-08-20 17:06:18 +02:00
|
|
|
|
|
|
|
testcases := []struct {
|
|
|
|
plaintextnames bool
|
|
|
|
deterministic_names bool
|
|
|
|
}{
|
|
|
|
{false, false},
|
|
|
|
{true, false},
|
|
|
|
{false, true},
|
|
|
|
}
|
|
|
|
for i, tc := range testcases {
|
2016-10-08 20:57:38 +02:00
|
|
|
argsA := []string{"-reverse"}
|
2021-08-20 17:06:18 +02:00
|
|
|
plaintextnames, deterministic_names = tc.plaintextnames, tc.deterministic_names
|
|
|
|
if tc.plaintextnames {
|
2016-10-08 20:57:38 +02:00
|
|
|
argsA = append(argsA, "-plaintextnames")
|
2021-08-20 17:06:18 +02:00
|
|
|
} else if tc.deterministic_names {
|
|
|
|
argsA = append(argsA, "-deterministic-names")
|
2016-10-08 20:57:38 +02:00
|
|
|
}
|
|
|
|
dirA = test_helpers.InitFS(nil, argsA...)
|
|
|
|
dirB = test_helpers.TmpDir + "/b"
|
|
|
|
dirC = test_helpers.TmpDir + "/c"
|
|
|
|
if err := os.Mkdir(dirB, 0700); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if err := os.Mkdir(dirC, 0700); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
test_helpers.MountOrExit(dirA, dirB, "-reverse", "-extpass", "echo test")
|
|
|
|
test_helpers.MountOrExit(dirB, dirC, "-extpass", "echo test")
|
|
|
|
r = m.Run()
|
|
|
|
test_helpers.UnmountPanic(dirC)
|
|
|
|
test_helpers.UnmountPanic(dirB)
|
|
|
|
|
|
|
|
os.RemoveAll(dirA)
|
|
|
|
os.RemoveAll(dirB)
|
|
|
|
os.RemoveAll(dirC)
|
|
|
|
|
|
|
|
if r != 0 {
|
2021-08-20 17:06:18 +02:00
|
|
|
fmt.Printf("testcases[%d] = %#v failed\n", i, tc)
|
2016-10-08 20:57:38 +02:00
|
|
|
os.Exit(r)
|
|
|
|
}
|
2016-09-25 15:05:09 +02:00
|
|
|
}
|
|
|
|
os.Exit(r)
|
|
|
|
}
|