summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-02-06 20:22:45 +0100
committerJakob Unterwurzacher2016-02-06 20:22:45 +0100
commitb0ee5258b1ac60b9a672d9db0816b17ae12d0e55 (patch)
tree3decdec7e3abf5978c2e936693a034cf838a16ca
parent9078a77850dd680bfa938d9ed7c83600a60c0e7b (diff)
Fix tests - were broken by the refactoring
-rw-r--r--internal/configfile/config_test.go4
-rw-r--r--internal/contentenc/content_api.go5
-rw-r--r--internal/contentenc/content_test.go19
-rw-r--r--internal/fusefrontend/fs.go4
-rw-r--r--internal/nametransform/names_test.go14
-rw-r--r--openssl_benchmark/openssl_test.go24
-rwxr-xr-xtest.bash5
7 files changed, 43 insertions, 32 deletions
diff --git a/internal/configfile/config_test.go b/internal/configfile/config_test.go
index 6606d22..5468b80 100644
--- a/internal/configfile/config_test.go
+++ b/internal/configfile/config_test.go
@@ -4,6 +4,8 @@ import (
"fmt"
"testing"
"time"
+
+ "github.com/rfjakob/gocryptfs/internal/toggledlog"
)
func TestLoadV1(t *testing.T) {
@@ -33,7 +35,7 @@ func TestLoadV2(t *testing.T) {
func TestLoadV2PwdError(t *testing.T) {
if !testing.Verbose() {
- Warn.Enabled = false
+ toggledlog.Warn.Enabled = false
}
_, _, err := LoadConfFile("config_test/v2.conf", "wrongpassword")
if err == nil {
diff --git a/internal/contentenc/content_api.go b/internal/contentenc/content_api.go
index 1700d35..4c6aa00 100644
--- a/internal/contentenc/content_api.go
+++ b/internal/contentenc/content_api.go
@@ -2,6 +2,11 @@ package contentenc
import "github.com/rfjakob/gocryptfs/internal/cryptocore"
+const (
+ // Default plaintext block size
+ DefaultBS = 4096
+)
+
type ContentEnc struct {
// Cryptographic primitives
cryptoCore *cryptocore.CryptoCore
diff --git a/internal/contentenc/content_test.go b/internal/contentenc/content_test.go
index 70ad58d..2272aa3 100644
--- a/internal/contentenc/content_test.go
+++ b/internal/contentenc/content_test.go
@@ -2,6 +2,8 @@ package contentenc
import (
"testing"
+
+ "github.com/rfjakob/gocryptfs/internal/cryptocore"
)
type testRange struct {
@@ -20,8 +22,9 @@ func TestSplitRange(t *testing.T) {
testRange{0, 65536},
testRange{6654, 8945})
- key := make([]byte, KEY_LEN)
- f := NewCryptFS(key, true, false, true)
+ key := make([]byte, cryptocore.KeyLen)
+ cc := cryptocore.New(key, false, true)
+ f := New(cc, DefaultBS)
for _, r := range ranges {
parts := f.ExplodePlainRange(r.offset, r.length)
@@ -31,7 +34,7 @@ func TestSplitRange(t *testing.T) {
t.Errorf("Duplicate block number %d", p.BlockNo)
}
lastBlockNo = p.BlockNo
- if p.Length > DEFAULT_PLAINBS || p.Skip >= DEFAULT_PLAINBS {
+ if p.Length > DefaultBS || p.Skip >= DefaultBS {
t.Errorf("Test fail: n=%d, length=%d, offset=%d\n", p.BlockNo, p.Length, p.Skip)
}
}
@@ -47,8 +50,9 @@ func TestCiphertextRange(t *testing.T) {
testRange{65444, 54},
testRange{6654, 8945})
- key := make([]byte, KEY_LEN)
- f := NewCryptFS(key, true, false, true)
+ key := make([]byte, cryptocore.KeyLen)
+ cc := cryptocore.New(key, false, true)
+ f := New(cc, DefaultBS)
for _, r := range ranges {
@@ -69,8 +73,9 @@ func TestCiphertextRange(t *testing.T) {
}
func TestBlockNo(t *testing.T) {
- key := make([]byte, KEY_LEN)
- f := NewCryptFS(key, true, false, true)
+ key := make([]byte, cryptocore.KeyLen)
+ cc := cryptocore.New(key, false, true)
+ f := New(cc, DefaultBS)
b := f.CipherOffToBlockNo(788)
if b != 0 {
diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go
index 0331215..a2deee5 100644
--- a/internal/fusefrontend/fs.go
+++ b/internal/fusefrontend/fs.go
@@ -21,8 +21,6 @@ import (
"github.com/rfjakob/gocryptfs/internal/configfile"
)
-const plainBS = 4096
-
type FS struct {
pathfs.FileSystem // loopbackFileSystem, see go-fuse/fuse/pathfs/loopback.go
args Args // Stores configuration arguments
@@ -40,7 +38,7 @@ type FS struct {
func NewFS(args Args) *FS {
cryptoCore := cryptocore.New(args.Masterkey, args.OpenSSL, args.GCMIV128)
- contentEnc := contentenc.New(cryptoCore, plainBS)
+ contentEnc := contentenc.New(cryptoCore, contentenc.DefaultBS)
nameTransform := nametransform.New(cryptoCore, args.EMENames)
return &FS{
diff --git a/internal/nametransform/names_test.go b/internal/nametransform/names_test.go
index 4a901be..fdb9f05 100644
--- a/internal/nametransform/names_test.go
+++ b/internal/nametransform/names_test.go
@@ -3,6 +3,8 @@ package nametransform
import (
"bytes"
"testing"
+
+ "github.com/rfjakob/gocryptfs/internal/cryptocore"
)
func TestEncryptPathNoIV(t *testing.T) {
@@ -11,8 +13,9 @@ func TestEncryptPathNoIV(t *testing.T) {
s = append(s, "foo12312312312312312313123123123")
s = append(s, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
- key := make([]byte, KEY_LEN)
- fs := NewCryptFS(key, true, false, true)
+ key := make([]byte, cryptocore.KeyLen)
+ cc := cryptocore.New(key, false, true)
+ fs := New(cc, true)
for _, n := range s {
c := fs.EncryptPathNoIV(n)
@@ -32,19 +35,16 @@ func TestPad16(t *testing.T) {
s = append(s, []byte("12345678901234567"))
s = append(s, []byte("12345678901234567abcdefg"))
- key := make([]byte, KEY_LEN)
- fs := NewCryptFS(key, true, false, true)
-
for i := range s {
orig := s[i]
- padded := fs.pad16(orig)
+ padded := pad16(orig)
if len(padded) <= len(orig) {
t.Errorf("Padded length not bigger than orig: %d", len(padded))
}
if len(padded)%16 != 0 {
t.Errorf("Length is not aligend: %d", len(padded))
}
- unpadded, err := fs.unPad16(padded)
+ unpadded, err := unPad16(padded)
if err != nil {
t.Error("unPad16 returned error:", err)
}
diff --git a/openssl_benchmark/openssl_test.go b/openssl_benchmark/openssl_test.go
index 35abca7..1530f9b 100644
--- a/openssl_benchmark/openssl_test.go
+++ b/openssl_benchmark/openssl_test.go
@@ -12,15 +12,17 @@ import (
"crypto/aes"
"crypto/cipher"
"fmt"
- "github.com/rfjakob/gocryptfs/cryptfs"
- "github.com/spacemonkeygo/openssl"
"os"
"testing"
+
+ "github.com/spacemonkeygo/openssl"
+
+ "github.com/rfjakob/gocryptfs/internal/cryptocore"
)
func TestMain(m *testing.M) {
- fmt.Printf("Benchmarking AES-GCM-%d with 4kB block size\n", cryptfs.KEY_LEN*8)
+ fmt.Printf("Benchmarking AES-GCM-%d with 4kB block size\n", cryptocore.KeyLen*8)
r := m.Run()
os.Exit(r)
@@ -30,7 +32,7 @@ func BenchmarkGoEnc4K(b *testing.B) {
buf := make([]byte, 1024*4)
b.SetBytes(int64(len(buf)))
- var key [cryptfs.KEY_LEN]byte
+ var key [cryptocore.KeyLen]byte
var nonce [12]byte
aes, _ := aes.NewCipher(key[:])
aesgcm, _ := cipher.NewGCM(aes)
@@ -47,7 +49,7 @@ func BenchmarkGoDec4K(b *testing.B) {
buf := make([]byte, 1024*4)
b.SetBytes(int64(len(buf)))
- var key [cryptfs.KEY_LEN]byte
+ var key [cryptocore.KeyLen]byte
var nonce [12]byte
aes, _ := aes.NewCipher(key[:])
aesgcm, _ := cipher.NewGCM(aes)
@@ -67,7 +69,7 @@ func BenchmarkOpensslEnc4K(b *testing.B) {
buf := make([]byte, 1024*4)
b.SetBytes(int64(len(buf)))
- var key [cryptfs.KEY_LEN]byte
+ var key [cryptocore.KeyLen]byte
var nonce [12]byte
// This would be fileID + blockNo
@@ -79,7 +81,7 @@ func BenchmarkOpensslEnc4K(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
ciphertext.Reset()
- ectx, err := openssl.NewGCMEncryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
+ ectx, err := openssl.NewGCMEncryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
if err != nil {
b.FailNow()
}
@@ -112,7 +114,7 @@ func BenchmarkOpensslDec4K(b *testing.B) {
tag := buf[4096:]
buf = buf[0:4096]
- var key [cryptfs.KEY_LEN]byte
+ var key [cryptocore.KeyLen]byte
var nonce [12]byte
var plaintext bytes.Buffer
@@ -121,7 +123,7 @@ func BenchmarkOpensslDec4K(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
plaintext.Reset()
- dctx, err := openssl.NewGCMDecryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
+ dctx, err := openssl.NewGCMDecryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
if err != nil {
b.FailNow()
}
@@ -144,12 +146,12 @@ func BenchmarkOpensslDec4K(b *testing.B) {
func makeOpensslCiphertext() []byte {
buf := make([]byte, 1024*4)
- var key [cryptfs.KEY_LEN]byte
+ var key [cryptocore.KeyLen]byte
var nonce [12]byte
var ciphertext bytes.Buffer
var part []byte
- ectx, _ := openssl.NewGCMEncryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
+ ectx, _ := openssl.NewGCMEncryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
part, _ = ectx.EncryptUpdate(buf)
ciphertext.Write(part)
part, _ = ectx.EncryptFinal()
diff --git a/test.bash b/test.bash
index f90c3da..d662e0f 100755
--- a/test.bash
+++ b/test.bash
@@ -4,7 +4,6 @@ set -eu
cd "$(dirname "$0")"
-#go test ./cryptfs $*
-
source build.bash
-go test ./integration_tests $*
+
+go test ./...