Search in sources :

Example 11 with PrivacyMode

use of com.quorum.tessera.enclave.PrivacyMode in project tessera by ConsenSys.

the class RestPayloadPublisherTest method publishEnhancedTransactionsToNodesThatDoNotSupport.

@Test
public void publishEnhancedTransactionsToNodesThatDoNotSupport() {
    Map<PrivacyMode, Set<String>> privacyModeAndVersions = new HashMap<>();
    privacyModeAndVersions.put(PrivacyMode.PARTY_PROTECTION, Set.of("v1"));
    privacyModeAndVersions.put(PrivacyMode.PRIVATE_STATE_VALIDATION, Set.of("v1"));
    for (Map.Entry<PrivacyMode, Set<String>> pair : privacyModeAndVersions.entrySet()) {
        String targetUrl = "http://someplace.com";
        EncodedPayload encodedPayload = mock(EncodedPayload.class);
        when(encodedPayload.getPrivacyMode()).thenReturn(pair.getKey());
        byte[] payloadData = "Some Data".getBytes();
        when(payloadEncoder.encode(encodedPayload)).thenReturn(payloadData);
        PublicKey recipientKey = mock(PublicKey.class);
        NodeInfo nodeInfo = mock(NodeInfo.class);
        when(nodeInfo.supportedApiVersions()).thenReturn(pair.getValue());
        Recipient recipient = mock(Recipient.class);
        when(recipient.getKey()).thenReturn(recipientKey);
        when(recipient.getUrl()).thenReturn(targetUrl);
        when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
        when(discovery.getRemoteNodeInfo(recipientKey)).thenReturn(nodeInfo);
        EnhancedPrivacyNotSupportedException exception = catchThrowableOfType(() -> payloadPublisher.publishPayload(encodedPayload, recipientKey), EnhancedPrivacyNotSupportedException.class);
        assertThat(exception).hasMessageContaining("Transactions with enhanced privacy is not currently supported");
        verify(discovery).getRemoteNodeInfo(eq(recipientKey));
    }
    payloadEncoderFactoryFunction.verify(times(2), () -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) PublicKey(com.quorum.tessera.encryption.PublicKey) PrivacyMode(com.quorum.tessera.enclave.PrivacyMode) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Recipient(com.quorum.tessera.partyinfo.node.Recipient) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) HashMap(java.util.HashMap) Map(java.util.Map) EnhancedPrivacyNotSupportedException(com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException) Test(org.junit.Test)

Aggregations

PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)11 PublicKey (com.quorum.tessera.encryption.PublicKey)10 MessageHash (com.quorum.tessera.data.MessageHash)7 URI (java.net.URI)7 SendSignedRequest (com.quorum.tessera.api.SendSignedRequest)5 Operation (io.swagger.v3.oas.annotations.Operation)5 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)5 Response (jakarta.ws.rs.core.Response)5 SendResponse (com.quorum.tessera.api.SendResponse)4 PrivacyValid (com.quorum.tessera.api.constraint.PrivacyValid)4 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)4 PrivacyGroupManager (com.quorum.tessera.privacygroup.PrivacyGroupManager)4 TransactionManager (com.quorum.tessera.transaction.TransactionManager)4 Content (io.swagger.v3.oas.annotations.media.Content)4 Schema (io.swagger.v3.oas.annotations.media.Schema)4 Tag (io.swagger.v3.oas.annotations.tags.Tag)4 Valid (jakarta.validation.Valid)4 NotNull (jakarta.validation.constraints.NotNull)4 UriBuilder (jakarta.ws.rs.core.UriBuilder)4 URLEncoder (java.net.URLEncoder)4