use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest in project besu by hyperledger.
the class PrivSubscribeTest method responseContainsSubscriptionId.
@Test
public void responseContainsSubscriptionId() {
final WebSocketRpcRequest webSocketRequest = createWebSocketRpcRequest();
final JsonRpcRequestContext jsonRpcrequestContext = new JsonRpcRequestContext(webSocketRequest);
final PrivateSubscribeRequest subscribeRequest = new PrivateSubscribeRequest(SubscriptionType.LOGS, null, null, webSocketRequest.getConnectionId(), PRIVACY_GROUP_ID, "public_key");
when(mapperMock.mapPrivateSubscribeRequest(eq(jsonRpcrequestContext), any())).thenReturn(subscribeRequest);
when(subscriptionManagerMock.subscribe(eq(subscribeRequest))).thenReturn(1L);
final JsonRpcSuccessResponse expectedResponse = new JsonRpcSuccessResponse(jsonRpcrequestContext.getRequest().getId(), Quantity.create((1L)));
assertThat(privSubscribe.response(jsonRpcrequestContext)).isEqualTo(expectedResponse);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest in project besu by hyperledger.
the class SubscriptionBuilderTest method shouldBuildPrivateLogsSubscriptionWhenSubscribeRequestTypeIsPrivateLogs.
@Test
public void shouldBuildPrivateLogsSubscriptionWhenSubscribeRequestTypeIsPrivateLogs() {
final String privacyGroupId = "ZDmkMK7CyxA1F1rktItzKFTfRwApg7aWzsTtm2IOZ5Y=";
final String enclavePublicKey = "C1bVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=";
final FilterParameter filterParameter = filterParameter();
final PrivateSubscribeRequest subscribeRequest = new PrivateSubscribeRequest(SubscriptionType.LOGS, filterParameter, null, CONNECTION_ID, privacyGroupId, enclavePublicKey);
final PrivateLogsSubscription expectedSubscription = new PrivateLogsSubscription(1L, CONNECTION_ID, filterParameter, privacyGroupId, enclavePublicKey);
final Subscription builtSubscription = subscriptionBuilder.build(1L, CONNECTION_ID, subscribeRequest);
assertThat(builtSubscription).usingRecursiveComparison().isEqualTo(expectedSubscription);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest in project besu by hyperledger.
the class SubscriptionManagerTest method shouldUnsubscribeIfUserRemovedFromPrivacyGroup.
@Test
public void shouldUnsubscribeIfUserRemovedFromPrivacyGroup() {
final String enclavePublicKey = "C1bVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=";
final FilterParameter filterParameter = new FilterParameter(BlockParameter.EARLIEST, BlockParameter.LATEST, null, null, null, null, null, null, null);
final String privacyGroupId = "ZDmkMK7CyxA1F1rktItzKFTfRwApg7aWzsTtm2IOZ5Y=";
final PrivateSubscribeRequest privateSubscribeRequest = new PrivateSubscribeRequest(SubscriptionType.LOGS, filterParameter, null, CONNECTION_ID, privacyGroupId, enclavePublicKey);
final Long subscriptionId = subscriptionManager.subscribe(privateSubscribeRequest);
assertThat(subscriptionManager.subscriptionsOfType(SubscriptionType.LOGS, PrivateLogsSubscription.class).size()).isEqualTo(1);
subscriptionManager.onPrivateTransactionProcessed(new PrivateTransactionEvent(privacyGroupId, enclavePublicKey));
subscriptionManager.onBlockAdded();
assertThat(subscriptionManager.subscriptionsOfType(SubscriptionType.LOGS, PrivateLogsSubscription.class).size()).isEqualTo(0);
assertThat(subscriptionManager.getSubscriptionById(subscriptionId)).isNull();
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest in project besu by hyperledger.
the class PrivSubscribeTest method multiTenancyCheckSuccess.
@Test
public void multiTenancyCheckSuccess() {
final User user = mock(User.class);
final WebSocketRpcRequest webSocketRequest = createWebSocketRpcRequest();
final JsonRpcRequestContext jsonRpcrequestContext = new JsonRpcRequestContext(webSocketRequest, user);
final PrivateSubscribeRequest subscribeRequest = new PrivateSubscribeRequest(SubscriptionType.LOGS, null, null, webSocketRequest.getConnectionId(), PRIVACY_GROUP_ID, ENCLAVE_KEY);
when(mapperMock.mapPrivateSubscribeRequest(any(), any())).thenReturn(subscribeRequest);
when(privacyIdProvider.getPrivacyUserId(any())).thenReturn(ENCLAVE_KEY);
// This should pass if a MultiTenancyMultiTenancyValidationException isn't thrown
final JsonRpcResponse response = privSubscribe.response(jsonRpcrequestContext);
assertThat(response).isInstanceOf(JsonRpcSuccessResponse.class);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest in project besu by hyperledger.
the class PrivSubscribe method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
try {
final String privacyUserId = privacyIdProvider.getPrivacyUserId(requestContext.getUser());
final PrivateSubscribeRequest subscribeRequest = getMapper().mapPrivateSubscribeRequest(requestContext, privacyUserId);
if (privacyController instanceof MultiTenancyPrivacyController) {
checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(requestContext, subscribeRequest.getPrivacyGroupId());
}
final Long subscriptionId = subscriptionManager().subscribe(subscribeRequest);
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), Quantity.create(subscriptionId));
} catch (final InvalidSubscriptionRequestException isEx) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST);
}
}
Aggregations