Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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);
}
}