Search in sources :

Example 11 with ServerConfig

use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.

the class ClientFactoryTest method testBuildSecureClientCAMode.

@Test
public void testBuildSecureClientCAMode() throws URISyntaxException {
    ServerConfig serverConfig = mock(ServerConfig.class);
    SslConfig sslConfig = mock(SslConfig.class);
    when(serverConfig.isSsl()).thenReturn(true);
    when(serverConfig.getServerUri()).thenReturn(new URI("https://localhost:8080"));
    when(serverConfig.getSslConfig()).thenReturn(sslConfig);
    Map<String, String> props = new HashMap<>();
    props.put("partyInfoInterval", "20000");
    when(serverConfig.getProperties()).thenReturn(props);
    SSLContext sslContext = mock(SSLContext.class);
    when(sslContextFactory.from(serverConfig.getServerUri().toString(), sslConfig)).thenReturn(sslContext);
    Client client = factory.buildFrom(serverConfig);
    assertThat(client).isNotNull();
    Map clientProperties = client.target(serverConfig.getServerUri()).getConfiguration().getProperties();
    assertThat(clientProperties.get(ClientProperties.READ_TIMEOUT)).isEqualTo(15000);
    assertThat(clientProperties.get(ClientProperties.CONNECT_TIMEOUT)).isEqualTo(15000);
    verify(sslContextFactory).from(serverConfig.getServerUri().toString(), sslConfig);
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) SslConfig(com.quorum.tessera.config.SslConfig) HashMap(java.util.HashMap) SSLContext(javax.net.ssl.SSLContext) Client(jakarta.ws.rs.client.Client) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 12 with ServerConfig

use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.

the class ClientFactoryTest method createUnixSocketClient.

@Test
public void createUnixSocketClient() {
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.setServerAddress("unix:/tmp/bogus.socket");
    serverConfig.setApp(AppType.Q2T);
    serverConfig.setCommunicationType(CommunicationType.REST);
    org.glassfish.jersey.client.JerseyClient result = (org.glassfish.jersey.client.JerseyClient) factory.buildFrom(serverConfig);
    assertThat(result.getConfiguration().getProperty("unixfile")).isNotNull().isInstanceOf(URI.class);
    assertThat(result.getConfiguration().getProperty("unixfile").toString()).isEqualTo("unix:/tmp/bogus.socket");
    assertThat(result.getConfiguration().getConnectorProvider().getClass().getName()).isEqualTo("com.quorum.tessera.jaxrs.unixsocket.JerseyUnixSocketConnectorProvider");
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) Test(org.junit.Test)

Example 13 with ServerConfig

use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.

the class ClientFactoryTest method testBuildInsecureClient.

@Test
public void testBuildInsecureClient() {
    ServerConfig serverConfig = mock(ServerConfig.class);
    when(serverConfig.isSsl()).thenReturn(false);
    when(serverConfig.getProperties()).thenReturn(Collections.emptyMap());
    Client client = factory.buildFrom(serverConfig);
    assertThat(client).isNotNull();
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Example 14 with ServerConfig

use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.

the class ResendClientProviderTest method provider.

@Test
public void provider() {
    try (var configFactoryMockedStatic = mockStatic(ConfigFactory.class);
        var clientSSLContextFactoryMockedStatic = mockStatic(ClientSSLContextFactory.class)) {
        ConfigFactory configFactory = mock(ConfigFactory.class);
        Config config = mock(Config.class);
        ServerConfig serverConfig = mock(ServerConfig.class);
        when(config.getP2PServerConfig()).thenReturn(serverConfig);
        when(configFactory.getConfig()).thenReturn(config);
        configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
        clientSSLContextFactoryMockedStatic.when(ClientSSLContextFactory::create).thenReturn(mock(ClientSSLContextFactory.class));
        ResendClient resendClient = ResendClientProvider.provider();
        assertThat(resendClient).isNotNull().isExactlyInstanceOf(RestResendClient.class);
        clientSSLContextFactoryMockedStatic.verify(ClientSSLContextFactory::create);
        clientSSLContextFactoryMockedStatic.verifyNoMoreInteractions();
        configFactoryMockedStatic.verify(ConfigFactory::create);
        configFactoryMockedStatic.verifyNoMoreInteractions();
    }
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) ClientSSLContextFactory(com.quorum.tessera.ssl.context.ClientSSLContextFactory) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 15 with ServerConfig

use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.

the class JerseyServerIT method onSetUp.

@Before
public void onSetUp() throws Exception {
    System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.setCommunicationType(CommunicationType.REST);
    serverConfig.setServerAddress("http://localhost:8080");
    CrossDomainConfig crossDomainConfig = new CrossDomainConfig();
    crossDomainConfig.setAllowedOrigins(Arrays.asList("*.acme.com", "*.other.com"));
    serverConfig.setCrossDomainConfig(crossDomainConfig);
    JaxbUtil.marshalWithNoValidation(serverConfig, System.out);
    server = new JerseyServer(serverConfig, SampleApplication.class);
    server.start();
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) CrossDomainConfig(com.quorum.tessera.config.CrossDomainConfig) Before(org.junit.Before)

Aggregations

ServerConfig (com.quorum.tessera.config.ServerConfig)27 Config (com.quorum.tessera.config.Config)20 Test (org.junit.Test)19 Before (org.junit.Before)13 Client (jakarta.ws.rs.client.Client)11 Collectors (java.util.stream.Collectors)10 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 After (org.junit.After)9 JsonObject (jakarta.json.JsonObject)7 Response (jakarta.ws.rs.core.Response)7 Stream (java.util.stream.Stream)7 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)6 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)6 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)6 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)6 KeyDataUtil (com.quorum.tessera.config.util.KeyDataUtil)6 PublicKey (com.quorum.tessera.encryption.PublicKey)6 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)6 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)6