Skip to content

Commit

Permalink
Remove short test checks, fix broken bccsp tests
Browse files Browse the repository at this point in the history
TestLoadLib failed when running tests with the pkcs11 tag enabled and
without the short flag. This fixes the test and removes all of the
`testing.Short` checks to prevent broken tests related to PKCS11 in CI.

Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm authored and mastersingh24 committed May 23, 2020
1 parent e5634e0 commit 7861a4d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 100 deletions.
3 changes: 0 additions & 3 deletions bccsp/pkcs11/ecdsakey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import (
)

func TestX509PublicKeyImportOptsKeyImporter(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestX509PublicKeyImportOptsKeyImporter")
}
ki := currentBCCSP

_, err := ki.KeyImport("Hello World", &bccsp.X509PublicKeyImportOpts{})
Expand Down
79 changes: 0 additions & 79 deletions bccsp/pkcs11/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ func TestInvalidSKI(t *testing.T) {
}

func TestKeyGenECDSAOpts(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestKeyGenECDSAOpts")
}
// Curve P256
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAP256KeyGenOpts{Temporary: false})
if err != nil {
Expand Down Expand Up @@ -281,9 +278,6 @@ func TestKeyGenECDSAOpts(t *testing.T) {
}

func TestKeyGenAESOpts(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestKeyGenAESOpts")
}
// AES 128
k, err := currentBCCSP.KeyGen(&bccsp.AES128KeyGenOpts{Temporary: false})
if err != nil {
Expand Down Expand Up @@ -331,9 +325,6 @@ func TestKeyGenAESOpts(t *testing.T) {
}

func TestHashOpts(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestHashOpts")
}
msg := []byte("abcd")

// SHA256
Expand Down Expand Up @@ -394,9 +385,6 @@ func TestHashOpts(t *testing.T) {
}

func TestECDSAKeyGenEphemeral(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAKeyGenEphemeral")
}
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: true})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand Down Expand Up @@ -427,9 +415,6 @@ func TestECDSAKeyGenEphemeral(t *testing.T) {
}

func TestECDSAPrivateKeySKI(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAPrivateKeySKI")
}
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand All @@ -442,9 +427,6 @@ func TestECDSAPrivateKeySKI(t *testing.T) {
}

func TestECDSAKeyGenNonEphemeral(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAKeyGenNonEphemeral")
}
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand All @@ -461,9 +443,6 @@ func TestECDSAKeyGenNonEphemeral(t *testing.T) {
}

func TestECDSAGetKeyBySKI(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAGetKeyBySKI")
}
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand All @@ -490,9 +469,6 @@ func TestECDSAGetKeyBySKI(t *testing.T) {
}

func TestECDSAPublicKeyFromPrivateKey(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAPublicKeyFromPrivateKey")
}
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand All @@ -514,10 +490,6 @@ func TestECDSAPublicKeyFromPrivateKey(t *testing.T) {
}

func TestECDSAPublicKeyBytes(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAPublicKeyBytes")
}

k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand All @@ -538,9 +510,6 @@ func TestECDSAPublicKeyBytes(t *testing.T) {
}

func TestECDSAPublicKeySKI(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAPublicKeySKI")
}
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand All @@ -558,9 +527,6 @@ func TestECDSAPublicKeySKI(t *testing.T) {
}

func TestECDSASign(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSASign")
}
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand Down Expand Up @@ -591,9 +557,6 @@ func TestECDSASign(t *testing.T) {
}

func TestECDSAVerify(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAVerify")
}
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand Down Expand Up @@ -671,9 +634,6 @@ func TestECDSAVerify(t *testing.T) {
}

func TestECDSAKeyImportFromExportedKey(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAKeyImportFromExportedKey")
}
// Generate an ECDSA key
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
Expand Down Expand Up @@ -723,9 +683,6 @@ func TestECDSAKeyImportFromExportedKey(t *testing.T) {
}

func TestECDSAKeyImportFromECDSAPublicKey(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSAKeyImportFromECDSAPublicKey")
}
// Generate an ECDSA key
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
Expand Down Expand Up @@ -780,9 +737,6 @@ func TestECDSAKeyImportFromECDSAPublicKey(t *testing.T) {
}

func TestKeyImportFromX509ECDSAPublicKey(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestKeyImportFromX509ECDSAPublicKey")
}
// Generate an ECDSA key
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
Expand Down Expand Up @@ -910,9 +864,6 @@ func TestKeyImportFromX509ECDSAPublicKey(t *testing.T) {
}

