[TEST] restore throws IOException clause on all sync performRequest callers

Original commit: elastic/x-pack-elasticsearch@d114419752
This commit is contained in:
javanna 2016-07-19 16:51:07 +02:00 committed by Luca Cavanna
parent 5c31e20746
commit 63a5001837
6 changed files with 20 additions and 14 deletions

View File

@ -8,6 +8,8 @@ package org.elasticsearch.smoketest;
import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.Name;
import org.elasticsearch.test.rest.RestTestCandidate; import org.elasticsearch.test.rest.RestTestCandidate;
import java.io.IOException;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
public class GraphWithSecurityInsufficientRoleIT extends GraphWithSecurityIT { public class GraphWithSecurityInsufficientRoleIT extends GraphWithSecurityIT {
@ -16,7 +18,7 @@ public class GraphWithSecurityInsufficientRoleIT extends GraphWithSecurityIT {
super(testCandidate); super(testCandidate);
} }
public void test() throws Exception { public void test() throws IOException {
try { try {
super.test(); super.test();
fail("should have failed because of missing role"); fail("should have failed because of missing role");

View File

@ -47,7 +47,7 @@ public class MonitoringWithSecurityInsufficientRoleIT extends ESRestTestCase {
} }
@Override @Override
public void test() throws Exception { public void test() throws IOException {
try { try {
super.test(); super.test();
fail("should have failed because of missing role"); fail("should have failed because of missing role");

View File

@ -18,6 +18,7 @@ import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken; import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -34,7 +35,7 @@ public abstract class AbstractPrivilegeTestCase extends SecurityIntegTestCase {
protected static final String USERS_PASSWD_HASHED = new String(Hasher.BCRYPT.hash(new SecuredString("passwd".toCharArray()))); protected static final String USERS_PASSWD_HASHED = new String(Hasher.BCRYPT.hash(new SecuredString("passwd".toCharArray())));
protected void assertAccessIsAllowed(String user, String method, String uri, String body, protected void assertAccessIsAllowed(String user, String method, String uri, String body,
Map<String, String> params) throws Exception { Map<String, String> params) throws IOException {
Response response = getRestClient().performRequest(method, uri, params, entityOrNull(body), Response response = getRestClient().performRequest(method, uri, params, entityOrNull(body),
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
UsernamePasswordToken.basicAuthHeaderValue(user, new SecuredString("passwd".toCharArray())))); UsernamePasswordToken.basicAuthHeaderValue(user, new SecuredString("passwd".toCharArray()))));
@ -44,24 +45,24 @@ public abstract class AbstractPrivilegeTestCase extends SecurityIntegTestCase {
assertThat(message, statusLine.getStatusCode(), is(not(greaterThanOrEqualTo(400)))); assertThat(message, statusLine.getStatusCode(), is(not(greaterThanOrEqualTo(400))));
} }
protected void assertAccessIsAllowed(String user, String method, String uri, String body) throws Exception { protected void assertAccessIsAllowed(String user, String method, String uri, String body) throws IOException {
assertAccessIsAllowed(user, method, uri, body, new HashMap<>()); assertAccessIsAllowed(user, method, uri, body, new HashMap<>());
} }
protected void assertAccessIsAllowed(String user, String method, String uri) throws Exception { protected void assertAccessIsAllowed(String user, String method, String uri) throws IOException {
assertAccessIsAllowed(user, method, uri, null, new HashMap<>()); assertAccessIsAllowed(user, method, uri, null, new HashMap<>());
} }
protected void assertAccessIsDenied(String user, String method, String uri, String body) throws Exception { protected void assertAccessIsDenied(String user, String method, String uri, String body) throws IOException {
assertAccessIsDenied(user, method, uri, body, new HashMap<>()); assertAccessIsDenied(user, method, uri, body, new HashMap<>());
} }
protected void assertAccessIsDenied(String user, String method, String uri) throws Exception { protected void assertAccessIsDenied(String user, String method, String uri) throws IOException {
assertAccessIsDenied(user, method, uri, null, new HashMap<>()); assertAccessIsDenied(user, method, uri, null, new HashMap<>());
} }
protected void assertAccessIsDenied(String user, String method, String uri, String body, protected void assertAccessIsDenied(String user, String method, String uri, String body,
Map<String, String> params) throws Exception { Map<String, String> params) throws IOException {
try { try {
getRestClient().performRequest(method, uri, params, entityOrNull(body), getRestClient().performRequest(method, uri, params, entityOrNull(body),
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,

View File

@ -14,7 +14,6 @@ import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
@ -24,6 +23,7 @@ import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken; import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
@ -73,7 +73,7 @@ public class BulkUpdateTests extends SecurityIntegTestCase {
assertThat(getResponse.getField("bulk updated").getValue(), equalTo("bulk updated")); assertThat(getResponse.getField("bulk updated").getValue(), equalTo("bulk updated"));
} }
public void testThatBulkUpdateDoesNotLoseFieldsHttp() throws Exception { public void testThatBulkUpdateDoesNotLoseFieldsHttp() throws IOException {
final String path = "/index1/type/1"; final String path = "/index1/type/1";
final Header basicAuthHeader = new BasicHeader("Authorization", final Header basicAuthHeader = new BasicHeader("Authorization",
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME, UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,

View File

@ -14,6 +14,8 @@ import org.elasticsearch.test.SecuritySettingsSource;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken; import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
import java.io.IOException;
import static org.elasticsearch.rest.RestStatus.OK; import static org.elasticsearch.rest.RestStatus.OK;
import static org.elasticsearch.rest.RestStatus.UNAUTHORIZED; import static org.elasticsearch.rest.RestStatus.UNAUTHORIZED;
import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
@ -29,7 +31,7 @@ public class SecurityPluginTests extends SecurityIntegTestCase {
.build(); .build();
} }
public void testThatPluginIsLoaded() throws Exception { public void testThatPluginIsLoaded() throws IOException {
try { try {
logger.info("executing unauthorized request to /_xpack info"); logger.info("executing unauthorized request to /_xpack info");
getRestClient().performRequest("GET", "/_xpack"); getRestClient().performRequest("GET", "/_xpack");

View File

@ -28,6 +28,7 @@ import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3HttpServe
import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3Transport; import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3Transport;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.cert.CertPathBuilderException; import java.security.cert.CertPathBuilderException;
@ -57,7 +58,7 @@ public class SslClientAuthTests extends SecurityIntegTestCase {
return true; return true;
} }
public void testThatHttpFailsWithoutSslClientAuth() throws Exception { public void testThatHttpFailsWithoutSslClientAuth() throws IOException {
SSLIOSessionStrategy sessionStrategy = new SSLIOSessionStrategy(SSLContexts.createDefault(), NoopHostnameVerifier.INSTANCE); SSLIOSessionStrategy sessionStrategy = new SSLIOSessionStrategy(SSLContexts.createDefault(), NoopHostnameVerifier.INSTANCE);
try (RestClient restClient = createRestClient(httpClientBuilder -> httpClientBuilder.setSSLStrategy(sessionStrategy), "https")) { try (RestClient restClient = createRestClient(httpClientBuilder -> httpClientBuilder.setSSLStrategy(sessionStrategy), "https")) {
restClient.performRequest("GET", "/"); restClient.performRequest("GET", "/");
@ -69,7 +70,7 @@ public class SslClientAuthTests extends SecurityIntegTestCase {
} }
} }
public void testThatHttpWorksWithSslClientAuth() throws Exception { public void testThatHttpWorksWithSslClientAuth() throws IOException {
Settings settings = Settings.builder() Settings settings = Settings.builder()
.put(getSSLSettingsForStore("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.jks", "testclient")) .put(getSSLSettingsForStore("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.jks", "testclient"))
.build(); .build();
@ -83,7 +84,7 @@ public class SslClientAuthTests extends SecurityIntegTestCase {
} }
} }
public void testThatTransportWorksWithoutSslClientAuth() throws Exception { public void testThatTransportWorksWithoutSslClientAuth() throws IOException {
// specify an arbitrary keystore, that does not include the certs needed to connect to the transport protocol // specify an arbitrary keystore, that does not include the certs needed to connect to the transport protocol
Path store = getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient-client-profile.jks"); Path store = getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient-client-profile.jks");