Search in sources :

Example 21 with RestApiConfig

use of com.hazelcast.config.RestApiConfig in project hazelcast by hazelcast.

the class TextProtocolsConfigTest method testEnabledRestApiCallWithGroupDefaults.

/**
 * <pre>
 * Given: RestApiConfig is explicitly enabled
 * When: REST endpoint is accessed
 * Then: it is permitted/denied based on its default groups values
 * </pre>
 */
@Test
public void testEnabledRestApiCallWithGroupDefaults() throws Exception {
    Config config = new Config();
    config.getNetworkConfig().setRestApiConfig(new RestApiConfig().setEnabled(true));
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    for (TestUrl testUrl : TEST_URLS) {
        if (isExpectedDefaultEnabled(testUrl.restEndpointGroup)) {
            assertTextProtocolResponse(hz, testUrl);
        } else {
            assertNoTextProtocolResponse(hz, testUrl);
        }
    }
}
Also used : RestApiConfig(com.hazelcast.config.RestApiConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) RestApiConfig(com.hazelcast.config.RestApiConfig) MemcacheProtocolConfig(com.hazelcast.config.MemcacheProtocolConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with RestApiConfig

use of com.hazelcast.config.RestApiConfig in project hazelcast by hazelcast.

the class TextProtocolsConfigTest method testAllRestPropertiesEnabled.

@Test
public void testAllRestPropertiesEnabled() throws Exception {
    Config config = new Config();
    config.getNetworkConfig().getMemcacheProtocolConfig().setEnabled(true);
    RestApiConfig restApiConfig = config.getNetworkConfig().getRestApiConfig();
    restApiConfig.setEnabled(true);
    restApiConfig.enableGroups(DATA);
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    hz.getMap("test").put("testKey", "testValue");
    assertTextProtocolResponse(hz, TEST_URL_DATA);
}
Also used : RestApiConfig(com.hazelcast.config.RestApiConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) RestApiConfig(com.hazelcast.config.RestApiConfig) MemcacheProtocolConfig(com.hazelcast.config.MemcacheProtocolConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with RestApiConfig

use of com.hazelcast.config.RestApiConfig in project hazelcast by hazelcast.

the class RestApiFilterTest method testMemcacheWhenRestApiEnabled.

/**
 * <pre>
 * Given: RestApiConfig is explicitly enabled
 * When: a memcache command prefix is used by client
 * Then: connection is terminated after reading the first 3 bytes (protocol header)
 * </pre>
 */
@Test
public void testMemcacheWhenRestApiEnabled() throws Exception {
    Config config = new Config();
    config.getNetworkConfig().setRestApiConfig(new RestApiConfig().setEnabled(true));
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    TextProtocolClient client = new TextProtocolClient(getAddress(hz).getInetSocketAddress());
    try {
        client.connect();
        client.sendData("ver");
        client.waitUntilClosed();
        assertEquals(3, client.getSentBytesCount());
        assertEquals(0, client.getReceivedBytes().length);
        assertTrue(client.isConnectionClosed());
    } finally {
        client.close();
    }
}
Also used : RestApiConfig(com.hazelcast.config.RestApiConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) RestApiConfig(com.hazelcast.config.RestApiConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with RestApiConfig

use of com.hazelcast.config.RestApiConfig in project hazelcast by hazelcast.

the class RestApiFilterTest method testRestApiDisabled.

/**
 * <pre>
 * Given: RestApiConfig is explicitly disabled
 * When: a HTTP GET method is used by client
 * Then: connection is terminated after reading the first 3 bytes (protocol header)
 * </pre>
 */
@Test
public void testRestApiDisabled() throws Exception {
    Config config = new Config();
    config.getNetworkConfig().setRestApiConfig(new RestApiConfig().setEnabled(false));
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    TextProtocolClient client = new TextProtocolClient(getAddress(hz).getInetSocketAddress());
    try {
        client.connect();
        client.sendData(GET);
        client.waitUntilClosed();
        assertEquals(3, client.getSentBytesCount());
        assertEquals(0, client.getReceivedBytes().length);
        assertTrue(client.isConnectionClosed());
    } finally {
        client.close();
    }
}
Also used : RestApiConfig(com.hazelcast.config.RestApiConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) RestApiConfig(com.hazelcast.config.RestApiConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with RestApiConfig

use of com.hazelcast.config.RestApiConfig in project hazelcast by hazelcast.

the class RestLogLevelTest method createReadWriteConfig.

protected Config createReadWriteConfig() {
    Config config = createConfig();
    RestApiConfig restApiConfig = new RestApiConfig().setEnabled(true).enableGroups(RestEndpointGroup.CLUSTER_READ).enableGroups(RestEndpointGroup.CLUSTER_WRITE);
    config.getNetworkConfig().setRestApiConfig(restApiConfig);
    return config;
}
Also used : RestApiConfig(com.hazelcast.config.RestApiConfig) Config(com.hazelcast.config.Config) RestApiConfig(com.hazelcast.config.RestApiConfig)

Aggregations

RestApiConfig (com.hazelcast.config.RestApiConfig)29 Config (com.hazelcast.config.Config)22 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 MemcacheProtocolConfig (com.hazelcast.config.MemcacheProtocolConfig)6 JoinConfig (com.hazelcast.config.JoinConfig)4 RestEndpointGroup (com.hazelcast.config.RestEndpointGroup)3 HazelcastTestSupport.smallInstanceConfig (com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig)3 RestServerEndpointConfig (com.hazelcast.config.RestServerEndpointConfig)2 AdvancedNetworkConfig (com.hazelcast.config.AdvancedNetworkConfig)1 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)1 NetworkConfig (com.hazelcast.config.NetworkConfig)1 WanReplicationConfig (com.hazelcast.config.WanReplicationConfig)1 StringUtil.bytesToString (com.hazelcast.internal.util.StringUtil.bytesToString)1 DiscoveryStrategyFactory (com.hazelcast.spi.discovery.DiscoveryStrategyFactory)1 Before (org.junit.Before)1