diff --git a/src/test/java/com/pusher/client/crypto/nacl/SecretBoxOpenerTest.java b/src/test/java/com/pusher/client/crypto/nacl/SecretBoxOpenerTest.java index e234ed6a..5b02c3b7 100644 --- a/src/test/java/com/pusher/client/crypto/nacl/SecretBoxOpenerTest.java +++ b/src/test/java/com/pusher/client/crypto/nacl/SecretBoxOpenerTest.java @@ -1,6 +1,7 @@ package com.pusher.client.crypto.nacl; import static com.google.common.truth.Truth.assertThat; +import static java.util.Arrays.copyOf; import com.pusher.client.util.internal.Base64; import org.junit.Before; @@ -9,6 +10,10 @@ public class SecretBoxOpenerTest { byte[] key = Base64.decode("6071zp2l/GPnDPDXNWTJDHyIZ8pZMvQrYsa4xuTKK2c="); + + byte[] nonce = Base64.decode("xsbOS0KylAV2ziTDHrP/7rSFqpCOah3p"); + byte[] cipher = Base64.decode("tvttPE2PRQp0bWDmaPyiEU8YJGztmTvTN77OoPwftTNTdDgJXwxHQPE="); + SecretBoxOpener subject; @Before @@ -18,11 +23,16 @@ public void setUp() { @Test public void open() { - byte[] cipher = Base64.decode("tvttPE2PRQp0bWDmaPyiEU8YJGztmTvTN77OoPwftTNTdDgJXwxHQPE="); - byte[] nonce = Base64.decode("xsbOS0KylAV2ziTDHrP/7rSFqpCOah3p"); - byte[] clearText = subject.open(cipher, nonce); assertThat(new String(clearText)).isEqualTo("{\"message\":\"hello world\"}"); } + + @Test(expected = AuthenticityException.class) + public void openFailsForTamperedCipher() { + byte[] tamperedCipher = copyOf(cipher, cipher.length); + tamperedCipher[0] ^= tamperedCipher[0]; + + subject.open(tamperedCipher, nonce); + } } \ No newline at end of file