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

Commit

Permalink
Rename privacyGroupId API to createPrivacyGroupId
Browse files Browse the repository at this point in the history
  • Loading branch information
Puneetha17 committed Jul 8, 2019
1 parent 5c55213 commit beffd05
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
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 @@ -34,8 +34,8 @@
import net.consensys.orion.enclave.sodium.FileKeyStore;
import net.consensys.orion.enclave.sodium.SodiumEnclave;
import net.consensys.orion.http.handler.partyinfo.PartyInfoHandler;
import net.consensys.orion.http.handler.privacy.CreatePrivacyGroupHandler;
import net.consensys.orion.http.handler.privacy.DeletePrivacyGroupHandler;
import net.consensys.orion.http.handler.privacy.PrivacyGroupHandler;
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 @@ -183,8 +183,8 @@ public static void configureRoutes(
.consumes(APPLICATION_OCTET_STREAM.httpHeaderValue)
.handler(new ReceiveHandler(enclave, storage, APPLICATION_OCTET_STREAM));

clientRouter.post("/privacyGroupId").consumes(JSON.httpHeaderValue).produces(JSON.httpHeaderValue).handler(
new PrivacyGroupHandler(privacyGroupStorage, networkNodes, enclave, vertx, config));
clientRouter.post("/createPrivacyGroupId").consumes(JSON.httpHeaderValue).produces(JSON.httpHeaderValue).handler(
new CreatePrivacyGroupHandler(privacyGroupStorage, networkNodes, enclave, vertx, config));

clientRouter.post("/deletePrivacyGroupId").consumes(JSON.httpHeaderValue).produces(JSON.httpHeaderValue).handler(
new DeletePrivacyGroupHandler(privacyGroupStorage, networkNodes, enclave, vertx, config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public enum OrionErrorCode {
ENCLAVE_UNABLE_STORE_PRIVACY_GROUP("PrivacyGroupNotStored"),
ENCLAVE_UNABLE_DELETE_PRIVACY_GROUP("PrivacyGroupNotDeleted"),
ENCLAVE_UNABLE_PUSH_DELETE_PRIVACY_GROUP("PrivacyGroupNotPushed"),
ENCLAVE_PRIVACY_GROUP_MISSING("PrivacyGroupNotFound");
ENCLAVE_PRIVACY_GROUP_MISSING("PrivacyGroupNotFound"),
CREATE_GROUP_INCLUDE_SELF("CreatePrivacyGroupShouldIncludeSelf");

private final String code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import org.apache.logging.log4j.Logger;

/**
* Get the privacyGroup id given the list of addresses.
* Create a privacyGroup given the list of addresses.
*/
public class PrivacyGroupHandler implements Handler<RoutingContext> {
public class CreatePrivacyGroupHandler implements Handler<RoutingContext> {


private static final Logger log = LogManager.getLogger();
Expand All @@ -54,7 +54,7 @@ public class PrivacyGroupHandler implements Handler<RoutingContext> {
private final Enclave enclave;
private final HttpClient httpClient;

public PrivacyGroupHandler(
public CreatePrivacyGroupHandler(
Storage<PrivacyGroupPayload> privacyGroupStorage,
ConcurrentNetworkNodes networkNodes,
Enclave enclave,
Expand All @@ -72,6 +72,12 @@ public void handle(RoutingContext routingContext) {
byte[] request = routingContext.getBody().getBytes();
PrivacyGroupRequest privacyGroup = Serializer.deserialize(JSON, PrivacyGroupRequest.class, request);

if (!Arrays.asList(privacyGroup.addresses()).contains(privacyGroup.from())) {
routingContext.fail(
new OrionException(OrionErrorCode.CREATE_GROUP_INCLUDE_SELF, "the list of addresses should include self "));
return;
}

byte[] bytes = new byte[20];
if (privacyGroup.getSeed().isPresent()) {
bytes = privacyGroup.getSeed().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import okhttp3.mockwebserver.MockWebServer;
import org.junit.jupiter.api.Test;

public class PrivacyGroupHandlerTest extends HandlerTest {
public class CreatePrivacyGroupHandlerTest extends HandlerTest {
private MemoryKeyStore memoryKeyStore;

@Override
Expand All @@ -58,7 +58,7 @@ void expectedPrivacyGroupId() throws Exception {

PrivacyGroupRequest privacyGroupRequestExpected =
buildPrivacyGroupRequest(toEncrypt, encodeBytes(senderKey.bytesArray()), "test", "desc");
Request request = buildPrivateAPIRequest("/privacyGroupId", JSON, privacyGroupRequestExpected);
Request request = buildPrivateAPIRequest("/createPrivacyGroupId", JSON, privacyGroupRequestExpected);

byte[] privacyGroupPayload = enclave.generatePrivacyGroupId(
addresses,
Expand Down Expand Up @@ -96,7 +96,7 @@ void oddNumberOfRecipientsPrivacyGroupId() throws IOException {
Box.PublicKey[] addresses = Arrays.stream(toEncrypt).map(enclave::readKey).toArray(Box.PublicKey[]::new);
PrivacyGroupRequest privacyGroupRequestExpected =
buildPrivacyGroupRequest(toEncrypt, encodeBytes(senderKey.bytesArray()), "test", "desc");
Request request = buildPrivateAPIRequest("/privacyGroupId", JSON, privacyGroupRequestExpected);
Request request = buildPrivateAPIRequest("/createPrivacyGroupId", JSON, privacyGroupRequestExpected);

byte[] privacyGroupPayload = enclave.generatePrivacyGroupId(
addresses,
Expand Down Expand Up @@ -138,7 +138,7 @@ void RepeatedRecipientsPrivacyGroupId() throws IOException {

PrivacyGroupRequest privacyGroupRequestExpected =
buildPrivacyGroupRequest(toEncrypt, encodeBytes(senderKey.bytesArray()), "test", "desc");
Request request = buildPrivateAPIRequest("/privacyGroupId", JSON, privacyGroupRequestExpected);
Request request = buildPrivateAPIRequest("/createPrivacyGroupId", JSON, privacyGroupRequestExpected);

byte[] privacyGroupPayload = enclave.generatePrivacyGroupId(
addresses,
Expand All @@ -159,6 +159,23 @@ void RepeatedRecipientsPrivacyGroupId() throws IOException {
assertEquals(privacyGroup.getPrivacyGroupId(), encodeBytes(privacyGroupPayload));
}

@Test
void ErrorIfCreateDoesntContainSelf() throws IOException {
Box.PublicKey senderKey = memoryKeyStore.generateKeyPair();
Box.PublicKey recipientKey = memoryKeyStore.generateKeyPair();

String[] toEncrypt = new String[] {encodeBytes(recipientKey.bytesArray())};

PrivacyGroupRequest privacyGroupRequestExpected =
buildPrivacyGroupRequest(toEncrypt, encodeBytes(senderKey.bytesArray()), "test", "desc");
Request request = buildPrivateAPIRequest("/createPrivacyGroupId", JSON, privacyGroupRequestExpected);

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

assertEquals(500, resp.code());
}

PrivacyGroupRequest buildPrivacyGroupRequest(String[] addresses, String from, String name, String description) {
PrivacyGroupRequest privacyGroupRequest = new PrivacyGroupRequest(addresses, from, name, description);
// create a random seed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void setup() throws IOException, InterruptedException {
String[] toEncrypt = new String[] {encodeBytes(senderKey.bytesArray()), encodeBytes(recipientKey.bytesArray())};
PrivacyGroupRequest privacyGroupRequestExpected =
buildPrivacyGroupRequest(toEncrypt, encodeBytes(senderKey.bytesArray()), "test", "desc");
Request request = buildPrivateAPIRequest("/privacyGroupId", JSON, privacyGroupRequestExpected);
Request request = buildPrivateAPIRequest("/createPrivacyGroupId", JSON, privacyGroupRequestExpected);

byte[] privacyGroupPayload = enclave.generatePrivacyGroupId(
new Box.PublicKey[] {senderKey, recipientKey},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ void sendToPrivacyGroupId() throws Exception {
// build the store privacy group request
PrivacyGroupRequest privacyGroupRequestExpected =
buildPrivacyGroupRequest(toEncrypt, encodeBytes(senderKey.bytesArray()), "test", "test");
Request request = buildPrivateAPIRequest("/privacyGroupId", JSON, privacyGroupRequestExpected);
Request request = buildPrivateAPIRequest("/createPrivacyGroupId", JSON, privacyGroupRequestExpected);

byte[] privacyGroupPayload = enclave.generatePrivacyGroupId(
addresses,
Expand All @@ -541,7 +541,7 @@ void sendToPrivacyGroupId() throws Exception {
FakePeer fakePeer = new FakePeer(new MockResponse().setBody(encodeBytes(privacyGroupPayload)), recipientKey);
networkNodes.addNode(fakePeer.publicKey, fakePeer.getURL());

// execute /privacyGroupId request
// execute /createPrivacyGroupId request
Response resp = httpClient.newCall(request).execute();

assertEquals(resp.code(), 200);
Expand Down

0 comments on commit beffd05

Please sign in to comment.