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

Commit

Permalink
Release 1.3.2 (#273)
Browse files Browse the repository at this point in the history
* Release 1.3.2

* Fix gradle file

* Adding test
  • Loading branch information
lucassaldanha authored Jul 31, 2019
1 parent 18c4c4a commit 68c0bd2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 61 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ apply plugin: 'maven-publish'
apply from: "gradle/check-licenses.gradle"
apply plugin: 'com.jfrog.bintray'

version = '1.3.1'
version = '1.3.2'

//////
// Default tasks and build aliases
Expand Down
48 changes: 26 additions & 22 deletions src/main/java/net/consensys/orion/cmd/Orion.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,35 +456,39 @@ public void run(PrintStream out, PrintStream err, Config config) {
}
}

nodeHTTPServer =
vertx.createHttpServer(options).requestHandler(nodeRouter::accept).exceptionHandler(log::error).listen(
completeFutureInHandler(nodeFuture));
CompletableFuture<Boolean> clientFuture = new CompletableFuture<>();
HttpServerOptions clientOptions =
new HttpServerOptions().setPort(config.clientPort()).setHost(config.clientNetworkInterface());
clientHTTPServer =
vertx.createHttpServer(clientOptions).requestHandler(clientRouter::accept).exceptionHandler(log::error).listen(
completeFutureInHandler(clientFuture));

CompletableFuture<Boolean> verticleFuture = new CompletableFuture<>();
// start network discovery of other peers
discovery = new NetworkDiscovery(networkNodes, config);
vertx.deployVerticle(discovery, result -> {
if (result.succeeded()) {
verticleFuture.complete(true);
} else {
verticleFuture.completeExceptionally(result.cause());
}
});

