Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Retrieve privacy group endpoint #307

Merged
merged 18 commits into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
after PR review - rename getPrivacyGroup to retrievePrivacyGroup
  • Loading branch information
jframe committed Dec 5, 2019
commit afb11e4940a0255b41aea29bd4057eb790cdb7f4
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import net.consensys.orion.http.handler.privacy.DeletePrivacyGroupRequest;
import net.consensys.orion.http.handler.privacy.FindPrivacyGroupRequest;
import net.consensys.orion.http.handler.privacy.GetPrivacyGroupRequest;
import net.consensys.orion.http.handler.privacy.PrivacyGroup;
import net.consensys.orion.http.handler.privacy.PrivacyGroupRequest;
import net.consensys.orion.http.handler.privacy.RetrievePrivacyGroupRequest;
import net.consensys.orion.http.handler.receive.ReceiveRequest;
import net.consensys.orion.http.handler.receive.ReceiveResponse;
import net.consensys.orion.utils.Serializer;
Expand Down Expand Up @@ -173,10 +173,10 @@ public Optional<PrivacyGroup[]> findPrivacyGroup(final String[] addresses) {
return Optional.ofNullable(keyFuture.join());
}

public Optional<PrivacyGroup> getPrivacyGroup(final String privacyGroupId) {
final GetPrivacyGroupRequest getGroupRequest = new GetPrivacyGroupRequest(privacyGroupId);
public Optional<PrivacyGroup> retrievePrivacyGroup(final String privacyGroupId) {
final RetrievePrivacyGroupRequest getGroupRequest = new RetrievePrivacyGroupRequest(privacyGroupId);
final CompletableFuture<PrivacyGroup> keyFuture = new CompletableFuture<>();
httpClient.post(clientPort, "localhost", "/getPrivacyGroup").handler(resp -> {
httpClient.post(clientPort, "localhost", "/retrievePrivacyGroup").handler(resp -> {
if (resp.statusCode() == 200) {
resp.bodyHandler(body -> keyFuture.complete(deserialize(body, PrivacyGroup.class)));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public static String deletePrivacyGroupTransaction(
return sender.deletePrivacyGroup(privacyGroupId, from).orElseThrow(AssertionFailedError::new);
}

public static PrivacyGroup getPrivacyGroupTransaction(final EthClientStub sender, final String privacyGroupId) {
return sender.getPrivacyGroup(privacyGroupId).orElseThrow(AssertionFailedError::new);
public static PrivacyGroup retrievePrivacyGroupTransaction(final EthClientStub sender, final String privacyGroupId) {
return sender.retrievePrivacyGroup(privacyGroupId).orElseThrow(AssertionFailedError::new);
}

/** Asserts the received payload matches that sent. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import static net.consensys.orion.acceptance.NodeUtils.createPrivacyGroupTransaction;
import static net.consensys.orion.acceptance.NodeUtils.deletePrivacyGroupTransaction;
import static net.consensys.orion.acceptance.NodeUtils.findPrivacyGroupTransaction;
import static net.consensys.orion.acceptance.NodeUtils.getPrivacyGroupTransaction;
import static net.consensys.orion.acceptance.NodeUtils.joinPathsAsTomlListEntry;
import static net.consensys.orion.acceptance.NodeUtils.retrievePrivacyGroupTransaction;
import static net.consensys.orion.http.server.HttpContentType.CBOR;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertArrayEquals;
Expand Down Expand Up @@ -200,7 +200,7 @@ void createAndFind() {
}

@Test
void createAndGet() {
void createAndRetrieve() {
final EthClientStub firstNode = NodeUtils.client(firstOrionLauncher.clientPort(), firstHttpClient);
final EthClientStub secondNode = NodeUtils.client(secondOrionLauncher.clientPort(), secondHttpClient);

Expand All @@ -215,7 +215,7 @@ void createAndGet() {
assertEquals(privacyGroup.getDescription(), description);

// get the created privacy group in first node
final PrivacyGroup firstNodePrivacyGroup = getPrivacyGroupTransaction(firstNode, privacyGroupId);
final PrivacyGroup firstNodePrivacyGroup = retrievePrivacyGroupTransaction(firstNode, privacyGroupId);

assertEquals(firstNodePrivacyGroup.getPrivacyGroupId(), privacyGroupId);
assertEquals(firstNodePrivacyGroup.getDescription(), description);
Expand All @@ -224,8 +224,8 @@ void createAndGet() {

// get the created privacy group in second node
await().atMost(20, TimeUnit.SECONDS).until(
() -> getPrivacyGroupTransaction(secondNode, privacyGroupId).getPrivacyGroupId().equals(privacyGroupId));
final PrivacyGroup secondNodePrivacyGroup = getPrivacyGroupTransaction(secondNode, privacyGroupId);
() -> retrievePrivacyGroupTransaction(secondNode, privacyGroupId).getPrivacyGroupId().equals(privacyGroupId));
final PrivacyGroup secondNodePrivacyGroup = retrievePrivacyGroupTransaction(secondNode, privacyGroupId);
assertEquals(secondNodePrivacyGroup.getDescription(), description);
jframe marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(secondNodePrivacyGroup.getName(), name);
assertArrayEquals(secondNodePrivacyGroup.getMembers(), addresses);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/consensys/orion/cmd/Orion.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import net.consensys.orion.http.handler.privacy.CreatePrivacyGroupHandler;
import net.consensys.orion.http.handler.privacy.DeletePrivacyGroupHandler;
import net.consensys.orion.http.handler.privacy.FindPrivacyGroupHandler;
import net.consensys.orion.http.handler.privacy.GetPrivacyGroupHandler;
import net.consensys.orion.http.handler.privacy.RetrievePrivacyGroupHandler;
import net.consensys.orion.http.handler.push.PushHandler;
import net.consensys.orion.http.handler.push.PushPrivacyGroupHandler;
import net.consensys.orion.http.handler.receive.ReceiveHandler;
Expand Down Expand Up @@ -213,8 +213,8 @@ public static void configureRoutes(
clientRouter.post("/findPrivacyGroup").consumes(JSON.httpHeaderValue).produces(JSON.httpHeaderValue).handler(
new FindPrivacyGroupHandler(queryPrivacyGroupStorage, privacyGroupStorage));

clientRouter.post("/getPrivacyGroup").consumes(JSON.httpHeaderValue).produces(JSON.httpHeaderValue).handler(
new GetPrivacyGroupHandler(privacyGroupStorage));
clientRouter.post("/retrievePrivacyGroup").consumes(JSON.httpHeaderValue).produces(JSON.httpHeaderValue).handler(
new RetrievePrivacyGroupHandler(privacyGroupStorage));

clientRouter.get("/knownnodes").produces(JSON.httpHeaderValue).handler(new KnownNodesHandler(networkNodes));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@
import org.apache.logging.log4j.Logger;

/**
* Get a privacy group given the privacyGroupId.
* Retrieves a privacy group given the privacyGroupId.
*/
public class GetPrivacyGroupHandler implements Handler<RoutingContext> {
public class RetrievePrivacyGroupHandler implements Handler<RoutingContext> {

private static final Logger log = LogManager.getLogger();

private final Storage<PrivacyGroupPayload> privacyGroupStorage;

public GetPrivacyGroupHandler(final Storage<PrivacyGroupPayload> privacyGroupStorage) {
public RetrievePrivacyGroupHandler(final Storage<PrivacyGroupPayload> privacyGroupStorage) {
this.privacyGroupStorage = privacyGroupStorage;
}

@Override
@SuppressWarnings("rawtypes")
public void handle(final RoutingContext routingContext) {
final byte[] request = routingContext.getBody().getBytes();
final GetPrivacyGroupRequest getPrivacyGroupRequest =
Serializer.deserialize(JSON, GetPrivacyGroupRequest.class, request);
final RetrievePrivacyGroupRequest retrievePrivacyGroupRequest =
Serializer.deserialize(JSON, RetrievePrivacyGroupRequest.class, request);

final String privacyGroupId = getPrivacyGroupRequest.privacyGroupId();
final String privacyGroupId = retrievePrivacyGroupRequest.privacyGroupId();

if (privacyGroupId == null) {
routingContext.fail(400);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class GetPrivacyGroupRequest implements Serializable {
public class RetrievePrivacyGroupRequest implements Serializable {

private final String privacyGroupId;

@JsonCreator
public GetPrivacyGroupRequest(@JsonProperty("privacyGroupId") final String privacyGroupId) {
public RetrievePrivacyGroupRequest(@JsonProperty("privacyGroupId") final String privacyGroupId) {
this.privacyGroupId = privacyGroupId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
@ExtendWith(TempDirectoryExtension.class)
public abstract class HandlerTest {

static final String RETRIEVE_PRIVACY_GROUP = "/retrievePrivacyGroup";
static final String DELETE_PRIVACY_GROUP = "/deletePrivacyGroup";
static final String PUSH_PRIVACY_GROUP = "/pushPrivacyGroup";
static final String CREATE_PRIVACY_GROUP = "/createPrivacyGroup";

// http client
protected final OkHttpClient httpClient = new OkHttpClient();
protected String nodeBaseUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import net.consensys.orion.enclave.sodium.SodiumEnclave;
import net.consensys.orion.helpers.FakePeer;
import net.consensys.orion.http.handler.privacy.DeletePrivacyGroupRequest;
import net.consensys.orion.http.handler.privacy.GetPrivacyGroupRequest;
import net.consensys.orion.http.handler.privacy.PrivacyGroup;
import net.consensys.orion.http.handler.privacy.PrivacyGroupRequest;
import net.consensys.orion.http.handler.privacy.RetrievePrivacyGroupRequest;
import net.consensys.orion.utils.Serializer;

import java.io.IOException;
Expand All @@ -40,7 +40,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class GetPrivacyGroupHandlerTest extends HandlerTest {
public class RetrievePrivacyGroupHandlerTest extends HandlerTest {

private static final String PRIVACY_GROUP_NAME = "test";
private static final String PRIVACY_GROUP_DESCRIPTION = "desc";
Expand Down Expand Up @@ -70,7 +70,7 @@ void setup() throws IOException, InterruptedException {
encodeBytes(senderKey.bytesArray()),
PRIVACY_GROUP_NAME,
PRIVACY_GROUP_DESCRIPTION);
final Request request = buildPrivateAPIRequest("/createPrivacyGroup", JSON, privacyGroupRequestExpected);
final Request request = buildPrivateAPIRequest(CREATE_PRIVACY_GROUP, JSON, privacyGroupRequestExpected);

final byte[] privacyGroupId = enclave.generatePrivacyGroupId(
new Box.PublicKey[] {senderKey, recipientKey},
Expand All @@ -87,7 +87,7 @@ void setup() throws IOException, InterruptedException {
assertThat(resp.code()).isEqualTo(200);

final RecordedRequest recordedRequest = peer.server.takeRequest();
assertThat(recordedRequest.getPath()).isEqualTo("/pushPrivacyGroup");
assertThat(recordedRequest.getPath()).isEqualTo(PUSH_PRIVACY_GROUP);
jframe marked this conversation as resolved.
Show resolved Hide resolved
assertThat(recordedRequest.getMethod()).isEqualTo("POST");

final PrivacyGroup privacyGroup = Serializer.deserialize(JSON, PrivacyGroup.class, resp.body().bytes());
Expand All @@ -96,8 +96,8 @@ void setup() throws IOException, InterruptedException {

@Test
void knownPrivacyGroupIsRetrieved() throws IOException {
final GetPrivacyGroupRequest getPrivacyGroupRequest = buildGetPrivacyGroupRequest(privacyGroupId);
final Request request = buildPrivateAPIRequest("/getPrivacyGroup", JSON, getPrivacyGroupRequest);
final RetrievePrivacyGroupRequest retrievePrivacyGroupRequest = buildGetPrivacyGroupRequest(privacyGroupId);
final Request request = buildPrivateAPIRequest(RETRIEVE_PRIVACY_GROUP, JSON, retrievePrivacyGroupRequest);
peer.addResponse(new MockResponse().setBody(privacyGroupId));

final Response resp = httpClient.newCall(request).execute();
Expand All @@ -112,8 +112,9 @@ void knownPrivacyGroupIsRetrieved() throws IOException {

@Test
void unknownPrivacyGroupIdReturnsNotFoundError() throws IOException {
final GetPrivacyGroupRequest getPrivacyGroupRequest = buildGetPrivacyGroupRequest("unknownPrivacyGroupId");
final Request request = buildPrivateAPIRequest("/getPrivacyGroup", JSON, getPrivacyGroupRequest);
final RetrievePrivacyGroupRequest retrievePrivacyGroupRequest =
buildGetPrivacyGroupRequest("unknownPrivacyGroupId");
final Request request = buildPrivateAPIRequest(RETRIEVE_PRIVACY_GROUP, JSON, retrievePrivacyGroupRequest);

final Response resp = httpClient.newCall(request).execute();

Expand All @@ -126,20 +127,20 @@ void deletedPrivacyGroupReturnsNotFoundError() throws IOException {

final DeletePrivacyGroupRequest deletePrivacyGroupRequest =
buildDeletePrivacyGroupRequest(privacyGroupId, encodeBytes(senderKey.bytesArray()));
final Request deleteRequest = buildPrivateAPIRequest("/deletePrivacyGroup", JSON, deletePrivacyGroupRequest);
final Request deleteRequest = buildPrivateAPIRequest(DELETE_PRIVACY_GROUP, JSON, deletePrivacyGroupRequest);
final Response deleteResponse = httpClient.newCall(deleteRequest).execute();
assertThat(deleteResponse.code()).isEqualTo(200);

final GetPrivacyGroupRequest getPrivacyGroupRequest = buildGetPrivacyGroupRequest(privacyGroupId);
final Request getGroupRequest = buildPrivateAPIRequest("/getPrivacyGroup", JSON, getPrivacyGroupRequest);
final RetrievePrivacyGroupRequest retrievePrivacyGroupRequest = buildGetPrivacyGroupRequest(privacyGroupId);
final Request getGroupRequest = buildPrivateAPIRequest(RETRIEVE_PRIVACY_GROUP, JSON, retrievePrivacyGroupRequest);
final Response getGroupResponse = httpClient.newCall(getGroupRequest).execute();
assertThat(getGroupResponse.code()).isEqualTo(404);
}

@Test
void requestWithoutPrivacyGroupIdFails() throws IOException {
final GetPrivacyGroupRequest getPrivacyGroupRequest = buildGetPrivacyGroupRequest(null);
final Request request = buildPrivateAPIRequest("/getPrivacyGroup", JSON, getPrivacyGroupRequest);
final RetrievePrivacyGroupRequest retrievePrivacyGroupRequest = buildGetPrivacyGroupRequest(null);
final Request request = buildPrivateAPIRequest(RETRIEVE_PRIVACY_GROUP, JSON, retrievePrivacyGroupRequest);

final Response resp = httpClient.newCall(request).execute();

Expand All @@ -161,8 +162,8 @@ private PrivacyGroupRequest buildPrivacyGroupRequest(
return privacyGroupRequest;
}

private GetPrivacyGroupRequest buildGetPrivacyGroupRequest(final String key) {
return new GetPrivacyGroupRequest(key);
private RetrievePrivacyGroupRequest buildGetPrivacyGroupRequest(final String key) {
return new RetrievePrivacyGroupRequest(key);
}

private DeletePrivacyGroupRequest buildDeletePrivacyGroupRequest(final String key, final String from) {
Expand Down