Search in sources :

Example 6 with PartyInfoParser

use of com.quorum.tessera.p2p.partyinfo.PartyInfoParser 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);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerConfig(com.quorum.tessera.config.ServerConfig) Response(jakarta.ws.rs.core.Response) After(org.junit.After) JsonObject(jakarta.json.JsonObject) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Before(org.junit.Before) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(jakarta.ws.rs.client.Entity) KeyDataUtil(com.quorum.tessera.config.util.KeyDataUtil) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Stream(java.util.stream.Stream) MediaType(jakarta.ws.rs.core.MediaType) Recipient(com.quorum.tessera.partyinfo.model.Recipient) Config(com.quorum.tessera.config.Config) NodeAlias(suite.NodeAlias) Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) PublicKey(com.quorum.tessera.encryption.PublicKey) Recipient(com.quorum.tessera.partyinfo.model.Recipient) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Client(jakarta.ws.rs.client.Client) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Test(org.junit.Test)

Example 7 with PartyInfoParser

use of com.quorum.tessera.p2p.partyinfo.PartyInfoParser 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);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerConfig(com.quorum.tessera.config.ServerConfig) Response(jakarta.ws.rs.core.Response) After(org.junit.After) JsonObject(jakarta.json.JsonObject) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Before(org.junit.Before) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(jakarta.ws.rs.client.Entity) KeyDataUtil(com.quorum.tessera.config.util.KeyDataUtil) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Stream(java.util.stream.Stream) MediaType(jakarta.ws.rs.core.MediaType) Recipient(com.quorum.tessera.partyinfo.model.Recipient) Config(com.quorum.tessera.config.Config) NodeAlias(suite.NodeAlias) PublicKey(com.quorum.tessera.encryption.PublicKey) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Recipient(com.quorum.tessera.partyinfo.model.Recipient) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Aggregations

PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)7 Stream (java.util.stream.Stream)6 Before (org.junit.Before)6 Config (com.quorum.tessera.config.Config)5 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)5 ServerConfig (com.quorum.tessera.config.ServerConfig)5 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)5 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)5 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)5 KeyDataUtil (com.quorum.tessera.config.util.KeyDataUtil)5 PublicKey (com.quorum.tessera.encryption.PublicKey)5 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)5 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)5 Recipient (com.quorum.tessera.partyinfo.model.Recipient)5 JsonObject (jakarta.json.JsonObject)5 Client (jakarta.ws.rs.client.Client)5 Entity (jakarta.ws.rs.client.Entity)5 MediaType (jakarta.ws.rs.core.MediaType)5 Response (jakarta.ws.rs.core.Response)5 StreamingOutput (jakarta.ws.rs.core.StreamingOutput)5