func TestECDSASignatureEncoding(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSASignatureEncoding")
}
v := []byte{0x30, 0x07, 0x02, 0x01, 0x8F, 0x02, 0x02, 0xff, 0xf1}
_, err := asn1.Unmarshal(v, &utils.ECDSASignature{})
if err == nil {
Expand Down Expand Up @@ -951,9 +902,6 @@ func TestECDSASignatureEncoding(t *testing.T) {
}

func TestECDSALowS(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestECDSALowS")
}
// Ensure that signature with low-S are generated
k, err := currentBCCSP.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
Expand Down Expand Up @@ -1016,9 +964,6 @@ func TestECDSALowS(t *testing.T) {
}

func TestAESKeyGen(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestAESKeyGen")
}
k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating AES_256 key [%s]", err)
Expand All @@ -1043,9 +988,6 @@ func TestAESKeyGen(t *testing.T) {
}

func TestAESEncrypt(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestAESEncrypt")
}
k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating AES_256 key [%s]", err)
Expand All @@ -1061,9 +1003,6 @@ func TestAESEncrypt(t *testing.T) {
}

func TestAESDecrypt(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestAESDecrypt")
}
k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating AES_256 key [%s]", err)
Expand All @@ -1090,9 +1029,6 @@ func TestAESDecrypt(t *testing.T) {
}

func TestHMACTruncated256KeyDerivOverAES256Key(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestHMACTruncated256KeyDerivOverAES256Key")
}
k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating AES_256 key [%s]", err)
Expand Down Expand Up @@ -1141,9 +1077,6 @@ func TestHMACTruncated256KeyDerivOverAES256Key(t *testing.T) {
}

func TestHMACKeyDerivOverAES256Key(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestHMACKeyDerivOverAES256Key")
}
k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating AES_256 key [%s]", err)
Expand Down Expand Up @@ -1173,9 +1106,6 @@ func TestHMACKeyDerivOverAES256Key(t *testing.T) {
}

func TestAES256KeyImport(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestAES256KeyImport")
}
raw, err := sw.GetRandomBytes(32)
if err != nil {
t.Fatalf("Failed generating AES key [%s]", err)
Expand Down Expand Up @@ -1223,9 +1153,6 @@ func TestAES256KeyImport(t *testing.T) {
}

func TestAES256KeyImportBadPaths(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestAES256KeyImportBadPaths")
}
_, err := currentBCCSP.KeyImport(nil, &bccsp.AES256ImportKeyOpts{Temporary: false})
if err == nil {
t.Fatal("Failed importing key. Must fail on importing nil key")
Expand All @@ -1238,9 +1165,6 @@ func TestAES256KeyImportBadPaths(t *testing.T) {
}

func TestAES256KeyGenSKI(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestAES256KeyGenSKI")
}
k, err := currentBCCSP.KeyGen(&bccsp.AESKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating AES_256 key [%s]", err)
Expand Down Expand Up @@ -1268,9 +1192,6 @@ func TestAES256KeyGenSKI(t *testing.T) {
}

func TestSHA(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestSHA")
}
for i := 0; i < 100; i++ {
b, err := sw.GetRandomBytes(i)
if err != nil {
Expand Down
20 changes: 2 additions & 18 deletions bccsp/pkcs11/pkcs11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import (
)

func TestKeyGenFailures(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestKeyGenFailures")
}
var testOpts bccsp.KeyGenOpts
ki := currentBCCSP
_, err := ki.KeyGen(testOpts)
Expand All @@ -30,9 +27,6 @@ func TestKeyGenFailures(t *testing.T) {
}

func TestLoadLib(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestLoadLib")
}
// Setup PKCS11 library and provide initial set of values
lib, pin, label := FindPKCS11Lib()

Expand All @@ -49,18 +43,15 @@ func TestLoadLib(t *testing.T) {
// Test for invalid label
_, _, _, err = loadLib(lib, pin, "badLabel")
assert.Error(t, err)
assert.Contains(t, err.Error(), "Could not find token with label")
assert.Contains(t, err.Error(), "could not find token with label")

// Test for no pin
_, _, _, err = loadLib(lib, "", label)
assert.Error(t, err)
assert.Contains(t, err.Error(), "No PIN set")
assert.Contains(t, err.Error(), "Login failed: pkcs11")
}

func TestNamedCurveFromOID(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestNamedCurveFromOID")
}
// Test for valid P224 elliptic curve
namedCurve := namedCurveFromOID(oidNamedCurveP224)
assert.Equal(t, elliptic.P224(), namedCurve, "Did not receive expected named curve for oidNamedCurveP224")
Expand All @@ -85,9 +76,6 @@ func TestNamedCurveFromOID(t *testing.T) {
}

func TestPKCS11GetSession(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestPKCS11GetSession")
}
var sessions []pkcs11.SessionHandle
for i := 0; i < 3*sessionCacheSize; i++ {
session, err := currentBCCSP.(*impl).getSession()
Expand Down Expand Up @@ -123,10 +111,6 @@ func TestPKCS11GetSession(t *testing.T) {
}

func TestPKCS11ECKeySignVerify(t *testing.T) {
if testing.Short() {
t.Skip("Skipping TestPKCS11ECKeySignVerify")
}

msg1 := []byte("This is my very authentic message")
msg2 := []byte("This is my very unauthentic message")
hash1, _ := currentBCCSP.Hash(msg1, &bccsp.SHAOpts{})
Expand Down

0 comments on commit 7861a4d

Please sign in to comment.