use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.
the class PeerToPeerIT method happyCase.
/*
* Send a valid party info from B to A
*/
@Test
public void happyCase() {
Party partyB = partyHelper.findByAlias(NodeAlias.B);
ServerConfig serverContext = Optional.of(partyB.getConfig()).map(Config::getP2PServerConfig).get();
Client client = clientFactory.buildFrom(serverContext);
PublicKey partyBKey = Optional.of(partyB).map(Party::getPublicKey).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
String partyBServerAddress = partyB.getConfig().getP2PServerConfig().getServerAddress();
Recipient recipient = Recipient.of(partyBKey, partyBServerAddress);
PartyInfo partyInfo = new PartyInfo(partyBServerAddress, Collections.singleton(recipient), Collections.emptySet());
PartyInfoParser partyInfoParser = PartyInfoParser.create();
byte[] data = partyInfoParser.to(partyInfo);
StreamingOutput output = out -> out.write(data);
Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().post(Entity.entity(output, MediaType.APPLICATION_OCTET_STREAM));
assertThat(response.getStatus()).isEqualTo(200);
}
use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.
the class PeerToPeerIT method benevolentNodeBecomesPossessedAndTriesToSendInvalidUrlAndKeyCombo.
@Test
public void benevolentNodeBecomesPossessedAndTriesToSendInvalidUrlAndKeyCombo() throws Exception {
Party partyB = partyHelper.findByAlias(NodeAlias.B);
ServerConfig serverConfig = partyB.getConfig().getP2PServerConfig();
PublicKey publicKey = Optional.of(partyB).map(Party::getPublicKey).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
Recipient itself = Recipient.of(publicKey, serverConfig.getServerUri().toString());
String validKeyFromOtherNode = partyHelper.findByAlias(NodeAlias.C).getPublicKey();
PublicKey validButIncorrectKey = Optional.of(validKeyFromOtherNode).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
String workingUrlFromSomeOtherNode = partyHelper.findByAlias(NodeAlias.D).getConfig().getP2PServerConfig().getServerAddress();
Recipient badRecipient = Recipient.of(validButIncorrectKey, workingUrlFromSomeOtherNode);
Set<Recipient> recipients = Stream.of(itself, badRecipient).collect(Collectors.toSet());
assertThat(recipients).containsExactlyInAnyOrder(itself, badRecipient);
PartyInfo partyInfo = new PartyInfo(serverConfig.getServerUri().toString(), recipients, Collections.emptySet());
Client client = new ClientFactory().buildFrom(serverConfig);
PartyInfoParser partyInfoParser = PartyInfoParser.create();
byte[] data = partyInfoParser.to(partyInfo);
StreamingOutput output = out -> out.write(data);
Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().post(Entity.entity(output, MediaType.APPLICATION_OCTET_STREAM));
assertThat(response.getStatus()).isEqualTo(200);
}
Aggregations