From 3b61244b72f74a25651d4ba184ac7cc62c937db0 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 6 Jun 2020 12:50:39 +0200 Subject: 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. --- tests/cli/cli_test.go | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'tests/cli') 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) -- cgit v1.2.3