use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class CustomPayloadEncryptionIT method payloadDecryptionFailsWithoutProperKeyAvailable.
@Test
public void payloadDecryptionFailsWithoutProperKeyAvailable() {
final Party sender = partyHelper.findByAlias(NodeAlias.A);
final Party recipient = partyHelper.findByAlias(NodeAlias.B);
final SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(Base64.getEncoder().encode("Test Payload".getBytes()));
sendRequest.setTo(recipient.getPublicKey());
final Response encryptResult = sender.getRestClientWebTarget().path("/encodedpayload/create").request().post(Entity.entity(sendRequest, mediaType));
assertThat(encryptResult.getStatus()).isEqualTo(200);
final PayloadEncryptResponse payloadEncryptResponse = encryptResult.readEntity(PayloadEncryptResponse.class);
// purposefully remove the wrong box so it can't be decrypted
// since the key that corresponds to the remaining box isn't on that node
final String firstRecipientInList = Base64.getEncoder().encodeToString(payloadEncryptResponse.getRecipientKeys().get(0));
if (Objects.equals(firstRecipientInList, sender.getPublicKey())) {
payloadEncryptResponse.getRecipientBoxes().remove(1);
} else {
payloadEncryptResponse.getRecipientBoxes().remove(0);
}
payloadEncryptResponse.setRecipientKeys(Collections.emptyList());
final Response decryptResultForRecipient = recipient.getRestClientWebTarget().path("/encodedpayload/decrypt").request().post(Entity.entity(payloadEncryptResponse, mediaType));
assertThat(decryptResultForRecipient.getStatus()).isEqualTo(500);
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class CustomPayloadEncryptionIT method createPayload.
@Test
public void createPayload() {
final Party sender = partyHelper.findByAlias(NodeAlias.A);
final SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(Base64.getEncoder().encode("Test Payload".getBytes()));
sendRequest.setTo(partyHelper.getParties().map(Party::getPublicKey).toArray(String[]::new));
Response result = sender.getRestClientWebTarget().path("/encodedpayload/create").request().post(Entity.entity(sendRequest, mediaType));
assertThat(result.getStatus()).isEqualTo(200);
final PayloadEncryptResponse payloadEncryptResponse = result.readEntity(PayloadEncryptResponse.class);
assertThat(Base64.getEncoder().encodeToString(payloadEncryptResponse.getSenderKey())).isEqualTo(sender.getPublicKey());
assertThat(payloadEncryptResponse.getCipherText()).isNotEmpty();
assertThat(payloadEncryptResponse.getCipherTextNonce()).isNotEmpty();
assertThat(payloadEncryptResponse.getRecipientBoxes()).hasSize(4);
assertThat(payloadEncryptResponse.getRecipientNonce()).isNotEmpty();
assertThat(payloadEncryptResponse.getRecipientKeys()).hasSize(4).containsExactlyInAnyOrder(partyHelper.getParties().map(Party::getPublicKey).map(Base64.getDecoder()::decode).toArray(byte[][]::new));
assertThat(payloadEncryptResponse.getPrivacyMode()).isEqualTo(0);
assertThat(payloadEncryptResponse.getAffectedContractTransactions()).isEmpty();
assertThat(payloadEncryptResponse.getExecHash()).isEmpty();
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class ResendIndividualIT method resendTransactionForIncorrectKey.
@Test
public void resendTransactionForIncorrectKey() {
final ResendRequest request = new ResendRequest();
request.setType(RESEND_INDIVIDUAL_VALUE);
request.setKey(this.hash);
Party anyOtherParty = partyHelper.getParties().filter(p -> !p.equals(sender)).filter(p -> !p.equals(recipient)).findAny().get();
request.setPublicKey(anyOtherParty.getPublicKey());
final Response response = vanillaHttpOnlyClient.target(recipient.getP2PUri()).path(RESEND_PATH).request().post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE));
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(500);
assertThat(response.readEntity(String.class)).contains("Recipient " + anyOtherParty.getPublicKey() + " is not a recipient of transaction");
}
Aggregations