File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
src/test/java/com/pusher/client/crypto/nacl Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 11package com .pusher .client .crypto .nacl ;
22
33import static com .google .common .truth .Truth .assertThat ;
4+ import static java .util .Arrays .copyOf ;
45
56import com .pusher .client .util .internal .Base64 ;
67import org .junit .Before ;
910public class SecretBoxOpenerTest {
1011
1112 byte [] key = Base64 .decode ("6071zp2l/GPnDPDXNWTJDHyIZ8pZMvQrYsa4xuTKK2c=" );
13+
14+ byte [] nonce = Base64 .decode ("xsbOS0KylAV2ziTDHrP/7rSFqpCOah3p" );
15+ byte [] cipher = Base64 .decode ("tvttPE2PRQp0bWDmaPyiEU8YJGztmTvTN77OoPwftTNTdDgJXwxHQPE=" );
16+
1217 SecretBoxOpener subject ;
1318
1419 @ Before
@@ -18,11 +23,16 @@ public void setUp() {
1823
1924 @ Test
2025 public void open () {
21- byte [] cipher = Base64 .decode ("tvttPE2PRQp0bWDmaPyiEU8YJGztmTvTN77OoPwftTNTdDgJXwxHQPE=" );
22- byte [] nonce = Base64 .decode ("xsbOS0KylAV2ziTDHrP/7rSFqpCOah3p" );
23-
2426 byte [] clearText = subject .open (cipher , nonce );
2527
2628 assertThat (new String (clearText )).isEqualTo ("{\" message\" :\" hello world\" }" );
2729 }
30+
31+ @ Test (expected = AuthenticityException .class )
32+ public void openFailsForTamperedCipher () {
33+ byte [] tamperedCipher = copyOf (cipher , cipher .length );
34+ tamperedCipher [0 ] ^= tamperedCipher [0 ];
35+
36+ subject .open (tamperedCipher , nonce );
37+ }
2838}
You can’t perform that action at this time.
0 commit comments