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());
}
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));
}
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());
}
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());
}
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"));
}
Aggregations