use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class PrivacyPrecompiledContractTest method testPayloadFoundInEnclave.
@Test
public void testPayloadFoundInEnclave() {
final Enclave enclave = mock(Enclave.class);
when(enclave.retrievePrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID)).thenReturn(new PrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", Arrays.asList(VALID_BASE64_ENCLAVE_KEY.toBase64String())));
final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
final List<Log> logs = new ArrayList<>();
contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.successful(logs, 0, 0, Bytes.fromHexString(DEFAULT_OUTPUT), null)));
final PrivateTransaction privateTransaction = privateTransactionBesu();
final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
final String privateFrom = privateTransaction.getPrivateFrom().toBase64String();
final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
when(enclave.receive(any(String.class))).thenReturn(response);
final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class PrivacyPrecompiledContractTest method testPrivateFromNotMemberOfGroup.
@Test
public void testPrivateFromNotMemberOfGroup() {
final Enclave enclave = mock(Enclave.class);
when(enclave.retrievePrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID)).thenReturn(new PrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", Arrays.asList(VALID_BASE64_ENCLAVE_KEY.toBase64String())));
final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.successful(new ArrayList<>(), 0, 0, Bytes.fromHexString(DEFAULT_OUTPUT), null)));
final PrivateTransaction privateTransaction = privateTransactionBesu();
final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
final String privateFrom = privateTransaction.getPrivateFrom().toBase64String();
final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
when(enclave.receive(any(String.class))).thenReturn(response);
final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class FlexiblePrivacyControllerTest method findsPrivacyGroupById.
@Test
public void findsPrivacyGroupById() {
final PrivacyGroup privacyGroup = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.FLEXIBLE, "", "", PRIVACY_GROUP_ADDRESSES);
mockingForFindPrivacyGroupById();
final Optional<PrivacyGroup> privacyGroupFound = privacyController.findPrivacyGroupByGroupId(PRIVACY_GROUP_ID, ADDRESS1);
assertThat(privacyGroupFound).isPresent();
assertThat(privacyGroupFound.get()).usingRecursiveComparison().isEqualTo(privacyGroup);
}
use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class MultiTenancyPrivacyControllerTest method createPrivacyGroupDelegatesToPrivacyController.
@Test
public void createPrivacyGroupDelegatesToPrivacyController() {
final List<String> addresses = List.of(ENCLAVE_PUBLIC_KEY1, ENCLAVE_PUBLIC_KEY2);
final PrivacyGroup delegatePrivacyGroup = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "name", "description", addresses);
when(privacyController.createPrivacyGroup(addresses, "name", "description", ENCLAVE_PUBLIC_KEY1)).thenReturn(delegatePrivacyGroup);
final PrivacyGroup privacyGroup = multiTenancyPrivacyController.createPrivacyGroup(addresses, "name", "description", ENCLAVE_PUBLIC_KEY1);
assertThat(privacyGroup).usingRecursiveComparison().isEqualTo(delegatePrivacyGroup);
verify(privacyController).createPrivacyGroup(addresses, "name", "description", ENCLAVE_PUBLIC_KEY1);
}
use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.
the class MultiTenancyPrivacyControllerTest method sendBesuTransactionFailsWithValidationExceptionWhenPrivacyGroupDoesNotContainPrivacyUserId.
@Test
public void sendBesuTransactionFailsWithValidationExceptionWhenPrivacyGroupDoesNotContainPrivacyUserId() {
final PrivateTransaction transaction = PrivateTransaction.builder().privateFrom(Bytes.fromBase64String(ENCLAVE_PUBLIC_KEY1)).privacyGroupId(Bytes.fromBase64String(PRIVACY_GROUP_ID)).build();
final PrivacyGroup privacyGroupWithoutPrivacyUserId = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", List.of(ENCLAVE_PUBLIC_KEY2));
doThrow(new MultiTenancyValidationException("Privacy group must contain the enclave public key")).when(privacyController).verifyPrivacyGroupContainsPrivacyUserId(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY1);
assertThatThrownBy(() -> multiTenancyPrivacyController.createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithoutPrivacyUserId))).isInstanceOf(MultiTenancyValidationException.class).hasMessage("Privacy group must contain the enclave public key");
verify(privacyController, never()).createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithoutPrivacyUserId));
}
Aggregations