mirror of https://github.com/apache/jclouds.git
use more constants in sts tests
This commit is contained in:
parent
091ef98dc9
commit
d37484f127
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.filters;
|
package org.jclouds.aws.filters;
|
||||||
|
|
||||||
|
import static javax.ws.rs.HttpMethod.GET;
|
||||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
|
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -43,7 +44,6 @@ import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.name.Names;
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code FormSigner}
|
* Tests behavior of {@code FormSigner}
|
||||||
*
|
*
|
||||||
|
@ -76,7 +76,7 @@ public class FormSignerTest {
|
||||||
|
|
||||||
public static FormSigner staticCredentialsFilter = filter(new Credentials("identity", "credential"));
|
public static FormSigner staticCredentialsFilter = filter(new Credentials("identity", "credential"));
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.builder().method("GET")
|
HttpRequest request = HttpRequest.builder().method(GET)
|
||||||
.endpoint("http://localhost")
|
.endpoint("http://localhost")
|
||||||
.addHeader(HttpHeaders.HOST, "localhost")
|
.addHeader(HttpHeaders.HOST, "localhost")
|
||||||
.addFormParam("Action", "DescribeImages")
|
.addFormParam("Action", "DescribeImages")
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.handlers;
|
package org.jclouds.aws.handlers;
|
||||||
|
import static javax.ws.rs.HttpMethod.PUT;
|
||||||
|
import static javax.ws.rs.core.Response.Status.CONFLICT;
|
||||||
|
import static javax.ws.rs.core.Response.Status.UNAUTHORIZED;
|
||||||
import static org.easymock.EasyMock.createMock;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
|
@ -54,7 +56,7 @@ public class AWSClientErrorRetryHandlerTest {
|
||||||
AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler,
|
AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler,
|
||||||
ImmutableSet.<String> of());
|
ImmutableSet.<String> of());
|
||||||
|
|
||||||
assert !retry.shouldRetryRequest(command, HttpResponse.builder().statusCode(401).build());
|
assert !retry.shouldRetryRequest(command, HttpResponse.builder().statusCode(UNAUTHORIZED.getStatusCode()).build());
|
||||||
|
|
||||||
verify(utils, backoffLimitedRetryHandler, command);
|
verify(utils, backoffLimitedRetryHandler, command);
|
||||||
|
|
||||||
|
@ -72,10 +74,10 @@ public class AWSClientErrorRetryHandlerTest {
|
||||||
BackoffLimitedRetryHandler backoffLimitedRetryHandler = createMock(BackoffLimitedRetryHandler.class);
|
BackoffLimitedRetryHandler backoffLimitedRetryHandler = createMock(BackoffLimitedRetryHandler.class);
|
||||||
HttpCommand command = createMock(HttpCommand.class);
|
HttpCommand command = createMock(HttpCommand.class);
|
||||||
|
|
||||||
HttpRequest putBucket = HttpRequest.builder().method("PUT")
|
HttpRequest putBucket = HttpRequest.builder().method(PUT)
|
||||||
.endpoint("https://adriancole-blobstore113.s3.amazonaws.com/").build();
|
.endpoint("https://adriancole-blobstore113.s3.amazonaws.com/").build();
|
||||||
|
|
||||||
HttpResponse operationAborted = HttpResponse.builder().statusCode(409)
|
HttpResponse operationAborted = HttpResponse.builder().statusCode(CONFLICT.getStatusCode())
|
||||||
.payload(Payloads.newStringPayload(String.format("<Error><Code>%s</Code></Error>", code))).build();
|
.payload(Payloads.newStringPayload(String.format("<Error><Code>%s</Code></Error>", code))).build();
|
||||||
|
|
||||||
expect(command.getCurrentRequest()).andReturn(putBucket);
|
expect(command.getCurrentRequest()).andReturn(putBucket);
|
||||||
|
|
|
@ -17,7 +17,12 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.handlers;
|
package org.jclouds.aws.handlers;
|
||||||
|
import static javax.ws.rs.HttpMethod.GET;
|
||||||
|
import static javax.ws.rs.HttpMethod.POST;
|
||||||
|
import static javax.ws.rs.HttpMethod.PUT;
|
||||||
|
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
|
||||||
|
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||||
|
import static javax.ws.rs.core.Response.Status.CONFLICT;
|
||||||
import static org.easymock.EasyMock.createMock;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
|
@ -51,46 +56,46 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithNotFoundSetsResourceNotFoundException() {
|
public void test400WithNotFoundSetsResourceNotFoundException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>Monster.NotFound</Code></Error>", ResourceNotFoundException.class);
|
"<Error><Code>Monster.NotFound</Code></Error>", ResourceNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithCloudBridgeNotFoundSetsResourceNotFoundException() {
|
public void test400WithCloudBridgeNotFoundSetsResourceNotFoundException() {
|
||||||
assertCodeMakes("POST", URI.create("https://api.greenqloud.com/"), 400, "",
|
assertCodeMakes(POST, URI.create("https://api.greenqloud.com/"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>Client.InvalidInstanceID.NotFound</Code></Error>", ResourceNotFoundException.class);
|
"<Error><Code>Client.InvalidInstanceID.NotFound</Code></Error>", ResourceNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithInvalidIdIllegalArgumentException() {
|
public void test400WithInvalidIdIllegalArgumentException() {
|
||||||
assertCodeMakes("POST", URI.create("https://ec2.us-east-1.amazonaws.com"), 400, "HTTP/1.1 400", "",
|
assertCodeMakes(POST, URI.create("https://ec2.us-east-1.amazonaws.com"), BAD_REQUEST.getStatusCode(), "HTTP/1.1 400", "",
|
||||||
"Invalid id: \"asdaasdsa\" (expecting \"ami-...\")", IllegalArgumentException.class);
|
"Invalid id: \"asdaasdsa\" (expecting \"ami-...\")", IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithLoadBalancerNotFoundSetsResourceNotFoundException() {
|
public void test400WithLoadBalancerNotFoundSetsResourceNotFoundException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>LoadBalancerNotFound</Code></Error>", ResourceNotFoundException.class);
|
"<Error><Code>LoadBalancerNotFound</Code></Error>", ResourceNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithSecurityGroupNotFoundForProjectSetsResourceNotFoundException() {
|
public void test400WithSecurityGroupNotFoundForProjectSetsResourceNotFoundException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>SecurityGroupNotFoundForProject</Code></Error>", ResourceNotFoundException.class);
|
"<Error><Code>SecurityGroupNotFoundForProject</Code></Error>", ResourceNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithUnsupportedCodeMakesUnsupportedOperationException() {
|
public void test400WithUnsupportedCodeMakesUnsupportedOperationException() {
|
||||||
assertCodeMakes("POST", URI.create("https://ec2.us-west-1.amazonaws.com/"), 400, "",
|
assertCodeMakes(POST, URI.create("https://ec2.us-west-1.amazonaws.com/"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>UnsupportedOperation</Code></Error>", UnsupportedOperationException.class);
|
"<Error><Code>UnsupportedOperation</Code></Error>", UnsupportedOperationException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithAddressLimitExceededCodeMakesInsufficientResourcesException() {
|
public void test400WithAddressLimitExceededCodeMakesInsufficientResourcesException() {
|
||||||
assertCodeMakes(
|
assertCodeMakes(
|
||||||
"POST",
|
POST,
|
||||||
URI.create("https://ec2.us-east-1.amazonaws.com/"),
|
URI.create("https://ec2.us-east-1.amazonaws.com/"),
|
||||||
400,
|
BAD_REQUEST.getStatusCode(),
|
||||||
"",
|
"",
|
||||||
"<Response><Errors><Error><Code>AddressLimitExceeded</Code><Message>Too many addresses allocated</Message></Error></Errors><RequestID>c14f531a-cc35-4b48-8149-2655c7e6dc76</RequestID></Response>",
|
"<Response><Errors><Error><Code>AddressLimitExceeded</Code><Message>Too many addresses allocated</Message></Error></Errors><RequestID>c14f531a-cc35-4b48-8149-2655c7e6dc76</RequestID></Response>",
|
||||||
InsufficientResourcesException.class);
|
InsufficientResourcesException.class);
|
||||||
|
@ -98,25 +103,25 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithInUseCodeSetsIllegalStateException() {
|
public void test400WithInUseCodeSetsIllegalStateException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>InvalidPlacementGroup.InUse</Code></Error>", IllegalStateException.class);
|
"<Error><Code>InvalidPlacementGroup.InUse</Code></Error>", IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithUnknownSetsResourceNotFoundException() {
|
public void test400WithUnknownSetsResourceNotFoundException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>InvalidPlacementGroup.Unknown</Code></Error>", ResourceNotFoundException.class);
|
"<Error><Code>InvalidPlacementGroup.Unknown</Code></Error>", ResourceNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithIncorrectStateSetsIllegalStateException() {
|
public void test400WithIncorrectStateSetsIllegalStateException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>IncorrectState</Code></Error>", IllegalStateException.class);
|
"<Error><Code>IncorrectState</Code></Error>", IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithInUseSetsIllegalStateException() {
|
public void test400WithInUseSetsIllegalStateException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", "text/plain",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "", TEXT_PLAIN,
|
||||||
"The placement group 'jclouds#adriancoleec2cccluster#us-east-1' is in use and may not be deleted.",
|
"The placement group 'jclouds#adriancoleec2cccluster#us-east-1' is in use and may not be deleted.",
|
||||||
IllegalStateException.class);
|
IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
@ -124,9 +129,9 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
@Test
|
@Test
|
||||||
public void test409SetsIllegalStateException() {
|
public void test409SetsIllegalStateException() {
|
||||||
assertCodeMakes(
|
assertCodeMakes(
|
||||||
"PUT",
|
PUT,
|
||||||
URI.create("https://adriancole-blobstore011.s3.amazonaws.com/"),
|
URI.create("https://adriancole-blobstore011.s3.amazonaws.com/"),
|
||||||
409,
|
CONFLICT.getStatusCode(),
|
||||||
"",
|
"",
|
||||||
"<Error><Code>OperationAborted</Code><Message>A conflicting conditional operation is currently in progress against this resource. Please try again.</Message><RequestId>F716E81C3D814E59</RequestId><HostId>SDprHxWzG/YXzanVnV7VTz/wP+6fRt1dS+q00kH1rz248YOOSddkFiTXF04XtqNO</HostId></Error>",
|
"<Error><Code>OperationAborted</Code><Message>A conflicting conditional operation is currently in progress against this resource. Please try again.</Message><RequestId>F716E81C3D814E59</RequestId><HostId>SDprHxWzG/YXzanVnV7VTz/wP+6fRt1dS+q00kH1rz248YOOSddkFiTXF04XtqNO</HostId></Error>",
|
||||||
IllegalStateException.class);
|
IllegalStateException.class);
|
||||||
|
@ -134,19 +139,19 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithInvalidGroupDuplicateIllegalStateException() {
|
public void test400WithInvalidGroupDuplicateIllegalStateException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "application/unknown",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), BAD_REQUEST.getReasonPhrase(), "application/unknown",
|
||||||
"<Error><Code>InvalidGroup.Duplicate</Code></Error>", IllegalStateException.class);
|
"<Error><Code>InvalidGroup.Duplicate</Code></Error>", IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithInvalidKeyPairGroupDuplicateIllegalStateException() {
|
public void test400WithInvalidKeyPairGroupDuplicateIllegalStateException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "application/unknown",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), BAD_REQUEST.getReasonPhrase(), "application/unknown",
|
||||||
"<Error><Code>InvalidKeyPair.Duplicate</Code></Error>", IllegalStateException.class);
|
"<Error><Code>InvalidKeyPair.Duplicate</Code></Error>", IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithTextPlainIllegalArgumentException() {
|
public void test400WithTextPlainIllegalArgumentException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "text/plain",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), BAD_REQUEST.getReasonPhrase(), TEXT_PLAIN,
|
||||||
"Failure: 400 Bad Request\nFailed to bind the following fields\nMonitoring.Enabled = true\n\n\n",
|
"Failure: 400 Bad Request\nFailed to bind the following fields\nMonitoring.Enabled = true\n\n\n",
|
||||||
IllegalArgumentException.class);
|
IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
@ -154,9 +159,9 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
@Test
|
@Test
|
||||||
public void test400WithGroupAlreadyExistsEucalyptusIllegalStateException() {
|
public void test400WithGroupAlreadyExistsEucalyptusIllegalStateException() {
|
||||||
assertCodeMakes(
|
assertCodeMakes(
|
||||||
"GET",
|
GET,
|
||||||
URI.create("https://amazonaws.com/foo"),
|
URI.create("https://amazonaws.com/foo"),
|
||||||
400,
|
BAD_REQUEST.getStatusCode(),
|
||||||
"",
|
"",
|
||||||
"<?xml version=\"1.0\"?><Response><Errors><Error><Code>Groups</Code><Message>\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists</Message></Error></Errors><RequestID>e0133975-3bc5-456d-9753-1d61b27e07e9</RequestID></Response>",
|
"<?xml version=\"1.0\"?><Response><Errors><Error><Code>Groups</Code><Message>\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists</Message></Error></Errors><RequestID>e0133975-3bc5-456d-9753-1d61b27e07e9</RequestID></Response>",
|
||||||
IllegalStateException.class);
|
IllegalStateException.class);
|
||||||
|
@ -164,13 +169,13 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithAuthFailureSetsAuthorizationException() {
|
public void test400WithAuthFailureSetsAuthorizationException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>AuthFailure</Code></Error>", AuthorizationException.class);
|
"<Error><Code>AuthFailure</Code></Error>", AuthorizationException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithCloudBridgeAuthFailureSetsAuthorizationException() {
|
public void test400WithCloudBridgeAuthFailureSetsAuthorizationException() {
|
||||||
assertCodeMakes("POST", URI.create("https://api.greenqloud.com/"), 400, "",
|
assertCodeMakes(POST, URI.create("https://api.greenqloud.com/"), BAD_REQUEST.getStatusCode(), "",
|
||||||
"<Error><Code>Client.AuthFailure</Code></Error>", AuthorizationException.class);
|
"<Error><Code>Client.AuthFailure</Code></Error>", AuthorizationException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.util;
|
package org.jclouds.aws.util;
|
||||||
|
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
|
||||||
|
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||||
import static org.easymock.EasyMock.createMock;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
|
@ -63,7 +64,7 @@ public class AWSUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse response(InputStream content) {
|
HttpResponse response(InputStream content) {
|
||||||
HttpResponse response = HttpResponse.builder().statusCode(400)
|
HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode())
|
||||||
.message("boa")
|
.message("boa")
|
||||||
.payload(content)
|
.payload(content)
|
||||||
.addHeader("x-amz-request-id", "requestid")
|
.addHeader("x-amz-request-id", "requestid")
|
||||||
|
@ -77,7 +78,7 @@ public class AWSUtilsTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNoExceptionWhenNoPayload() {
|
public void testNoExceptionWhenNoPayload() {
|
||||||
HttpResponse response = HttpResponse.builder().statusCode(400).build();
|
HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()).build();
|
||||||
assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response));
|
assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +87,8 @@ public class AWSUtilsTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNoExceptionParsingTextPlain() {
|
public void testNoExceptionParsingTextPlain() {
|
||||||
HttpResponse response = HttpResponse.builder().statusCode(400).payload("foo bar").build();
|
HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()).payload("foo bar").build();
|
||||||
response.getPayload().getContentMetadata().setContentType("text/plain");
|
response.getPayload().getContentMetadata().setContentType(TEXT_PLAIN);
|
||||||
assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response));
|
assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.sts;
|
package org.jclouds.sts;
|
||||||
|
import static com.google.common.net.HttpHeaders.HOST;
|
||||||
|
import static javax.ws.rs.HttpMethod.POST;
|
||||||
|
import static javax.ws.rs.core.Response.Status.OK;
|
||||||
import static org.jclouds.sts.options.AssumeRoleOptions.Builder.externalId;
|
import static org.jclouds.sts.options.AssumeRoleOptions.Builder.externalId;
|
||||||
import static org.jclouds.sts.options.FederatedUserOptions.Builder.policy;
|
import static org.jclouds.sts.options.FederatedUserOptions.Builder.policy;
|
||||||
import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.serialNumber;
|
import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.serialNumber;
|
||||||
|
@ -39,9 +41,9 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = "unit", testName = "STSApiExpectTest")
|
@Test(groups = "unit", testName = "STSApiExpectTest")
|
||||||
public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
||||||
|
|
||||||
HttpRequest createTemporaryCredentials = HttpRequest.builder().method("POST")
|
HttpRequest createTemporaryCredentials = HttpRequest.builder().method(POST)
|
||||||
.endpoint("https://sts.amazonaws.com/")
|
.endpoint("https://sts.amazonaws.com/")
|
||||||
.addHeader("Host", "sts.amazonaws.com")
|
.addHeader(HOST, "sts.amazonaws.com")
|
||||||
.addFormParam("Action", "GetSessionToken")
|
.addFormParam("Action", "GetSessionToken")
|
||||||
.addFormParam("Signature", "ntC%2BPKAcmYTJ5Py5tjICG4KX5y00Pl2L0XJrLbSgLEs%3D")
|
.addFormParam("Signature", "ntC%2BPKAcmYTJ5Py5tjICG4KX5y00Pl2L0XJrLbSgLEs%3D")
|
||||||
.addFormParam("SignatureMethod", "HmacSHA256")
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
@ -50,7 +52,7 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
||||||
.addFormParam("Version", "2011-06-15")
|
.addFormParam("Version", "2011-06-15")
|
||||||
.addFormParam("AWSAccessKeyId", "identity").build();
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
HttpResponse createTemporaryCredentialsResponse = HttpResponse.builder().statusCode(200)
|
HttpResponse createTemporaryCredentialsResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
|
||||||
.payload(payloadFromResourceWithContentType("/session_token.xml", "text/xml")).build();
|
.payload(payloadFromResourceWithContentType("/session_token.xml", "text/xml")).build();
|
||||||
|
|
||||||
public void testCreateTemporaryCredentialsWhenResponseIs2xx() {
|
public void testCreateTemporaryCredentialsWhenResponseIs2xx() {
|
||||||
|
@ -62,9 +64,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
||||||
new GetSessionTokenResponseTest().expected().toString());
|
new GetSessionTokenResponseTest().expected().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRequest createTemporaryCredentialsWithOptions = HttpRequest.builder().method("POST")
|
HttpRequest createTemporaryCredentialsWithOptions = HttpRequest.builder().method(POST)
|
||||||
.endpoint("https://sts.amazonaws.com/")
|
.endpoint("https://sts.amazonaws.com/")
|
||||||
.addHeader("Host", "sts.amazonaws.com")
|
.addHeader(HOST, "sts.amazonaws.com")
|
||||||
.addFormParam("Action", "GetSessionToken")
|
.addFormParam("Action", "GetSessionToken")
|
||||||
.addFormParam("DurationSeconds", "900")
|
.addFormParam("DurationSeconds", "900")
|
||||||
.addFormParam("SerialNumber", "YourMFADeviceSerialNumber")
|
.addFormParam("SerialNumber", "YourMFADeviceSerialNumber")
|
||||||
|
@ -86,9 +88,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
||||||
new GetSessionTokenResponseTest().expected().toString());
|
new GetSessionTokenResponseTest().expected().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRequest assumeRole = HttpRequest.builder().method("POST")
|
HttpRequest assumeRole = HttpRequest.builder().method(POST)
|
||||||
.endpoint("https://sts.amazonaws.com/")
|
.endpoint("https://sts.amazonaws.com/")
|
||||||
.addHeader("Host", "sts.amazonaws.com")
|
.addHeader(HOST, "sts.amazonaws.com")
|
||||||
.addFormParam("Action", "AssumeRole")
|
.addFormParam("Action", "AssumeRole")
|
||||||
.addFormParam("RoleArn", "arn:aws:iam::123456789012:role/demo")
|
.addFormParam("RoleArn", "arn:aws:iam::123456789012:role/demo")
|
||||||
.addFormParam("RoleSessionName", "Bob")
|
.addFormParam("RoleSessionName", "Bob")
|
||||||
|
@ -99,7 +101,7 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
||||||
.addFormParam("Version", "2011-06-15")
|
.addFormParam("Version", "2011-06-15")
|
||||||
.addFormParam("AWSAccessKeyId", "identity").build();
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
HttpResponse assumeRoleResponse = HttpResponse.builder().statusCode(200)
|
HttpResponse assumeRoleResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
|
||||||
.payload(payloadFromResourceWithContentType("/assume_role.xml", "text/xml")).build();
|
.payload(payloadFromResourceWithContentType("/assume_role.xml", "text/xml")).build();
|
||||||
|
|
||||||
public void testAssumeRoleWhenResponseIs2xx() {
|
public void testAssumeRoleWhenResponseIs2xx() {
|
||||||
|
@ -112,9 +114,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
||||||
|
|
||||||
String policy = "{\"Statement\":[{\"Sid\":\"Stmt1\",\"Effect\":\"Allow\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}";
|
String policy = "{\"Statement\":[{\"Sid\":\"Stmt1\",\"Effect\":\"Allow\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}";
|
||||||
|
|
||||||
HttpRequest assumeRoleWithOptions = HttpRequest.builder().method("POST")
|
HttpRequest assumeRoleWithOptions = HttpRequest.builder().method(POST)
|
||||||
.endpoint("https://sts.amazonaws.com/")
|
.endpoint("https://sts.amazonaws.com/")
|
||||||
.addHeader("Host", "sts.amazonaws.com")
|
.addHeader(HOST, "sts.amazonaws.com")
|
||||||
.addFormParam("Action", "AssumeRole")
|
.addFormParam("Action", "AssumeRole")
|
||||||
.addFormParam("DurationSeconds", "900")
|
.addFormParam("DurationSeconds", "900")
|
||||||
.addFormParam("ExternalId", "123ABC")
|
.addFormParam("ExternalId", "123ABC")
|
||||||
|
@ -138,9 +140,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
||||||
new AssumeRoleResponseTest().expected().toString());
|
new AssumeRoleResponseTest().expected().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRequest createFederatedUser = HttpRequest.builder().method("POST")
|
HttpRequest createFederatedUser = HttpRequest.builder().method(POST)
|
||||||
.endpoint("https://sts.amazonaws.com/")
|
.endpoint("https://sts.amazonaws.com/")
|
||||||
.addHeader("Host", "sts.amazonaws.com")
|
.addHeader(HOST, "sts.amazonaws.com")
|
||||||
.addFormParam("Action", "GetFederationToken")
|
.addFormParam("Action", "GetFederationToken")
|
||||||
.addFormParam("Name", "Bob")
|
.addFormParam("Name", "Bob")
|
||||||
.addFormParam("Signature", "Z7AtGK4X9IAx/zMtLD7baNiyltNl%2BF%2BSHqjIGUidzOc%3D")
|
.addFormParam("Signature", "Z7AtGK4X9IAx/zMtLD7baNiyltNl%2BF%2BSHqjIGUidzOc%3D")
|
||||||
|
@ -150,7 +152,7 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
||||||
.addFormParam("Version", "2011-06-15")
|
.addFormParam("Version", "2011-06-15")
|
||||||
.addFormParam("AWSAccessKeyId", "identity").build();
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
HttpResponse createFederatedUserResponse = HttpResponse.builder().statusCode(200)
|
HttpResponse createFederatedUserResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
|
||||||
.payload(payloadFromResourceWithContentType("/federation_token.xml", "text/xml")).build();
|
.payload(payloadFromResourceWithContentType("/federation_token.xml", "text/xml")).build();
|
||||||
|
|
||||||
public void testCreateFederatedUserWhenResponseIs2xx() {
|
public void testCreateFederatedUserWhenResponseIs2xx() {
|
||||||
|
@ -161,9 +163,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest {
|
||||||
.expected().toString());
|
.expected().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRequest createFederatedUserWithOptions = HttpRequest.builder().method("POST")
|
HttpRequest createFederatedUserWithOptions = HttpRequest.builder().method(POST)
|
||||||
.endpoint("https://sts.amazonaws.com/")
|
.endpoint("https://sts.amazonaws.com/")
|
||||||
.addHeader("Host", "sts.amazonaws.com")
|
.addHeader(HOST, "sts.amazonaws.com")
|
||||||
.addFormParam("Action", "GetFederationToken")
|
.addFormParam("Action", "GetFederationToken")
|
||||||
.addFormParam("DurationSeconds", "900")
|
.addFormParam("DurationSeconds", "900")
|
||||||
.addFormParam("Name", "Bob")
|
.addFormParam("Name", "Bob")
|
||||||
|
|
Loading…
Reference in New Issue