use of org.apache.hadoop.hbase.rest.client.Client in project hbase by apache.
the class TestSecurityHeadersFilter method testHstsAndCspSettings.
@Test
public void testHstsAndCspSettings() throws Exception {
TEST_UTIL.getConfiguration().set("hbase.http.filter.hsts.value", "max-age=63072000;includeSubDomains;preload");
TEST_UTIL.getConfiguration().set("hbase.http.filter.csp.value", "default-src https: data: 'unsafe-inline' 'unsafe-eval'");
TEST_UTIL.startMiniCluster();
REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
String path = "/version/cluster";
Response response = client.get(path);
assertThat(response.getCode(), equalTo(200));
assertThat("Header 'Strict-Transport-Security' is missing from Rest response", response.getHeader("Strict-Transport-Security"), is(not((String) null)));
assertThat("Header 'Strict-Transport-Security' has invalid value", response.getHeader("Strict-Transport-Security"), equalTo("max-age=63072000;includeSubDomains;preload"));
assertThat("Header 'Content-Security-Policy' is missing from Rest response", response.getHeader("Content-Security-Policy"), is(not((String) null)));
assertThat("Header 'Content-Security-Policy' has invalid value", response.getHeader("Content-Security-Policy"), equalTo("default-src https: data: 'unsafe-inline' 'unsafe-eval'"));
}
Aggregations