@@ -46,6 +46,7 @@ public void shouldCreateCorrectly() throws Exception {
46
46
47
47
assertThat (transaction .getTransactionToken (), is (equalTo ("TRANSACTION_TOKEN" )));
48
48
assertThat (transaction .getRecoveryCode (), is (equalTo ("RECOVERY_CODE" )));
49
+ assertThat (transaction .getTotpSecret (), is (equalTo ("OTP_SECRET" )));
49
50
assertThat (transaction .totpURI ("username" , "company" ), is (equalTo ("otpauth://totp/company:username?secret=OTP_SECRET&issuer=company" )));
50
51
}
51
52
@@ -55,6 +56,7 @@ public void shouldCreateCorrectlyWithSpaces() throws Exception {
55
56
56
57
assertThat (transaction .getTransactionToken (), is (equalTo ("TRANSACTION_TOKEN" )));
57
58
assertThat (transaction .getRecoveryCode (), is (equalTo ("RECOVERY_CODE" )));
59
+ assertThat (transaction .getTotpSecret (), is (equalTo ("OTP_SECRET" )));
58
60
assertThat (transaction .totpURI ("user name" , "company name" ), is (equalTo ("otpauth://totp/company%20name:user%20name?secret=OTP_SECRET&issuer=company%20name" )));
59
61
}
60
62
@@ -64,6 +66,7 @@ public void shouldCreateCorrectlyWithWeirdCharacters() throws Exception {
64
66
65
67
assertThat (transaction .getTransactionToken (), is (equalTo ("TRANSACTION_TOKEN" )));
66
68
assertThat (transaction .getRecoveryCode (), is (equalTo ("RECOVERY_CODE" )));
69
+ assertThat (transaction .getTotpSecret (), is (equalTo ("OTP_SECRET" )));
67
70
assertThat (transaction .totpURI ("user%name" , "compañy?!" ), is (equalTo ("otpauth://totp/compa%C3%B1y%3F!:user%25name?secret=OTP_SECRET&issuer=compa%C3%B1y?!" )));
68
71
}
69
72
@@ -91,6 +94,32 @@ public void shouldSerializeCorrectly() throws Exception {
91
94
assertThat (restoredTransaction .getRecoveryCode (), is (equalTo ("RECOVERY_CODE" )));
92
95
}
93
96
97
+ @ Test
98
+ public void shouldThrowWhenRequestingOtpSecretAfterSerialization () throws Exception {
99
+ exception .expect (IllegalStateException .class );
100
+ exception .expectMessage ("There is no OTP Secret for this transaction" );
101
+
102
+ Transaction transaction = new Transaction ("TRANSACTION_TOKEN" , "RECOVERY_CODE" , "OTP_SECRET" );
103
+
104
+ // save
105
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
106
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream (outputStream );
107
+ objectOutputStream .writeObject (transaction );
108
+ objectOutputStream .close ();
109
+ outputStream .close ();
110
+
111
+ byte [] binaryData = outputStream .toByteArray ();
112
+
113
+ // restore
114
+ ByteArrayInputStream inputStream = new ByteArrayInputStream (binaryData );
115
+ ObjectInputStream objectInputStream = new ObjectInputStream (inputStream );
116
+ Transaction restoredTransaction = (Transaction ) objectInputStream .readObject ();
117
+ objectInputStream .close ();
118
+ inputStream .close ();
119
+
120
+ restoredTransaction .getTotpSecret ();
121
+ }
122
+
94
123
@ Test
95
124
public void shouldThrowWhenRequestingTotpUriAfterSerialization () throws Exception {
96
125
exception .expect (IllegalStateException .class );
0 commit comments