Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aburdulescu committed Dec 12, 2023
1 parent defe9d7 commit e9179c9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
8 changes: 4 additions & 4 deletions internal/aes/cbc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ func TestCbcCmd(t *testing.T) {
})
}
t.Run("NoKey", func(t *testing.T) {
if err := CbcCmd(); err == nil {
if err := testutil.RunCmd(CbcCmd); err == nil {
t.Fatal("expected and error")
}
})
t.Run("KeyAsHexAndFromFile", func(t *testing.T) {
if err := CbcCmd("-key=0011", "-key-file=foo"); err == nil {
if err := testutil.RunCmd(CbcCmd, "-key=0011", "-key-file=foo"); err == nil {
t.Fatal("expected and error")
}
})
t.Run("NoIv", func(t *testing.T) {
if err := CbcCmd("-key=0011"); err == nil {
if err := testutil.RunCmd(CbcCmd, "-key=0011"); err == nil {
t.Fatal("expected and error")
}
})
Expand All @@ -63,7 +63,7 @@ func testCbcCmd(t *testing.T, tmp string, direction string, key, iv, input, expe
"-in", in,
"-out", out,
)
if err := CbcCmd(args...); err != nil {
if err := testutil.RunCmd(CbcCmd, args...); err != nil {
t.Fatal(err)
}
testutil.ExpectFileContent(t, out, expected)
Expand Down
4 changes: 2 additions & 2 deletions internal/aes/cmac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestCmacCmd(t *testing.T) {

args := []string{"-bin", "-key", key, "-in", in, "-out", out}

if err := CmacGenerateCmd(args...); err != nil {
if err := testutil.RunCmd(CmacGenerateCmd, args...); err != nil {
t.Fatal(err)
}

Expand All @@ -57,7 +57,7 @@ func TestCmacCmd(t *testing.T) {

args := []string{"-key", key, "-in", in, "-mac", test.mac}

if err := CmacVerifyCmd(args...); err != nil {
if err := testutil.RunCmd(CmacVerifyCmd, args...); err != nil {
t.Log("msg =", test.msg)
t.Log("mac =", test.mac)
t.Fatal(err)
Expand Down
6 changes: 3 additions & 3 deletions internal/aes/ecb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func TestEcbCmd(t *testing.T) {
}
}
t.Run("NoKey", func(t *testing.T) {
if err := EcbCmd(); err == nil {
if err := testutil.RunCmd(EcbCmd); err == nil {
t.Fatal("expected and error")
}
})
t.Run("KeyAsHexAndFromFile", func(t *testing.T) {
if err := EcbCmd("-key=0011", "-key-file=foo"); err == nil {
if err := testutil.RunCmd(EcbCmd, "-key=0011", "-key-file=foo"); err == nil {
t.Fatal("expected and error")
}
})
Expand All @@ -55,7 +55,7 @@ func testEcbCmd(t *testing.T, tmp string, direction string, key, input, expected
"-in", in,
"-out", out,
)
if err := EcbCmd(args...); err != nil {
if err := testutil.RunCmd(EcbCmd, args...); err != nil {
t.Fatal(err)
}
testutil.ExpectFileContent(t, out, expected)
Expand Down
8 changes: 4 additions & 4 deletions internal/aes/gcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ func TestGcmCmd(t *testing.T) {
})
}
t.Run("NoKey", func(t *testing.T) {
if err := GcmCmd(); err == nil {
if err := testutil.RunCmd(GcmCmd); err == nil {
t.Fatal("expected and error")
}
})
t.Run("KeyAsHexAndFromFile", func(t *testing.T) {
if err := GcmCmd("-key=0011", "-key-file=foo"); err == nil {
if err := testutil.RunCmd(GcmCmd, "-key=0011", "-key-file=foo"); err == nil {
t.Fatal("expected and error")
}
})
t.Run("NoIv", func(t *testing.T) {
if err := GcmCmd("-key=0011"); err == nil {
if err := testutil.RunCmd(GcmCmd, "-key=0011"); err == nil {
t.Fatal("expected and error")
}
})
Expand Down Expand Up @@ -71,7 +71,7 @@ func testGcm(t *testing.T, tmp string, direction string, key, nonce, aad, input,
}
args = append(args, "-aad", dstpath)
}
if err := GcmCmd(args...); err != nil {
if err := testutil.RunCmd(GcmCmd, args...); err != nil {
t.Fatal(err)
}
testutil.ExpectFileContent(t, out, expected)
Expand Down
6 changes: 3 additions & 3 deletions internal/hash/sha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
func TestShaCmd(t *testing.T) {

t.Run("NoAlg", func(t *testing.T) {
if err := ShaCmd(); err == nil {
if err := testutil.RunCmd(ShaCmd); err == nil {
t.Fatal("expected error")
}
})

t.Run("InvalidAlg", func(t *testing.T) {
if err := ShaCmd("-alg=foo"); err == nil {
if err := testutil.RunCmd(ShaCmd, "-alg=foo"); err == nil {
t.Fatal("expected error")
}
})
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestShaCmd(t *testing.T) {

args := []string{"-alg", test.alg, "-in", in, "-out", out, "-bin"}

if err := ShaCmd(args...); err != nil {
if err := testutil.RunCmd(ShaCmd, args...); err != nil {
t.Fatal(err)
}

Expand Down
14 changes: 8 additions & 6 deletions internal/kdf/pbkdf2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"path/filepath"
"testing"

"bandr.me/p/pocryp/internal/testutil"
)

func bytesFromHex(t testing.TB, s string) []byte {
Expand Down Expand Up @@ -67,7 +69,7 @@ func TestPbkdf2Cmd(t *testing.T) {
"-hash=SHA-1",
"-out", out,
}
if err := Pbkdf2Cmd(args...); err != nil {
if err := testutil.RunCmd(Pbkdf2Cmd, args...); err != nil {
t.Fatal(err)
}
result, err := os.ReadFile(out)
Expand All @@ -82,27 +84,27 @@ func TestPbkdf2Cmd(t *testing.T) {
})
}
t.Run("NoKey", func(t *testing.T) {
if err := Pbkdf2Cmd(); err == nil {
if err := testutil.RunCmd(Pbkdf2Cmd); err == nil {
t.Fatal("expected and error")
}
})
t.Run("KeyAsHexAndFromFile", func(t *testing.T) {
if err := Pbkdf2Cmd("-key=0011", "-key-file=foo"); err == nil {
if err := testutil.RunCmd(Pbkdf2Cmd, "-key=0011", "-key-file=foo"); err == nil {
t.Fatal("expected and error")
}
})
t.Run("NoSalt", func(t *testing.T) {
if err := Pbkdf2Cmd("-key=0011"); err == nil {
if err := testutil.RunCmd(Pbkdf2Cmd, "-key=0011"); err == nil {
t.Fatal("expected and error")
}
})
t.Run("SaltAsHexAndFromFile", func(t *testing.T) {
if err := Pbkdf2Cmd("-key=0011", "-salt=0011", "-salt-file=foo"); err == nil {
if err := testutil.RunCmd(Pbkdf2Cmd, "-key=0011", "-salt=0011", "-salt-file=foo"); err == nil {
t.Fatal("expected and error")
}
})
t.Run("InvalidHashFunc", func(t *testing.T) {
if err := Pbkdf2Cmd("-key=0011", "-salt=0011", "-hash=foo"); err == nil {
if err := testutil.RunCmd(Pbkdf2Cmd, "-key=0011", "-salt=0011", "-hash=foo"); err == nil {
t.Fatal("expected and error")
}
})
Expand Down
6 changes: 3 additions & 3 deletions internal/keywrap/aes/cmd/keywrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func TestCmd(t *testing.T) {
})
}
t.Run("NoKey", func(t *testing.T) {
if err := Run(); err == nil {
if err := testutil.RunCmd(Cmd); err == nil {
t.Fatal("expected and error")
}
})
t.Run("KeyAsHexAndFromFile", func(t *testing.T) {
if err := Run("-key=0011", "-key-file=foo"); err == nil {
if err := testutil.RunCmd(Cmd, "-key=0011", "-key-file=foo"); err == nil {
t.Fatal("expected and error")
}
})
Expand All @@ -48,7 +48,7 @@ func testCmd(t *testing.T, tmp string, direction string, key, input, expected []
"-in", in,
"-out", out,
)
if err := Run(args...); err != nil {
if err := testutil.RunCmd(Cmd, args...); err != nil {
t.Fatal(err)
}
testutil.ExpectFileContent(t, out, expected)
Expand Down

0 comments on commit e9179c9

Please sign in to comment.