From e9179c927130cf6dd4c6155604ff1c6ad290ec6c Mon Sep 17 00:00:00 2001 From: Andrei Burdulescu Date: Tue, 12 Dec 2023 15:28:38 +0200 Subject: [PATCH] Fix tests --- internal/aes/cbc_test.go | 8 ++++---- internal/aes/cmac_test.go | 4 ++-- internal/aes/ecb_test.go | 6 +++--- internal/aes/gcm_test.go | 8 ++++---- internal/hash/sha_test.go | 6 +++--- internal/kdf/pbkdf2_test.go | 14 ++++++++------ internal/keywrap/aes/cmd/keywrap_test.go | 6 +++--- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/internal/aes/cbc_test.go b/internal/aes/cbc_test.go index 88e7e85..da23a4b 100644 --- a/internal/aes/cbc_test.go +++ b/internal/aes/cbc_test.go @@ -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") } }) @@ -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) diff --git a/internal/aes/cmac_test.go b/internal/aes/cmac_test.go index da4328f..28214a4 100644 --- a/internal/aes/cmac_test.go +++ b/internal/aes/cmac_test.go @@ -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) } @@ -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) diff --git a/internal/aes/ecb_test.go b/internal/aes/ecb_test.go index 3dba698..386963f 100644 --- a/internal/aes/ecb_test.go +++ b/internal/aes/ecb_test.go @@ -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") } }) @@ -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) diff --git a/internal/aes/gcm_test.go b/internal/aes/gcm_test.go index 551f7b2..403c3b3 100644 --- a/internal/aes/gcm_test.go +++ b/internal/aes/gcm_test.go @@ -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") } }) @@ -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) diff --git a/internal/hash/sha_test.go b/internal/hash/sha_test.go index c6702f9..d169071 100644 --- a/internal/hash/sha_test.go +++ b/internal/hash/sha_test.go @@ -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") } }) @@ -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) } diff --git a/internal/kdf/pbkdf2_test.go b/internal/kdf/pbkdf2_test.go index 0430dde..522e310 100644 --- a/internal/kdf/pbkdf2_test.go +++ b/internal/kdf/pbkdf2_test.go @@ -7,6 +7,8 @@ import ( "os" "path/filepath" "testing" + + "bandr.me/p/pocryp/internal/testutil" ) func bytesFromHex(t testing.TB, s string) []byte { @@ -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) @@ -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") } }) diff --git a/internal/keywrap/aes/cmd/keywrap_test.go b/internal/keywrap/aes/cmd/keywrap_test.go index 026da40..5c7c782 100644 --- a/internal/keywrap/aes/cmd/keywrap_test.go +++ b/internal/keywrap/aes/cmd/keywrap_test.go @@ -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") } }) @@ -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)