Search in sources :

Example 51 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class ShutdownContainerIT method testShutDown.

@Test
public void testShutDown() {
    RestClient client = SERVER_TEST.rest().get();
    String containerName = "default";
    RestResponse response = join(client.cacheManager(containerName).caches());
    assertEquals(200, response.getStatus());
    response = join(client.container().shutdown());
    assertEquals(204, response.getStatus());
    // Ensure operations on the cachemanager are not possible
    response = join(client.cacheManager(containerName).caches());
    assertEquals(503, response.getStatus());
    response = join(client.counters());
    assertEquals(503, response.getStatus());
    // Ensure that the K8s liveness pods will not fail
    response = join(client.cacheManager(containerName).healthStatus());
    assertEquals(200, response.getStatus());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 52 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class ShutdownRestIT method testShutDown.

@Test
public void testShutDown() {
    RestClient client = SERVER_TEST.rest().create();
    sync(client.server().stop());
    eventually(() -> isServerShutdown(client));
    eventually(() -> !SERVER.getServerDriver().isRunning(0));
}
Also used : RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 53 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class RestAuthentication method testStaticResourcesAnonymously.

@Test
public void testStaticResourcesAnonymously() {
    InfinispanServerDriver serverDriver = SERVERS.getServerDriver();
    InetSocketAddress serverAddress = serverDriver.getServerSocket(0, 11222);
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder().followRedirects(false);
    builder.addServer().host(serverAddress.getHostName()).port(serverAddress.getPort());
    RestClient restClient = RestClient.forConfiguration(builder.build());
    RestResponse response = sync(restClient.raw().get("/"));
    // The root resource redirects to the console
    assertEquals(307, response.getStatus());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) InetSocketAddress(java.net.InetSocketAddress) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) InfinispanServerDriver(org.infinispan.server.test.core.InfinispanServerDriver) Test(org.junit.Test)

Example 54 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class RestAuthentication method testMalformedDigestHeader.

@Test
public void testMalformedDigestHeader() throws Exception {
    assumeTrue(mechanism.startsWith("DIGEST"));
    InfinispanServerDriver serverDriver = SERVERS.getServerDriver();
    InetSocketAddress serverAddress = serverDriver.getServerSocket(0, 11222);
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder().followRedirects(false);
    builder.addServer().host(serverAddress.getHostName()).port(serverAddress.getPort());
    RestClient restClient = RestClient.forConfiguration(builder.build());
    RestResponse response = sync(restClient.raw().get("/rest/v2/caches"));
    assertEquals(401, response.getStatus());
    String auth = response.headers().get("Www-Authenticate").stream().filter(h -> h.startsWith("Digest")).findFirst().get();
    HashMap<String, byte[]> parameters = DigestUtil.parseResponse(auth.substring(7).getBytes(UTF_8), UTF_8, false, httpDigest);
    final String realm = new String(parameters.get("realm"), UTF_8);
    final String nonce = new String(parameters.get("nonce"), UTF_8);
    final String opaque = new String(parameters.get("opaque"), UTF_8);
    final String algorithm = new String(parameters.get("algorithm"), UTF_8);
    final String charset = StandardCharsets.ISO_8859_1.name();
    final MessageDigest digester = MessageDigest.getInstance(algorithm);
    final String nc = "00000001";
    final String cnonce = "00000000";
    final String username = "h4ck0rz";
    final String password = "letmein";
    final String uri = "/backdoor";
    final String s1 = username + ':' + realm + ':' + password;
    final String s2 = "GET:" + uri;
    final String hasha1 = toHexString(digester.digest(s1.getBytes(charset)));
    final String h2 = toHexString(digester.digest(s2.getBytes(charset)));
    final String digestValue = hasha1 + ':' + nonce + ':' + nc + ':' + cnonce + ":auth:" + h2;
    final String digest = toHexString(digester.digest(digestValue.getBytes(StandardCharsets.US_ASCII.toString())));
    String authz = String.format("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\", qop=auth, nc=%s, cnonce=%s, algorithm=%s, opaque=\"%s\"", username, realm, nonce, uri, digest, nc, cnonce, algorithm, opaque);
    response = sync(restClient.raw().get("/rest/v2/caches", Collections.singletonMap("Authorization", authz)));
    assertEquals(400, response.getStatus());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) InetSocketAddress(java.net.InetSocketAddress) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) InfinispanServerDriver(org.infinispan.server.test.core.InfinispanServerDriver) Util.toHexString(org.infinispan.commons.util.Util.toHexString) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Example 55 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class AbstractAuthorization method testRestAdminsShouldBeAbleToModifyLoggers.

@Test
public void testRestAdminsShouldBeAbleToModifyLoggers() {
    RestClient client = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ADMIN)).get();
    assertStatus(NO_CONTENT, client.server().logging().setLogger("org.infinispan.TEST_LOGGER", "ERROR", "STDOUT"));
    assertStatus(NO_CONTENT, client.server().logging().removeLogger("org.infinispan.TEST_LOGGER"));
}
Also used : RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Aggregations

RestClient (org.infinispan.client.rest.RestClient)65 Test (org.junit.Test)41 RestResponse (org.infinispan.client.rest.RestResponse)37 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)26 Json (org.infinispan.commons.dataconversion.internal.Json)15 RestCacheClient (org.infinispan.client.rest.RestCacheClient)11 Test (org.testng.annotations.Test)10 IOException (java.io.IOException)6 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)6 ArrayList (java.util.ArrayList)4 RestServerHelper (org.infinispan.rest.helper.RestServerHelper)4 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)4 InetSocketAddress (java.net.InetSocketAddress)3 List (java.util.List)3 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)3 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 TestUser (org.infinispan.server.test.api.TestUser)3 File (java.io.File)2 UncheckedIOException (java.io.UncheckedIOException)2