-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
534 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package signer | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestSignatureIntegrityError(t *testing.T) { | ||
expectedMsg := "signature is invalid. Error: se produjo un error" | ||
validateErrorMsg(SignatureIntegrityError{err: fmt.Errorf("se produjo un error")}, expectedMsg, t) | ||
} | ||
|
||
func TestMalformedSignatureError(t *testing.T) { | ||
expectedMsg := "signature envelope format is malformed" | ||
validateErrorMsg(MalformedSignatureError{}, expectedMsg, t) | ||
|
||
expectedMsg = "Se produjo un error" | ||
validateErrorMsg(MalformedSignatureError{msg: expectedMsg}, expectedMsg, t) | ||
} | ||
|
||
func TestUnsupportedSignatureFormatError(t *testing.T) { | ||
expectedMsg := "signature envelope format with media type \"hola\" is not supported" | ||
validateErrorMsg(UnsupportedSignatureFormatError{mediaType: "hola"}, expectedMsg, t) | ||
} | ||
|
||
func TestUnsupportedSigningKeyError(t *testing.T) { | ||
expectedMsg := "signing key is not supported" | ||
validateErrorMsg(UnsupportedSigningKeyError{}, expectedMsg, t) | ||
validateErrorMsg(UnsupportedSigningKeyError{keyType: "RSA"}, expectedMsg, t) | ||
validateErrorMsg(UnsupportedSigningKeyError{keyLength: 1024}, expectedMsg, t) | ||
|
||
expectedMsg = "\"RSA\" signing key of size 1024 is not supported" | ||
validateErrorMsg(UnsupportedSigningKeyError{keyType: "RSA", keyLength: 1024}, expectedMsg, t) | ||
} | ||
|
||
func TestMalformedArgumentError(t *testing.T) { | ||
expectedMsg := "\"hola\" param is malformed" | ||
validateErrorMsg(MalformedArgumentError{param: "hola"}, expectedMsg, t) | ||
|
||
expectedMsg = "\"hola\" param is malformed. Error: se produjo un error" | ||
validateErrorMsg(MalformedArgumentError{param: "hola", err: fmt.Errorf("se produjo un error")}, expectedMsg, t) | ||
} | ||
|
||
func TestSignatureAlgoNotSupportedError(t *testing.T) { | ||
expectedMsg := "signature algorithm \"hola\" is not supported" | ||
validateErrorMsg(SignatureAlgoNotSupportedError{alg: "hola"}, expectedMsg, t) | ||
} | ||
|
||
func TestMalformedSignRequestError(t *testing.T) { | ||
expectedMsg := "SignRequest is malformed" | ||
validateErrorMsg(MalformedSignRequestError{}, expectedMsg, t) | ||
|
||
expectedMsg = "Se produjo un error" | ||
validateErrorMsg(MalformedSignRequestError{msg: expectedMsg}, expectedMsg, t) | ||
} | ||
|
||
func validateErrorMsg(err error, expectedMsg string, t *testing.T) { | ||
foundMsg := err.Error() | ||
if expectedMsg != foundMsg { | ||
t.Errorf("Expected %q but found %q", expectedMsg, foundMsg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.