Search in sources :

Example 31 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class SendWithRemoteEnclaveReconnectIT method beforeTest.

@Before
public void beforeTest() throws IOException {
    EncryptorConfig encryptorConfig = new EncryptorConfig() {

        {
            setType(EncryptorType.NACL);
        }
    };
    ExecutionContext.Builder.create().with(CommunicationType.REST).with(DBType.H2).with(SocketType.HTTP).with(EnclaveType.REMOTE).with(encryptorConfig.getType()).with(ClientMode.TESSERA).buildAndStoreContext();
    final PortUtil portGenerator = new PortUtil(50100);
    final String serverUriTemplate = "http://localhost:%d";
    KeyEncryptorFactory.newFactory().create(encryptorConfig);
    final Config nodeConfig = new Config();
    nodeConfig.setEncryptor(encryptorConfig);
    JdbcConfig jdbcConfig = new JdbcConfig();
    jdbcConfig.setUrl("jdbc:h2:mem:junit");
    jdbcConfig.setUsername("sa");
    jdbcConfig.setPassword("");
    jdbcConfig.setAutoCreateTables(true);
    nodeConfig.setJdbcConfig(jdbcConfig);
    ServerConfig p2pServerConfig = new ServerConfig();
    p2pServerConfig.setApp(AppType.P2P);
    p2pServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
    p2pServerConfig.setCommunicationType(CommunicationType.REST);
    final ServerConfig q2tServerConfig = new ServerConfig();
    q2tServerConfig.setApp(AppType.Q2T);
    q2tServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
    q2tServerConfig.setCommunicationType(CommunicationType.REST);
    final Config enclaveConfig = new Config();
    enclaveConfig.setEncryptor(nodeConfig.getEncryptor());
    final ServerConfig enclaveServerConfig = new ServerConfig();
    enclaveServerConfig.setApp(AppType.ENCLAVE);
    enclaveServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
    enclaveServerConfig.setCommunicationType(CommunicationType.REST);
    nodeConfig.setServerConfigs(Arrays.asList(p2pServerConfig, q2tServerConfig, enclaveServerConfig));
    KeyData keyPair = new KeyData();
    keyPair.setPublicKey("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=");
    keyPair.setPrivateKey("yAWAJjwPqUtNVlqGjSrBmr1/iIkghuOh1803Yzx9jLM=");
    enclaveConfig.setKeys(new KeyConfiguration());
    enclaveConfig.getKeys().setKeyData(Arrays.asList(keyPair));
    nodeConfig.setPeers(Arrays.asList(new Peer(p2pServerConfig.getServerAddress())));
    enclaveConfig.setServerConfigs(Arrays.asList(enclaveServerConfig));
    Path configPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
    configPath.toFile().deleteOnExit();
    Path enclaveConfigPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
    enclaveConfigPath.toFile().deleteOnExit();
    try (OutputStream out = Files.newOutputStream(configPath)) {
        JaxbUtil.marshalWithNoValidation(nodeConfig, out);
        out.flush();
    }
    JaxbUtil.marshalWithNoValidation(enclaveConfig, System.out);
    try (OutputStream out = Files.newOutputStream(enclaveConfigPath)) {
        JaxbUtil.marshalWithNoValidation(enclaveConfig, out);
        out.flush();
    }
    ConfigDescriptor configDescriptor = new ConfigDescriptor(NodeAlias.A, configPath, nodeConfig, enclaveConfig, enclaveConfigPath);
    String key = configDescriptor.getKey().getPublicKey();
    URL file = Utils.toUrl(configDescriptor.getPath());
    String alias = configDescriptor.getAlias().name();
    this.party = new Party(key, file, alias);
    nodeExecManager = new NodeExecManager(configDescriptor);
    enclaveExecManager = new EnclaveExecManager(configDescriptor);
    enclaveExecManager.start();
    nodeExecManager.start();
    client = party.getRestClient();
}
Also used : Path(java.nio.file.Path) PortUtil(config.PortUtil) OutputStream(java.io.OutputStream) NodeExecManager(exec.NodeExecManager) EnclaveExecManager(exec.EnclaveExecManager) URL(java.net.URL) Party(com.quorum.tessera.test.Party) ConfigDescriptor(config.ConfigDescriptor) Before(org.junit.Before)

Example 32 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class VersionIT method getSupportedVersions.

