use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class SendReceivePrivacyGroupIT method sendTransactionToPrivacyGroup.
@Test
public void sendTransactionToPrivacyGroup() throws UnsupportedEncodingException {
final Party a = partyHelper.findByAlias(NodeAlias.A);
final Party b = partyHelper.findByAlias(NodeAlias.B);
final String output = privacyGroupTestUtil.create("A", "B");
final JsonObject jsonObj = Json.createReader(new StringReader(output)).readObject();
final String groupId = jsonObj.getString("privacyGroupId");
byte[] transactionData = utils.createTransactionData();
final SendRequest sendRequest = new SendRequest();
sendRequest.setPrivacyGroupId(groupId);
sendRequest.setPayload(transactionData);
final Response response = a.getRestClient().target(a.getQ2TUri()).path("/send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
final SendResponse result = response.readEntity(SendResponse.class);
final String hash = result.getKey();
// Hash length should be 64 bytes
assertThat(Base64.getDecoder().decode(hash)).hasSize(64);
final String encodedHash = URLEncoder.encode(hash, UTF_8.toString());
assertThat(hash).isNotNull().isNotBlank();
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(201);
final Response receiveResponse = a.getRestClient().target(a.getQ2TUri()).path("/transaction").path(encodedHash).request().accept(MIME_TYPE_JSON_2_1).buildGet().invoke();
// validate result
assertThat(receiveResponse).isNotNull();
assertThat(receiveResponse.getStatus()).isEqualTo(200);
final ReceiveResponse receiveResult = receiveResponse.readEntity(ReceiveResponse.class);
assertThat(receiveResult.getPayload()).isEqualTo(transactionData);
assertThat(receiveResult.getManagedParties()).containsExactly(a.getPublicKey());
assertThat(receiveResult.getSenderKey()).isEqualTo(a.getPublicKey());
// assertThat(receiveResult.getPrivacyGroupId()).isEqualTo(groupId);
final Response receiveResponseOnB = b.getRestClient().target(b.getQ2TUri()).path("/transaction").path(encodedHash).request().accept(MIME_TYPE_JSON_2_1).buildGet().invoke();
// validate result
assertThat(receiveResponseOnB).isNotNull();
assertThat(receiveResponseOnB.getStatus()).isEqualTo(200);
final ReceiveResponse receiveResultOnB = receiveResponseOnB.readEntity(ReceiveResponse.class);
assertThat(receiveResultOnB.getPayload()).isEqualTo(transactionData);
assertThat(receiveResultOnB.getManagedParties()).containsExactly(b.getPublicKey());
assertThat(receiveResultOnB.getSenderKey()).isEqualTo(a.getPublicKey());
// assertThat(receiveResultOnB.getPrivacyGroupId()).isEqualTo(groupId);
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class ReceiveRawIT method fetchExistingTransactionNotUsingKeyOnRecipient.
@Test
public void fetchExistingTransactionNotUsingKeyOnRecipient() {
Party sender = partyHelper.findByAlias("A");
byte[] transactionPayload = new RestUtils().createTransactionData();
SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(transactionPayload);
sendRequest.setFrom(sender.getPublicKey());
sendRequest.setTo(partyHelper.findByAlias("B").getPublicKey());
final Response r = sender.getRestClient().target(sender.getQ2TUri()).path("/send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
final SendResponse sendResponse = r.readEntity(SendResponse.class);
final Party pty = partyHelper.findByAlias(NodeAlias.B);
final Response response = pty.getRestClient().target(pty.getQ2TUri()).path(RECEIVE_PATH).request().header(C11N_KEY, sendResponse.getKey()).buildGet().invoke();
// validate result
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
final byte[] result = response.readEntity(byte[].class);
assertThat(result).isEqualTo(transactionPayload);
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class AdminConfigIT method addPeer.
@Test
public void addPeer() {
Party party = partyHelper.getParties().findAny().get();
String url = "http://" + UUID.randomUUID().toString().replaceAll("-", "");
Peer peer = new Peer(url);
Response response = client.target(party.getAdminUri()).path("config").path("peers").request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).put(Entity.entity(peer, MediaType.APPLICATION_JSON));
assertThat(response.getStatus()).isEqualTo(201);
URI location = response.getLocation();
Response queryResponse = client.target(location).request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).get();
assertThat(queryResponse.getStatus()).isEqualTo(200);
assertThat(queryResponse.readEntity(Peer.class)).isEqualTo(peer);
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class CustomPayloadEncryptionIT method payloadDecryptionFailsOnBadMessage.
@Test
public void payloadDecryptionFailsOnBadMessage() {
final Party sender = partyHelper.findByAlias(NodeAlias.A);
final SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(Base64.getEncoder().encode("Test Payload".getBytes()));
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);
// edit the cipher text to something rubbish, so it can't be decrypted
payloadEncryptResponse.setCipherText("Unexpected data".getBytes());
// attempt to decrypt it
final Response decryptResultForSender = sender.getRestClientWebTarget().path("/encodedpayload/decrypt").request().post(Entity.entity(payloadEncryptResponse, mediaType));
assertThat(decryptResultForSender.getStatus()).isEqualTo(500);
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class CustomPayloadEncryptionIT method createAndDecryptPayload.
@Test
public void createAndDecryptPayload() {
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);
// decrypt it again with the sender
final Response decryptResultForSender = sender.getRestClientWebTarget().path("/encodedpayload/decrypt").request().post(Entity.entity(payloadEncryptResponse, mediaType));
final ReceiveResponse decryptedPayload = decryptResultForSender.readEntity(ReceiveResponse.class);
assertThat(Base64.getDecoder().decode(decryptedPayload.getPayload())).isEqualTo("Test Payload".getBytes());
// decrypt it using the recipient
final String firstRecipientInList = Base64.getEncoder().encodeToString(payloadEncryptResponse.getRecipientKeys().get(0));
if (Objects.equals(firstRecipientInList, sender.getPublicKey())) {
payloadEncryptResponse.getRecipientBoxes().remove(0);
} else {
payloadEncryptResponse.getRecipientBoxes().remove(1);
}
payloadEncryptResponse.setRecipientKeys(Collections.emptyList());
final Response decryptResultForRecipient = recipient.getRestClientWebTarget().path("/encodedpayload/decrypt").request().post(Entity.entity(payloadEncryptResponse, mediaType));
final ReceiveResponse decryptedPayloadForRecipient = decryptResultForRecipient.readEntity(ReceiveResponse.class);
assertThat(Base64.getDecoder().decode(decryptedPayloadForRecipient.getPayload())).isEqualTo("Test Payload".getBytes());
}
Aggregations