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);
}
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()));
}
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));
}
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();
}
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();
}
Aggregations