Search in sources :

Example 26 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class PrivacyGroupResourceTest method testFindPrivacyGroup.

@Test
public void testFindPrivacyGroup() {
    PrivacyGroupSearchRequest req = new PrivacyGroupSearchRequest();
    final List<PublicKey> members = List.of(PublicKey.from("member1".getBytes()), PublicKey.from("member2".getBytes()));
    req.setAddresses(members.stream().map(PublicKey::encodeToBase64).toArray(String[]::new));
    when(privacyGroupManager.findPrivacyGroup(members)).thenReturn(List.of(mockResult));
    final Response response = privacyGroupResource.findPrivacyGroup(req);
    // jersey.target("findPrivacyGroup").request().post(Entity.entity(req,
    // MediaType.APPLICATION_JSON));
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
    PrivacyGroupResponse[] privacyGroupResponses = (PrivacyGroupResponse[]) response.getEntity();
    PrivacyGroupResponse result = privacyGroupResponses[0];
    assertThat(result.getName()).isEqualTo(mockResult.getName());
    assertThat(result.getDescription()).isEqualTo(mockResult.getDescription());
    assertThat(result.getMembers()).isEqualTo(req.getAddresses());
    assertThat(result.getPrivacyGroupId()).isEqualTo(mockResult.getId().getBase64());
    assertThat(result.getType()).isEqualTo(mockResult.getType().name());
    verify(privacyGroupManager).findPrivacyGroup(members);
}
Also used : Response(jakarta.ws.rs.core.Response) PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 27 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class PrivacyGroupResourceTest method testRetrievePrivacyGroup.

@Test
public void testRetrievePrivacyGroup() {
    PrivacyGroupRetrieveRequest req = new PrivacyGroupRetrieveRequest();
    req.setPrivacyGroupId("aWQ=");
    when(privacyGroupManager.retrievePrivacyGroup(mockResult.getId())).thenReturn(mockResult);
    final Response response = privacyGroupResource.retrievePrivacyGroup(req);
    // jersey.target("retrievePrivacyGroup").request().post(Entity.entity(req,
    // MediaType.APPLICATION_JSON));
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
    final PrivacyGroupResponse res = (PrivacyGroupResponse) response.getEntity();
    assertThat(res.getName()).isEqualTo(mockResult.getName());
    assertThat(res.getDescription()).isEqualTo(mockResult.getDescription());
    assertThat(res.getMembers()).isEqualTo(mockResult.getMembers().stream().map(PublicKey::encodeToBase64).toArray());
    assertThat(res.getPrivacyGroupId()).isEqualTo(mockResult.getId().getBase64());
    assertThat(res.getType()).isEqualTo(mockResult.getType().name());
    verify(privacyGroupManager).retrievePrivacyGroup(PrivacyGroup.Id.fromBytes("id".getBytes()));
}
Also used : Response(jakarta.ws.rs.core.Response) PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 28 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class TransactionResource3Test method receive.

