Search in sources :

Example 26 with Party

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);
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) StringReader(java.io.StringReader) JsonObject(jakarta.json.JsonObject) Test(org.junit.Test)

Example 27 with Party

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);
}
Also used : Response(jakarta.ws.rs.core.Response) SendResponse(com.quorum.tessera.api.SendResponse) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) SendResponse(com.quorum.tessera.api.SendResponse) Test(org.junit.Test)

Example 28 with Party

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);
}
Also used : Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) Peer(com.quorum.tessera.config.Peer) URI(java.net.URI) Test(org.junit.Test)

Example 29 with Party

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);
}
Also used : PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) Test(org.junit.Test)

Example 30 with Party

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());
}
Also used : PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Test(org.junit.Test)

Aggregations

Party (com.quorum.tessera.test.Party)63 Response (jakarta.ws.rs.core.Response)60 Test (org.junit.Test)46 SendResponse (com.quorum.tessera.api.SendResponse)45 SendRequest (com.quorum.tessera.api.SendRequest)43 ReceiveResponse (com.quorum.tessera.api.ReceiveResponse)32 URI (java.net.URI)16 RestUtils (com.quorum.tessera.test.rest.RestUtils)11 JsonObject (jakarta.json.JsonObject)7 PartyHelper (com.quorum.tessera.test.PartyHelper)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 PayloadEncryptResponse (com.quorum.tessera.api.PayloadEncryptResponse)4 Entity (jakarta.ws.rs.client.Entity)4 StringReader (java.io.StringReader)4 ExecutionContext (suite.ExecutionContext)4 ServerConfig (com.quorum.tessera.config.ServerConfig)3 ConfigDescriptor (config.ConfigDescriptor)3 Json (jakarta.json.Json)3 Client (jakarta.ws.rs.client.Client)3 Before (org.junit.Before)3