Search in sources :

Example 11 with RestApiConfig

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

the class RestApiFilterTest method testHttpGetForUnknownResource.

/**
 * <pre>
 * Given: RestApiConfig is explicitly enabled
 * When: HTTP GET command is used to retrieve a non-Hazelcast resource
 * Then: connection is terminated after reading the command line
 * </pre>
 */
@Test
public void testHttpGetForUnknownResource() 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(GET);
        client.waitUntilClosed(2000);
        assertFalse(client.isConnectionClosed());
        client.sendData(" /test/abc HTTP/1.0" + CRLF);
        client.waitUntilClosed();
        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 12 with RestApiConfig

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

the class TextProtocolsConfigTest method testRestApiCallEnabledGroupsEnabled.

/**
 * <pre>
 * Given: RestApiConfig is explicitly enabled and all groups are explicitly enabled
 * When: REST endpoint is accessed
 * Then: access is permitted
 * </pre>
 */
@Test
public void testRestApiCallEnabledGroupsEnabled() throws Exception {
    Config config = new Config();
    config.getNetworkConfig().setRestApiConfig(new RestApiConfig().setEnabled(true).enableAllGroups());
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    for (TestUrl testUrl : TEST_URLS) {
        assertTextProtocolResponse(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 13 with RestApiConfig

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

the class TextProtocolsConfigTest method testRestApiCallWithDefaults.

/**
 * <pre>
 * Given: -
 * When: empty RestApiConfig object is created
 * Then: access to all REST endpoints is denied
 * </pre>
 */
@Test
public void testRestApiCallWithDefaults() throws Exception {
    Config config = new Config();
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    for (TestUrl testUrl : TEST_URLS) {
        assertNoTextProtocolResponse(hz, testUrl);
    }
}
Also used : 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 14 with RestApiConfig

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

the class TextProtocolsConfigTest method testRestApiCallDisabledGroupsEnabled.

/**
 * <pre>
 * Given: RestApiConfig is explicitly disabled and all groups are explicitly enabled
 * When: REST endpoint is accessed
 * Then: access is denied
 * </pre>
 */
@Test
public void testRestApiCallDisabledGroupsEnabled() throws Exception {
    Config config = new Config();
    config.getNetworkConfig().setRestApiConfig(new RestApiConfig().setEnabled(false).enableAllGroups());
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    for (TestUrl testUrl : TEST_URLS) {
        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 15 with RestApiConfig

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

the class TextProtocolsConfigTest method testRestApiDefaults.

/**
 * <pre>
 * Given: -
 * When: empty RestApiConfig object is created
 * Then: it's disabled and the only enabled REST endpoint group is the CLUSTER_READ
 * </pre>
 */
@Test
public void testRestApiDefaults() throws Exception {
    RestApiConfig restApiConfig = new RestApiConfig();
    assertFalse("REST should be disabled by default", restApiConfig.isEnabled());
    for (RestEndpointGroup endpointGroup : RestEndpointGroup.values()) {
        if (isExpectedDefaultEnabled(endpointGroup)) {
            assertTrue("REST endpoint group should be enabled by default: " + endpointGroup, restApiConfig.isGroupEnabled(endpointGroup));
        } else {
            assertFalse("REST endpoint group should be disabled by default: " + endpointGroup, restApiConfig.isGroupEnabled(endpointGroup));
        }
    }
}
Also used : RestApiConfig(com.hazelcast.config.RestApiConfig) RestEndpointGroup(com.hazelcast.config.RestEndpointGroup) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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