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.
This commit is contained in:
parent
261cf12829
commit
3b61244b72
|
@ -712,9 +712,9 @@ func TestBadname(t *testing.T) {
|
|||
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)
|
||||
}
|
||||
|
@ -735,26 +735,17 @@ func TestBadname(t *testing.T) {
|
|||
if ciphername != "gocryptfs.conf" && ciphername != "gocryptfs.diriv" {
|
||||
encryptedfilename = ciphername
|
||||
// found cipher name of "file"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
//Read encrypted file name to generated invalid filenames
|
||||
fsource, err := os.Open(dir + "/" + encryptedfilename)
|
||||
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)
|
||||
err = ioutil.WriteFile(dir+"/"+encryptedfilename+invalidSuffix, nil, 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)
|
||||
err = ioutil.WriteFile(dir+"/"+encryptedfilename[:len(encryptedfilename)-2]+invalidSuffix, nil, 0600)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue