Search in sources :

Example 1 with PrivateSubscribeRequest

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);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) PrivateSubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 2 with PrivateSubscribeRequest

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);
}
Also used : PrivateLogsSubscription(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.logs.PrivateLogsSubscription) PrivateSubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest) SyncingSubscription(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.syncing.SyncingSubscription) LogsSubscription(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.logs.LogsSubscription) NewBlockHeadersSubscription(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.blockheaders.NewBlockHeadersSubscription) PrivateLogsSubscription(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.logs.PrivateLogsSubscription) FilterParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter) Test(org.junit.Test)

Example 3 with PrivateSubscribeRequest

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();
}
Also used : PrivateTransactionEvent(org.hyperledger.besu.ethereum.privacy.PrivateTransactionEvent) PrivateLogsSubscription(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.logs.PrivateLogsSubscription) PrivateSubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest) FilterParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter) Test(org.junit.Test)

Example 4 with PrivateSubscribeRequest

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);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) User(io.vertx.ext.auth.User) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) PrivateSubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest) Test(org.junit.Test)

Example 5 with PrivateSubscribeRequest

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);
    }
}
Also used : PrivateSubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) InvalidSubscriptionRequestException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException) MultiTenancyPrivacyController(org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Aggregations

PrivateSubscribeRequest (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest)5 Test (org.junit.Test)4 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)2 FilterParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter)2 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)2 PrivateLogsSubscription (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.logs.PrivateLogsSubscription)2 User (io.vertx.ext.auth.User)1 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)1 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)1 NewBlockHeadersSubscription (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.blockheaders.NewBlockHeadersSubscription)1 LogsSubscription (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.logs.LogsSubscription)1 InvalidSubscriptionRequestException (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException)1 SyncingSubscription (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.syncing.SyncingSubscription)1 MultiTenancyPrivacyController (org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController)1 PrivateTransactionEvent (org.hyperledger.besu.ethereum.privacy.PrivateTransactionEvent)1