@Test
public void getSupportedVersions() {
    Map<URI, Party> uriPartyPairs = partyHelper.getParties().map(p -> Map.of(p.getQ2TUri(), p, p.getP2PUri(), p)).flatMap(m -> m.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    uriPartyPairs.entrySet().forEach(pair -> {
        URI u = pair.getKey();
        Party party = pair.getValue();
        Response response = party.getRestClient().target(u).path("version").path("api").request().get();
        assertThat(response.getStatus()).describedAs("%s should return status 200", u).isEqualTo(200);
        JsonArray versions = response.readEntity(JsonArray.class);
        assertThat(versions.stream().map(JsonString.class::cast).map(JsonString::getString).toArray(String[]::new)).describedAs("%s/version/api should return 1.0, 2.0, 2.1, 3.0, 4.0, 5.0", u).containsExactly("1.0", "2.0", "2.1", "3.0", "4.0", "5.0");
    });
}
Also used : AppType(com.quorum.tessera.config.AppType) Client(jakarta.ws.rs.client.Client) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) PartyHelper(com.quorum.tessera.test.PartyHelper) ServerConfig(com.quorum.tessera.config.ServerConfig) Collectors(java.util.stream.Collectors) Response(jakarta.ws.rs.core.Response) Map(java.util.Map) URI(java.net.URI) Party(com.quorum.tessera.test.Party) JsonArray(jakarta.json.JsonArray) JsonString(jakarta.json.JsonString) Response(jakarta.ws.rs.core.Response) JsonArray(jakarta.json.JsonArray) Party(com.quorum.tessera.test.Party) JsonString(jakarta.json.JsonString) JsonString(jakarta.json.JsonString) URI(java.net.URI) Map(java.util.Map) Test(org.junit.Test)

Example 33 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class PrivacyIT method updateExistingContractByParticipant.

@Test
public void updateExistingContractByParticipant() {
    final String originalHash = sendContractCreationTransaction(PrivacyMode.PARTY_PROTECTION);
    Party sender = partyHelper.findByAlias(NodeAlias.B);
    SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(new RestUtils().createTransactionData());
    sendRequest.setFrom(sender.getPublicKey());
    List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.A).getPublicKey());
    sendRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
    sendRequest.setPrivacyFlag(PrivacyMode.PARTY_PROTECTION.getPrivacyFlag());
    sendRequest.setAffectedContractTransactions(originalHash);
    Response response = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
    assertThat(response.getStatus()).isEqualTo(201);
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) RestUtils(com.quorum.tessera.test.rest.RestUtils) Test(org.junit.Test)

Example 34 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class PrivacyIT method sendPSVTransactionWithoutExecHashWillBeRejected.

@Test
public void sendPSVTransactionWithoutExecHashWillBeRejected() {
    Party sender = partyHelper.findByAlias(NodeAlias.A);
    SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(new RestUtils().createTransactionData());
    sendRequest.setFrom(sender.getPublicKey());
    List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.B).getPublicKey());
    sendRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
    sendRequest.setPrivacyFlag(PrivacyMode.PRIVATE_STATE_VALIDATION.getPrivacyFlag());
    sendRequest.setAffectedContractTransactions(new String[0]);
    Response response = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
    assertThat(response.getStatus()).isEqualTo(400);
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) RestUtils(com.quorum.tessera.test.rest.RestUtils) Test(org.junit.Test)

Example 35 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class PrivacyIT method updateExistingContractByNonParticipant.

@Test
public void updateExistingContractByNonParticipant() {
    final String originalHash = sendContractCreationTransaction(PrivacyMode.PARTY_PROTECTION);
    Party sender = partyHelper.findByAlias(NodeAlias.C);
    SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(new RestUtils().createTransactionData());
    sendRequest.setFrom(sender.getPublicKey());
    List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.B).getPublicKey());
    sendRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
    sendRequest.setPrivacyFlag(PrivacyMode.PARTY_PROTECTION.getPrivacyFlag());
    sendRequest.setAffectedContractTransactions(originalHash);
    Response response = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
    assertThat(response.getStatus()).isEqualTo(403);
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) RestUtils(com.quorum.tessera.test.rest.RestUtils) Test(org.junit.Test)

Aggregations

Party (com.quorum.tessera.test.Party)63 Response (jakarta.ws.rs.core.Response)60 Test (org.junit.Test)46 SendResponse (com.quorum.tessera.api.SendResponse)45 SendRequest (com.quorum.tessera.api.SendRequest)43 ReceiveResponse (com.quorum.tessera.api.ReceiveResponse)32 URI (java.net.URI)16 RestUtils (com.quorum.tessera.test.rest.RestUtils)11 JsonObject (jakarta.json.JsonObject)7 PartyHelper (com.quorum.tessera.test.PartyHelper)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 PayloadEncryptResponse (com.quorum.tessera.api.PayloadEncryptResponse)4 Entity (jakarta.ws.rs.client.Entity)4 StringReader (java.io.StringReader)4 ExecutionContext (suite.ExecutionContext)4 ServerConfig (com.quorum.tessera.config.ServerConfig)3 ConfigDescriptor (config.ConfigDescriptor)3 Json (jakarta.json.Json)3 Client (jakarta.ws.rs.client.Client)3 Before (org.junit.Before)3