Skip to content

Commit fee0e2f

Browse files
author
Rijul Gulati
committed
Improved test coverage
1 parent 2063e8f commit fee0e2f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

andotp/andotp_test.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
)
88

99
const (
10-
jsonstr string = "[{\"secret\":\"SOMEAWESOMESECRET\",\"issuer\":\"SOMEAWESOMEISSUER\",\"label\":\"TESTLABEL\",\"digits\":6,\"type\":\"TOTP\",\"algorithm\":\"SHA1\",\"thumbnail\":\"Default\",\"last_used\":1000000000000,\"used_frequency\":0,\"period\":30,\"tags\":[]}]"
11-
password string = "testpass"
10+
jsonstr string = "[{\"secret\":\"SOMEAWESOMESECRET\",\"issuer\":\"SOMEAWESOMEISSUER\",\"label\":\"TESTLABEL\",\"digits\":6,\"type\":\"TOTP\",\"algorithm\":\"SHA1\",\"thumbnail\":\"Default\",\"last_used\":1000000000000,\"used_frequency\":0,\"period\":30,\"tags\":[]}]"
11+
jsonstrNoSecret string = "[{\"secret\":,\"issuer\":\"SOMEAWESOMEISSUER\",\"label\":\"TESTLABEL\",\"digits\":6,\"type\":\"TOTP\",\"algorithm\":\"SHA1\",\"thumbnail\":\"Default\",\"last_used\":1000000000000,\"used_frequency\":0,\"period\":30,\"tags\":[]}]"
12+
password string = "testpass"
1213
)
1314

1415
func TestEncryptDecrypt(t *testing.T) {
@@ -26,4 +27,22 @@ func TestEncryptDecrypt(t *testing.T) {
2627
if string(decryptedtext) != jsonstr {
2728
t.Error("Encryption/Decryption failed. Text mismatch")
2829
}
30+
31+
// With wrong password
32+
33+
encryptedtext = nil
34+
decryptedtext = nil
35+
err = nil
36+
37+
encryptedtext, err = andotp.Encrypt([]byte(jsonstr), password)
38+
if err != nil {
39+
t.Error(err)
40+
}
41+
42+
_, err = andotp.Decrypt(encryptedtext, "someotherpass")
43+
if err != nil {
44+
if err.Error() != "error: cipher: message authentication failed" {
45+
t.Error(err)
46+
}
47+
}
2948
}

0 commit comments

Comments
 (0)