Search in sources :

Example 11 with RestClient

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

the class AbstractAuthorization method testRestNonAdminsMustNotAdminServer.

@Test
public void testRestNonAdminsMustNotAdminServer() {
    for (TestUser user : TestUser.NON_ADMINS) {
        RestClientConfigurationBuilder userConfig = restBuilders.get(user);
        RestClient client = getServerTest().rest().withClientConfiguration(userConfig).get();
        assertStatus(FORBIDDEN, client.server().report());
        assertStatus(FORBIDDEN, client.server().connectorStop("endpoint-default"));
        assertStatus(FORBIDDEN, client.server().connectorStart("endpoint-default"));
        assertStatus(FORBIDDEN, client.server().connectorIpFilterSet("endpoint-default", Collections.emptyList()));
        assertStatus(FORBIDDEN, client.server().connectorIpFiltersClear("endpoint-default"));
        assertStatus(FORBIDDEN, client.server().memory());
        assertStatus(FORBIDDEN, client.server().env());
        assertStatus(FORBIDDEN, client.server().configuration());
    }
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 12 with RestClient

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

the class AbstractAuthorization method testRestNonAdminsMustNotModifyCacheIgnores.

@Test
public void testRestNonAdminsMustNotModifyCacheIgnores() {
    for (TestUser user : TestUser.NON_ADMINS) {
        RestClient client = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get();
        assertStatus(FORBIDDEN, client.server().ignoreCache("default", "predefined"));
        assertStatus(FORBIDDEN, client.server().unIgnoreCache("default", "predefined"));
    }
}
Also used : RestClient(org.infinispan.client.rest.RestClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 13 with RestClient

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

the class GracefulShutdownRestartIT method testGracefulShutdownRestart.

@Test
public void testGracefulShutdownRestart() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC).persistence().addSingleFileStore().segmented(false);
    RemoteCache<Object, Object> hotRod = SERVER_TEST.hotrod().withServerConfiguration(builder).create();
    for (int i = 0; i < 100; i++) {
        hotRod.put(String.format("k%03d", i), String.format("v%03d", i));
    }
    RestClientConfigurationBuilder restClientBuilder = new RestClientConfigurationBuilder().socketTimeout(RestClientConfigurationProperties.DEFAULT_SO_TIMEOUT * 60).connectionTimeout(RestClientConfigurationProperties.DEFAULT_CONNECT_TIMEOUT * 60);
    RestClient rest = SERVER_TEST.rest().withClientConfiguration(restClientBuilder).get();
    sync(rest.cluster().stop(), 5, TimeUnit.MINUTES);
    ContainerInfinispanServerDriver serverDriver = (ContainerInfinispanServerDriver) SERVER.getServerDriver();
    Eventually.eventually("Cluster did not shutdown within timeout", () -> (!serverDriver.isRunning(0) && !serverDriver.isRunning(1)), serverDriver.getTimeout(), 1, TimeUnit.SECONDS);
    serverDriver.restartCluster();
    for (int i = 0; i < 100; i++) {
        assertEquals(String.format("v%03d", i), hotRod.get(String.format("k%03d", i)));
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) ContainerInfinispanServerDriver(org.infinispan.server.test.core.ContainerInfinispanServerDriver) Test(org.junit.Test)

Example 14 with RestClient

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

the class RestAuthentication method testRestReadWrite.

@Test
public void testRestReadWrite() {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    if (!mechanism.isEmpty()) {
        builder.protocol(protocol).security().authentication().mechanism(mechanism).realm("default").username("all_user").password("all");
    }
    if (mechanism.isEmpty()) {
        Exceptions.expectException(SecurityException.class, () -> SERVER_TEST.rest().withClientConfiguration(builder).create());
    } else {
        RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
        RestResponse response = sync(client.cache(SERVER_TEST.getMethodName()).post("k1", "v1"));
        assertEquals(204, response.getStatus());
        assertEquals(protocol, response.getProtocol());
        response = sync(client.cache(SERVER_TEST.getMethodName()).get("k1"));
        assertEquals(200, response.getStatus());
        assertEquals(protocol, response.getProtocol());
        assertEquals("v1", response.getBody());
    }
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 15 with RestClient

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

the class AbstractAuthorization method searchActions.

private void searchActions(TestUser user, String indexedCache, int status, int noContentStatus) {
    RestClient client = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get();
    assertStatus(status, client.cache(indexedCache).clearSearchStats());
    assertStatus(noContentStatus, client.cache(indexedCache).reindex());
    assertStatus(noContentStatus, client.cache(indexedCache).clearIndex());
}
Also used : RestClient(org.infinispan.client.rest.RestClient)

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