1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

Fixed failing tests

This commit is contained in:
Adrian Utrilla
2016-08-24 16:48:56 -07:00
parent 3f277d2ddb
commit b8cb6cf016
3 changed files with 15 additions and 12 deletions

View File

@@ -3,4 +3,5 @@ FROM golang:1.7
COPY . /go/src/go.mozilla.org/sops
WORKDIR /go/src/go.mozilla.org/sops
RUN go get -d -v
RUN go test ./...
RUN go install -v ./...

View File

@@ -12,7 +12,7 @@ func TestDecrypt(t *testing.T) {
expected := "foo"
key := []byte(strings.Repeat("f", 32))
message := `ENC[AES256_GCM,data:oYyi,iv:MyIDYbT718JRr11QtBkcj3Dwm4k1aCGZBVeZf0EyV8o=,tag:t5z2Z023Up0kxwCgw1gNxg==,type:str]`
decryption, err := Decrypt(message, key, []byte("bar:"))
decryption, err := Cipher{}.Decrypt(message, key, []byte("bar:"))
if err != nil {
t.Errorf("%s", err)
}
@@ -23,7 +23,7 @@ func TestDecrypt(t *testing.T) {
func TestDecryptInvalidAad(t *testing.T) {
message := `ENC[AES256_GCM,data:oYyi,iv:MyIDYbT718JRr11QtBkcj3Dwm4k1aCGZBVeZf0EyV8o=,tag:t5z2Z023Up0kxwCgw1gNxg==,type:str]`
_, err := Decrypt(message, []byte(strings.Repeat("f", 32)), []byte(""))
_, err := Cipher{}.Decrypt(message, []byte(strings.Repeat("f", 32)), []byte(""))
if err == nil {
t.Errorf("Decrypting with an invalid AAC should fail")
}
@@ -36,12 +36,12 @@ func TestRoundtripString(t *testing.T) {
if x == "" {
return true
}
s, err := Encrypt(x, key, aad)
s, err := Cipher{}.Encrypt(x, key, aad)
if err != nil {
fmt.Println(err)
return false
}
d, err := Decrypt(s, key, aad)
d, err := Cipher{}.Decrypt(s, key, aad)
if err != nil {
return false
}
@@ -55,12 +55,12 @@ func TestRoundtripString(t *testing.T) {
func TestRoundtripFloat(t *testing.T) {
key := []byte(strings.Repeat("f", 32))
f := func(x float64) bool {
s, err := Encrypt(x, key, []byte(""))
s, err := Cipher{}.Encrypt(x, key, []byte(""))
if err != nil {
fmt.Println(err)
return false
}
d, err := Decrypt(s, key, []byte(""))
d, err := Cipher{}.Decrypt(s, key, []byte(""))
if err != nil {
return false
}
@@ -74,12 +74,12 @@ func TestRoundtripFloat(t *testing.T) {
func TestRoundtripInt(t *testing.T) {
key := []byte(strings.Repeat("f", 32))
f := func(x int) bool {
s, err := Encrypt(x, key, []byte(""))
s, err := Cipher{}.Encrypt(x, key, []byte(""))
if err != nil {
fmt.Println(err)
return false
}
d, err := Decrypt(s, key, []byte(""))
d, err := Cipher{}.Decrypt(s, key, []byte(""))
if err != nil {
return false
}
@@ -93,12 +93,12 @@ func TestRoundtripInt(t *testing.T) {
func TestRoundtripBool(t *testing.T) {
key := []byte(strings.Repeat("f", 32))
f := func(x bool) bool {
s, err := Encrypt(x, key, []byte(""))
s, err := Cipher{}.Encrypt(x, key, []byte(""))
if err != nil {
fmt.Println(err)
return false
}
d, err := Decrypt(s, key, []byte(""))
d, err := Cipher{}.Decrypt(s, key, []byte(""))
if err != nil {
return false
}

View File

@@ -2,6 +2,7 @@ package sops
import (
"bytes"
"go.mozilla.org/sops/aes"
"reflect"
"testing"
)
@@ -20,14 +21,15 @@ func TestUnencryptedSuffix(t *testing.T) {
Value: "bar",
},
}
_, err := tree.Encrypt(bytes.Repeat([]byte("f"), 32))
cipher := aes.Cipher{}
_, err := tree.Encrypt(bytes.Repeat([]byte("f"), 32), cipher)
if err != nil {
t.Errorf("Encrypting the tree failed: %s", err)
}
if !reflect.DeepEqual(tree.Branch, expected) {
t.Errorf("Trees don't match: \ngot \t\t%+v,\n expected \t\t%+v", tree.Branch, expected)
}
_, err = tree.Decrypt(bytes.Repeat([]byte("f"), 32))
_, err = tree.Decrypt(bytes.Repeat([]byte("f"), 32), cipher)
if err != nil {
t.Errorf("Decrypting the tree failed: %s", err)
}