try {
CompletableFuture.allOf(nodeFuture, clientFuture, verticleFuture).get();
nodeHTTPServer =
vertx.createHttpServer(options).requestHandler(nodeRouter::accept).exceptionHandler(log::error).listen(
completeFutureInHandler(nodeFuture));
CompletableFuture<Boolean> clientFuture = new CompletableFuture<>();
HttpServerOptions clientOptions =
new HttpServerOptions().setPort(config.clientPort()).setHost(config.clientNetworkInterface());
clientHTTPServer = vertx
.createHttpServer(clientOptions)
.requestHandler(clientRouter::accept)
.exceptionHandler(log::error)
.listen(completeFutureInHandler(clientFuture));

// wait for node and client http server to start successfully
CompletableFuture.allOf(nodeFuture, clientFuture).get();
// if there is not a node url in the config, then grab the actual port and use it to set the node url.
if (!config.nodeUrl().isPresent()) {
networkNodes.setNodeUrl(
new URL("http", config.nodeNetworkInterface(), nodeHTTPServer.actualPort(), ""),
keyStore.nodeKeys());
}

CompletableFuture<Boolean> networkDiscoveryFuture = new CompletableFuture<>();
// start network discovery of other peers
discovery = new NetworkDiscovery(networkNodes, config);
vertx.deployVerticle(discovery, result -> {
if (result.succeeded()) {
networkDiscoveryFuture.complete(true);
} else {
networkDiscoveryFuture.completeExceptionally(result.cause());
}
});
CompletableFuture.allOf(networkDiscoveryFuture).get();
} catch (ExecutionException | MalformedURLException e) {
throw new OrionStartException("Orion failed to start: " + e.getCause().getMessage(), e.getCause());
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ public void handle(final RoutingContext routingContext) {
final byte[] request = routingContext.getBody().getBytes();
final PrivacyGroupRequest privacyGroupRequest = Serializer.deserialize(JSON, PrivacyGroupRequest.class, request);

if (privacyGroupRequest.name().isBlank() || privacyGroupRequest.description().isBlank()) {
routingContext.fail(
new OrionException(
OrionErrorCode.CREATE_GROUP_INVALID_PARAMS,
"neither the name nor the description may be null "));
return;
}

if (!Arrays.asList(privacyGroupRequest.addresses()).contains(privacyGroupRequest.from())) {
routingContext.fail(
new OrionException(OrionErrorCode.CREATE_GROUP_INCLUDE_SELF, "the list of addresses should include self "));
Expand All @@ -102,8 +94,10 @@ public void handle(final RoutingContext routingContext) {

final PrivacyGroupPayload privacyGroupPayload = new PrivacyGroupPayload(
privacyGroupRequest.addresses(),
privacyGroupRequest.name(),
privacyGroupRequest.description(),
privacyGroupRequest.name() == null || privacyGroupRequest.name().isBlank() ? "Default Name"
: privacyGroupRequest.name(),
privacyGroupRequest.description() == null || privacyGroupRequest.description().isBlank() ? "Default Description"
: privacyGroupRequest.description(),
PrivacyGroupPayload.State.ACTIVE,
PrivacyGroupPayload.Type.PANTHEON,
bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,6 @@ void expectedPrivacyGroupId() throws Exception {
assertEquals(privacyGroup.getPrivacyGroupId(), encodeBytes(privacyGroupPayload));
}


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

String[] toEncrypt = new String[] {encodeBytes(senderKey.bytesArray()), encodeBytes(recipientKey.bytesArray())};
Box.PublicKey[] addresses = Arrays.stream(toEncrypt).map(enclave::readKey).toArray(Box.PublicKey[]::new);

PrivacyGroupRequest privacyGroupRequestExpected =
buildPrivacyGroupRequest(toEncrypt, encodeBytes(senderKey.bytesArray()), null, null);
Request request = buildPrivateAPIRequest("/createPrivacyGroup", JSON, privacyGroupRequestExpected);

byte[] privacyGroupPayload = enclave.generatePrivacyGroupId(
addresses,
privacyGroupRequestExpected.getSeed().get(),
PrivacyGroupPayload.Type.PANTHEON);

// create fake peer
FakePeer fakePeer = new FakePeer(new MockResponse().setBody(encodeBytes(privacyGroupPayload)), recipientKey);
networkNodes.addNode(fakePeer.publicKey, fakePeer.getURL());

// execute request
Response resp = httpClient.newCall(request).execute();
assertEquals(500, resp.code());
}


@Test
void oddNumberOfRecipientsPrivacyGroupId() throws IOException {
Box.PublicKey senderKey = memoryKeyStore.generateKeyPair();
Expand Down Expand Up @@ -215,6 +187,37 @@ PrivacyGroupRequest buildPrivacyGroupRequest(String[] addresses, String from, St
return privacyGroupRequest;
}

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

String[] toEncrypt = new String[] {encodeBytes(senderKey.bytesArray()), encodeBytes(recipientKey.bytesArray())};
Box.PublicKey[] addresses = Arrays.stream(toEncrypt).map(enclave::readKey).toArray(Box.PublicKey[]::new);

PrivacyGroupRequest privacyGroupRequestExpected =
buildPrivacyGroupRequest(toEncrypt, encodeBytes(senderKey.bytesArray()), null, null);
Request request = buildPrivateAPIRequest("/createPrivacyGroup", JSON, privacyGroupRequestExpected);

byte[] privacyGroupPayload = enclave.generatePrivacyGroupId(
addresses,
privacyGroupRequestExpected.getSeed().get(),
PrivacyGroupPayload.Type.PANTHEON);

// create fake peer
FakePeer fakePeer = new FakePeer(new MockResponse().setBody(encodeBytes(privacyGroupPayload)), recipientKey);
networkNodes.addNode(fakePeer.publicKey, fakePeer.getURL());

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

assertEquals(200, resp.code());

PrivacyGroup privacyGroup = Serializer.deserialize(JSON, PrivacyGroup.class, resp.body().bytes());

assertEquals(privacyGroup.getPrivacyGroupId(), encodeBytes(privacyGroupPayload));
}

class FakePeer {
final MockWebServer server;
final Box.PublicKey publicKey;
Expand Down

0 comments on commit 68c0bd2

Please sign in to comment.