diff options
author | Jakob Unterwurzacher | 2020-06-06 12:50:39 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2020-06-06 12:53:45 +0200 |
commit | 3b61244b72f74a25651d4ba184ac7cc62c937db0 (patch) | |
tree | 525f41948b45c118723235ac8e64b7731e9b4918 | |
parent | 261cf12829dcef31f1a02559b898e5067a03af31 (diff) |
tests: TestBadname: simplify test by using empty files
Simplify the tests by using empty files. Empty
files are valid, and we don't check the content
anyway.
Also adjust comment style a little and add
a missing break statement.
-rw-r--r-- | tests/cli/cli_test.go | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go index 08abed9..bb1558c 100644 --- a/tests/cli/cli_test.go +++ b/tests/cli/cli_test.go @@ -708,18 +708,18 @@ func TestBadname(t *testing.T) { validFileName := "file" invalidSuffix := ".invalid_file" - //use static suffix for testing + // use static suffix for testing test_helpers.MountOrFatal(t, dir, mnt, "-badname=*", "-extpass=echo test") defer test_helpers.UnmountPanic(mnt) - //write one valid file + // write one valid filename (empty content) file := mnt + "/" + validFileName - err := ioutil.WriteFile(file, []byte("somecontent"), 0600) + err := ioutil.WriteFile(file, nil, 0600) if err != nil { t.Fatal(err) } - //read encrypted file name + // read encrypted file name fread, err := os.Open(dir) if err != nil { t.Fatal(err) @@ -734,32 +734,23 @@ func TestBadname(t *testing.T) { for _, ciphername := range ciphernames { if ciphername != "gocryptfs.conf" && ciphername != "gocryptfs.diriv" { encryptedfilename = ciphername - //found cipher name of "file" + // found cipher name of "file" + break } } - //Read encrypted file name to generated invalid filenames - fsource, err := os.Open(dir + "/" + encryptedfilename) + // write invalid file which should be decodable + err = ioutil.WriteFile(dir+"/"+encryptedfilename+invalidSuffix, nil, 0600) if err != nil { t.Fatal(err) } - content, err := ioutil.ReadAll(fsource) - if err != nil { - t.Fatal(err) - } - fsource.Close() - //write invalid file which should be decodable - err = ioutil.WriteFile(dir+"/"+encryptedfilename+invalidSuffix, content, 0600) - if err != nil { - t.Fatal(err) - } - //write invalid file which is not decodable (cropping the encrpyted file name) - err = ioutil.WriteFile(dir+"/"+encryptedfilename[:len(encryptedfilename)-2]+invalidSuffix, content, 0600) + // write invalid file which is not decodable (cropping the encrpyted file name) + err = ioutil.WriteFile(dir+"/"+encryptedfilename[:len(encryptedfilename)-2]+invalidSuffix, nil, 0600) if err != nil { t.Fatal(err) } - //check for filenames + // check for filenames f, err := os.Open(mnt) if err != nil { t.Fatal(err) |