wallet request validation test. loopify auth request validation test.

This commit is contained in:
Daniel Krol 2022-06-21 19:27:54 -04:00
parent 408a4817dc
commit 39015963e6
2 changed files with 56 additions and 27 deletions

View file

@ -101,31 +101,33 @@ func TestServerValidateAuthRequest(t *testing.T) {
t.Fatalf("Expected valid AuthRequest to successfully validate")
}
authRequest = AuthRequest{Email: "joe@example.com", Password: "aoeu"}
if authRequest.validate() {
t.Fatalf("Expected AuthRequest with missing device to not successfully validate")
tt := []struct {
authRequest AuthRequest
failureDescription string
}{
{
AuthRequest{Email: "joe@example.com", Password: "aoeu"},
"Expected AuthRequest with missing device to not successfully validate",
}, {
AuthRequest{DeviceId: "dId", Email: "joe-example.com", Password: "aoeu"},
"Expected AuthRequest with invalid email to not successfully validate",
}, {
// Note that Golang's email address parser, which I use, will accept
// "Joe <joe@example.com>" so we need to make sure to avoid accepting it. See
// the implementation.
AuthRequest{DeviceId: "dId", Email: "Joe <joe@example.com>", Password: "aoeu"},
"Expected AuthRequest with email with unexpected formatting to not successfully validate",
}, {
AuthRequest{DeviceId: "dId", Password: "aoeu"},
"Expected AuthRequest with missing email to not successfully validate",
}, {
AuthRequest{DeviceId: "dId", Email: "joe@example.com"},
"Expected AuthRequest with missing password to not successfully validate",
},
}
authRequest = AuthRequest{DeviceId: "dId", Email: "joe-example.com", Password: "aoeu"}
if authRequest.validate() {
t.Fatalf("Expected AuthRequest with invalid email to not successfully validate")
}
// Note that Golang's email address parser, which I use, will accept
// "Joe <joe@example.com>" so we need to make sure to avoid accepting it. See
// the implementation.
authRequest = AuthRequest{DeviceId: "dId", Email: "Joe <joe@example.com>", Password: "aoeu"}
if authRequest.validate() {
t.Fatalf("Expected AuthRequest with email with unexpected formatting to not successfully validate")
}
authRequest = AuthRequest{DeviceId: "dId", Password: "aoeu"}
if authRequest.validate() {
t.Fatalf("Expected AuthRequest with missing email to not successfully validate")
}
authRequest = AuthRequest{DeviceId: "dId", Email: "joe@example.com"}
if authRequest.validate() {
t.Fatalf("Expected AuthRequest with missing password to not successfully validate")
for _, tc := range tt {
if tc.authRequest.validate() {
t.Errorf(tc.failureDescription)
}
}
}

View file

@ -357,6 +357,33 @@ func TestServerPostWallet(t *testing.T) {
}
func TestServerValidateWalletRequest(t *testing.T) {
// also add a basic test case for this in TestServerAuthHandlerSuccess to make sure it's called at all
t.Fatalf("Test me: Implement and test WalletRequest.validate()")
walletRequest := WalletRequest{Token: "seekrit", EncryptedWallet: "my-encrypted-wallet", Hmac: "my-hmac", Sequence: 2}
if !walletRequest.validate() {
t.Fatalf("Expected valid WalletRequest to successfully validate")
}
tt := []struct {
walletRequest WalletRequest
failureDescription string
}{
{
WalletRequest{EncryptedWallet: "my-encrypted-wallet", Hmac: "my-hmac", Sequence: 2},
"Expected WalletRequest with missing token to not successfully validate",
}, {
WalletRequest{Token: "seekrit", Hmac: "my-hmac", Sequence: 2},
"Expected WalletRequest with missing encrypted wallet to not successfully validate",
}, {
WalletRequest{Token: "seekrit", EncryptedWallet: "my-encrypted-wallet", Sequence: 2},
"Expected WalletRequest with missing hmac to not successfully validate",
}, {
WalletRequest{Token: "seekrit", EncryptedWallet: "my-encrypted-wallet", Hmac: "my-hmac", Sequence: 0},
"Expected WalletRequest with sequence < 1 to not successfully validate",
},
}
for _, tc := range tt {
if tc.walletRequest.validate() {
t.Errorf(tc.failureDescription)
}
}
}