Search in sources :

Example 6 with TestUser

use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.

the class AbstractAuthorization method testAdminAndDeployerCanManageSchema.

@Test
public void testAdminAndDeployerCanManageSchema() {
    String schema = Exceptions.unchecked(() -> Util.getResourceAsString("/sample_bank_account/bank.proto", this.getClass().getClassLoader()));
    for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.DEPLOYER)) {
        RemoteCacheManager remoteCacheManager = getServerTest().hotrod().withClientConfiguration(hotRodBuilders.get(user)).createRemoteCacheManager();
        RemoteCache<String, String> metadataCache = remoteCacheManager.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
        metadataCache.put(BANK_PROTO, schema);
        metadataCache.remove(BANK_PROTO);
    }
}
Also used : RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 7 with TestUser

use of org.infinispan.server.test.api.TestUser 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 8 with TestUser

use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.

the class AbstractAuthorization method testNonBulkReadUsersCannotQuery.

@Test
public void testNonBulkReadUsersCannotQuery() {
    org.infinispan.configuration.cache.ConfigurationBuilder builder = prepareIndexedCache();
    // Hot Rod
    for (TestUser user : EnumSet.of(TestUser.READER, TestUser.WRITER)) {
        RemoteCache<Integer, User> userCache = getServerTest().hotrod().withClientConfiguration(clientConfigurationWithProtostreamMarshaller(user)).withServerConfiguration(builder).get();
        QueryFactory qf = Search.getQueryFactory(userCache);
        Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'Tom'");
        Exceptions.expectException(HotRodClientException.class, "(?s).*ISPN000287.*", () -> query.execute().list());
    }
    // REST
    for (TestUser user : EnumSet.of(TestUser.READER, TestUser.WRITER, TestUser.MONITOR)) {
        RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
        assertStatus(FORBIDDEN, userCache.query("FROM sample_bank_account.User WHERE name = 'Tom'"));
        assertStatus(OK, userCache.searchStats());
        assertStatus(OK, userCache.indexStats());
        assertStatus(OK, userCache.queryStats());
    }
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) TestUser(org.infinispan.server.test.api.TestUser) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 9 with TestUser

use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.

the class AbstractAuthorization method testScriptUpload.

@Test
public void testScriptUpload() {
    SkipJunit.skipSinceJDK(16);
    InfinispanServerTestMethodRule serverTest = getServerTest();
    for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.DEPLOYER)) {
        RemoteCacheManager remoteCacheManager = serverTest.hotrod().withClientConfiguration(hotRodBuilders.get(user)).createRemoteCacheManager();
        serverTest.addScript(remoteCacheManager, "scripts/test.js");
    }
    for (TestUser user : EnumSet.of(TestUser.MONITOR, TestUser.APPLICATION, TestUser.OBSERVER, TestUser.WRITER)) {
        RemoteCacheManager remoteCacheManager = serverTest.hotrod().withClientConfiguration(hotRodBuilders.get(user)).createRemoteCacheManager();
        Exceptions.expectException(HotRodClientException.class, "(?s).*ISPN000287.*", () -> serverTest.addScript(remoteCacheManager, "scripts/test.js"));
    }
}
Also used : RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) InfinispanServerTestMethodRule(org.infinispan.server.test.junit4.InfinispanServerTestMethodRule) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 10 with TestUser

use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.

the class AbstractAuthorization method testNonCreatorsSchema.

@Test
public void testNonCreatorsSchema() {
    String schema = Exceptions.unchecked(() -> Util.getResourceAsString("/sample_bank_account/bank.proto", this.getClass().getClassLoader()));
    for (TestUser user : EnumSet.of(TestUser.APPLICATION, TestUser.OBSERVER, TestUser.WRITER)) {
        RemoteCacheManager remoteCacheManager = getServerTest().hotrod().withClientConfiguration(hotRodBuilders.get(user)).createRemoteCacheManager();
        RemoteCache<String, String> metadataCache = remoteCacheManager.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
        Exceptions.expectException(HotRodClientException.class, "(?s).*ISPN000287.*", () -> metadataCache.put(BANK_PROTO, schema));
    }
}
Also used : RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Aggregations

TestUser (org.infinispan.server.test.api.TestUser)19 Test (org.junit.Test)12 RestCacheClient (org.infinispan.client.rest.RestCacheClient)5 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)3 RestClient (org.infinispan.client.rest.RestClient)3 UserTool (org.infinispan.cli.user.UserTool)2 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)2 User (org.infinispan.protostream.sampledomain.User)2 QueryFactory (org.infinispan.query.dsl.QueryFactory)2 AuthorizationPermission (org.infinispan.security.AuthorizationPermission)2 InfinispanServerTestMethodRule (org.infinispan.server.test.junit4.InfinispanServerTestMethodRule)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 CertificateException (java.security.cert.CertificateException)1