tests: add raw64 tests

Also, use "%#v" instead of JSON for debug output.
This means we can unexport all fields.
This commit is contained in:
Jakob Unterwurzacher 2016-11-01 18:39:00 +01:00
parent d41492bcbc
commit 964e0e6b36
1 changed files with 26 additions and 25 deletions

View File

@ -13,7 +13,6 @@ package matrix
import ( import (
"bytes" "bytes"
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -34,23 +33,25 @@ import (
var testcase testcaseMatrix var testcase testcaseMatrix
type testcaseMatrix struct { type testcaseMatrix struct {
// Exported so we can dump the struct using json.Marshal plaintextnames bool
Plaintextnames bool openssl string
Openssl string aessiv bool
Aessiv bool raw64 bool
} }
var matrix = []testcaseMatrix{ var matrix = []testcaseMatrix{
// Normal // Normal
{false, "auto", false}, {false, "auto", false, false},
{false, "true", false}, {false, "true", false, false},
{false, "false", false}, {false, "false", false, false},
// Plaintextnames // Plaintextnames
{true, "true", false}, {true, "true", false, false},
{true, "false", false}, {true, "false", false, false},
// AES-SIV (does not use openssl, no need to test permutations) // AES-SIV (does not use openssl, no need to test permutations)
{false, "auto", true}, {false, "auto", true, false},
{true, "auto", true}, {true, "auto", true, false},
// Raw64
{false, "auto", false, true},
} }
// This is the entry point for the tests // This is the entry point for the tests
@ -58,19 +59,19 @@ func TestMain(m *testing.M) {
// Make "testing.Verbose()" return the correct value // Make "testing.Verbose()" return the correct value
flag.Parse() flag.Parse()
for _, testcase = range matrix { for _, testcase = range matrix {
if !cryptocore.HaveModernGoGCM && testcase.Openssl != "true" { if !cryptocore.HaveModernGoGCM && testcase.openssl != "true" {
fmt.Printf("Skipping Go GCM variant, Go installation is too old") fmt.Printf("Skipping Go GCM variant, Go installation is too old")
continue continue
} }
if testing.Verbose() { if testing.Verbose() {
j, _ := json.Marshal(testcase) fmt.Printf("matrix: testcase = %#v\n", testcase)
fmt.Printf("matrix: testcase = %s\n", string(j))
} }
test_helpers.ResetTmpDir(!testcase.Plaintextnames) test_helpers.ResetTmpDir(!testcase.plaintextnames)
opts := []string{"-zerokey"} opts := []string{"-zerokey"}
opts = append(opts, fmt.Sprintf("-openssl=%v", testcase.Openssl)) opts = append(opts, fmt.Sprintf("-openssl=%v", testcase.openssl))
opts = append(opts, fmt.Sprintf("-plaintextnames=%v", testcase.Plaintextnames)) opts = append(opts, fmt.Sprintf("-plaintextnames=%v", testcase.plaintextnames))
opts = append(opts, fmt.Sprintf("-aessiv=%v", testcase.Aessiv)) opts = append(opts, fmt.Sprintf("-aessiv=%v", testcase.aessiv))
opts = append(opts, fmt.Sprintf("-raw64=%v", testcase.raw64))
test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, opts...) test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, opts...)
r := m.Run() r := m.Run()
test_helpers.UnmountPanic(test_helpers.DefaultPlainDir) test_helpers.UnmountPanic(test_helpers.DefaultPlainDir)
@ -474,17 +475,17 @@ func TestRmwRace(t *testing.T) {
func TestFiltered(t *testing.T) { func TestFiltered(t *testing.T) {
filteredFile := test_helpers.DefaultPlainDir + "/gocryptfs.conf" filteredFile := test_helpers.DefaultPlainDir + "/gocryptfs.conf"
file, err := os.Create(filteredFile) file, err := os.Create(filteredFile)
if testcase.Plaintextnames && err == nil { if testcase.plaintextnames && err == nil {
t.Errorf("should have failed but didn't") t.Errorf("should have failed but didn't")
} else if !testcase.Plaintextnames && err != nil { } else if !testcase.plaintextnames && err != nil {
t.Error(err) t.Error(err)
} }
file.Close() file.Close()
err = os.Remove(filteredFile) err = os.Remove(filteredFile)
if testcase.Plaintextnames && err == nil { if testcase.plaintextnames && err == nil {
t.Errorf("should have failed but didn't") t.Errorf("should have failed but didn't")
} else if !testcase.Plaintextnames && err != nil { } else if !testcase.plaintextnames && err != nil {
t.Error(err) t.Error(err)
} }
} }
@ -496,9 +497,9 @@ func TestFilenameEncryption(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
_, err = os.Stat(test_helpers.DefaultCipherDir + "/TestFilenameEncryption.txt") _, err = os.Stat(test_helpers.DefaultCipherDir + "/TestFilenameEncryption.txt")
if testcase.Plaintextnames && err != nil { if testcase.plaintextnames && err != nil {
t.Errorf("plaintextnames not working: %v", err) t.Errorf("plaintextnames not working: %v", err)
} else if !testcase.Plaintextnames && err == nil { } else if !testcase.plaintextnames && err == nil {
t.Errorf("file name encryption not working") t.Errorf("file name encryption not working")
} }
} }