@Test
public void receive() {
    PublicKey sender = PublicKey.from("sender".getBytes());
    ReceiveResponse response = mock(ReceiveResponse.class);
    when(response.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    when(response.getUnencryptedTransactionData()).thenReturn("Success".getBytes());
    when(response.sender()).thenReturn(sender);
    when(transactionManager.receive(any(com.quorum.tessera.transaction.ReceiveRequest.class))).thenReturn(response);
    String transactionHash = Base64.getEncoder().encodeToString("transactionHash".getBytes());
    Response result = transactionResource.receive(transactionHash, null, Boolean.FALSE.toString());
    assertThat(result.getStatus()).isEqualTo(200);
    com.quorum.tessera.api.ReceiveResponse resultResponse = com.quorum.tessera.api.ReceiveResponse.class.cast(result.getEntity());
    assertThat(resultResponse.getExecHash()).isNull();
    assertThat(resultResponse.getPrivacyFlag()).isEqualTo(PrivacyMode.STANDARD_PRIVATE.getPrivacyFlag());
    assertThat(resultResponse.getExecHash()).isNull();
    assertThat(resultResponse.getAffectedContractTransactions()).isNullOrEmpty();
    assertThat(resultResponse.getPayload()).isEqualTo("Success".getBytes());
    assertThat(resultResponse.getSenderKey()).isEqualTo(sender.encodeToBase64());
    verify(transactionManager).receive(any(com.quorum.tessera.transaction.ReceiveRequest.class));
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) PublicKey(com.quorum.tessera.encryption.PublicKey) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Test(org.junit.Test)

Example 29 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class TransactionResource3Test method sendForRecipient.

@Test
public void sendForRecipient() {
    final Base64.Encoder base64Encoder = Base64.getEncoder();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(base64Encoder.encode("PAYLOAD".getBytes()));
    sendRequest.setTo(Base64.getEncoder().encodeToString("Mr Benn".getBytes()));
    final PublicKey sender = mock(PublicKey.class);
    when(transactionManager.defaultPublicKey()).thenReturn(sender);
    final com.quorum.tessera.transaction.SendResponse sendResponse = mock(com.quorum.tessera.transaction.SendResponse.class);
    final MessageHash messageHash = mock(MessageHash.class);
    final byte[] txnData = "TxnData".getBytes();
    when(messageHash.getHashBytes()).thenReturn(txnData);
    when(sendResponse.getTransactionHash()).thenReturn(messageHash);
    when(transactionManager.send(any(com.quorum.tessera.transaction.SendRequest.class))).thenReturn(sendResponse);
    final Response result = transactionResource.send(sendRequest);
    assertThat(result.getStatus()).isEqualTo(201);
    assertThat(result.getLocation().getPath()).isEqualTo("transaction/" + base64Encoder.encodeToString(txnData));
    verify(transactionManager).send(any(com.quorum.tessera.transaction.SendRequest.class));
    verify(transactionManager).defaultPublicKey();
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) SendRequest(com.quorum.tessera.api.SendRequest) PublicKey(com.quorum.tessera.encryption.PublicKey) MessageHash(com.quorum.tessera.data.MessageHash) Test(org.junit.Test)

Example 30 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class TransactionResource3Test method sendSignedTransactionEmptyRecipients.

@Test
public void sendSignedTransactionEmptyRecipients() {
    final PublicKey sender = PublicKey.from("sender".getBytes());
    com.quorum.tessera.transaction.SendResponse sendResponse = mock(com.quorum.tessera.transaction.SendResponse.class);
    byte[] transactionHashData = "I Love Sparrows".getBytes();
    final String base64EncodedTransactionHAshData = Base64.getEncoder().encodeToString(transactionHashData);
    MessageHash transactionHash = mock(MessageHash.class);
    when(transactionHash.getHashBytes()).thenReturn(transactionHashData);
    when(sendResponse.getTransactionHash()).thenReturn(transactionHash);
    when(sendResponse.getSender()).thenReturn(sender);
    when(transactionManager.sendSignedTransaction(any(com.quorum.tessera.transaction.SendSignedRequest.class))).thenReturn(sendResponse);
    SendSignedRequest sendSignedRequest = new SendSignedRequest();
    sendSignedRequest.setHash("SOMEDATA".getBytes());
    Response result = transactionResource.sendSignedTransaction(sendSignedRequest);
    // jersey.target("sendsignedtx")
    // .request()
    // .header("Content-Type", "application/vnd.tessera-2.1+json")
    // .header("Accept", "application/vnd.tessera-2.1+json")
    // .post(Entity.entity(sendSignedRequest,
    // "application/vnd.tessera-2.1+json"));
    assertThat(result.getStatus()).isEqualTo(201);
    SendResponse resultResponse = (SendResponse) result.getEntity();
    assertThat(resultResponse.getKey()).isEqualTo(base64EncodedTransactionHAshData);
    assertThat(resultResponse.getSenderKey()).isEqualTo(sender.encodeToBase64());
    assertThat(result.getLocation()).hasPath("transaction/".concat(base64EncodedTransactionHAshData));
    ArgumentCaptor<com.quorum.tessera.transaction.SendSignedRequest> argumentCaptor = ArgumentCaptor.forClass(com.quorum.tessera.transaction.SendSignedRequest.class);
    verify(transactionManager).sendSignedTransaction(argumentCaptor.capture());
    com.quorum.tessera.transaction.SendSignedRequest obj = argumentCaptor.getValue();
    assertThat(obj).isNotNull();
    assertThat(obj.getSignedData()).isEqualTo("SOMEDATA".getBytes());
    assertThat(obj.getRecipients()).hasSize(0);
    assertThat(obj.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
    assertThat(obj.getAffectedContractTransactions()).isEmpty();
    assertThat(obj.getExecHash()).isEmpty();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) SendResponse(com.quorum.tessera.api.SendResponse) MessageHash(com.quorum.tessera.data.MessageHash) SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) SendSignedRequest(com.quorum.tessera.api.SendSignedRequest) Test(org.junit.Test)

Aggregations

PublicKey (com.quorum.tessera.encryption.PublicKey)281 Test (org.junit.Test)213 Response (jakarta.ws.rs.core.Response)59 MessageHash (com.quorum.tessera.data.MessageHash)57 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)48 Collectors (java.util.stream.Collectors)32 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)28 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)25 java.util (java.util)23 SendResponse (com.quorum.tessera.api.SendResponse)21 Nonce (com.quorum.tessera.encryption.Nonce)20 Recipient (com.quorum.tessera.partyinfo.node.Recipient)20 Operation (io.swagger.v3.oas.annotations.Operation)20 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)20 Stream (java.util.stream.Stream)19 ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)18 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)17 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)17 URI (java.net.URI)17 SendRequest (com.quorum.tessera.api.SendRequest)15