Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from sjones4/autoscaling-missing-param-validation
Browse files Browse the repository at this point in the history
Auto scaling parameter validation test updated to cover EUCA-13035
  • Loading branch information
ccassler authored Mar 15, 2017
2 parents e9a9e1e + 02b1ee0 commit 99bc4eb
Show file tree
Hide file tree
Showing 3 changed files with 595 additions and 26 deletions.
150 changes: 127 additions & 23 deletions src/main/java/com/eucalyptus/tests/awssdk/TestAutoScalingValidation.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
/*************************************************************************
* Copyright 2009-2016 Eucalyptus Systems, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
* Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
* CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
* additional information or have any questions.
************************************************************************/
package com.eucalyptus.tests.awssdk;

import com.amazonaws.AmazonServiceException;
Expand All @@ -33,9 +14,10 @@
/**
* This application tests parameter validation for auto scaling.
* <p/>
* This is verification for the story:
* This is verification for:
* <p/>
* https://eucalyptus.atlassian.net/browse/EUCA-5016
* https://eucalyptus.atlassian.net/browse/EUCA-13035
*/
public class TestAutoScalingValidation {

Expand Down Expand Up @@ -66,6 +48,8 @@ public void run() {
assertThat(false, "Expected error when creating launch configuration with invalid name");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Create launch configuration with missing required parameter
Expand All @@ -77,6 +61,8 @@ public void run() {
assertThat(false, "Expected error when creating launch configuration with missing parameter");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Create launch configuration
Expand Down Expand Up @@ -106,9 +92,11 @@ public void run() {
.withMaxSize(1)
.withAvailabilityZones(AVAILABILITY_ZONE)
);
assertThat(false, "Expected error when creating launch group with invalid size");
assertThat(false, "Expected error when creating scaling group with invalid size");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Create scaling group with invalid capacity
Expand All @@ -122,9 +110,11 @@ public void run() {
.withDesiredCapacity(2)
.withAvailabilityZones(AVAILABILITY_ZONE)
);
assertThat(false, "Expected error when creating launch group with invalid capacity");
assertThat(false, "Expected error when creating scaling group with invalid capacity");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Create scaling group with invalid tag
Expand All @@ -143,9 +133,23 @@ public void run() {
new Tag().withKey("tag1" + nameSuffix).withValue("propagate").withPropagateAtLaunch(Boolean.TRUE)
)
);
assertThat(false, "Expected error when creating launch group with invalid tag");
assertThat(false, "Expected error when creating scaling group with invalid tag");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Create scaling group with missing required parameter
print("Creating auto scaling group with missing required parameters");
try {
as.createAutoScalingGroup( new CreateAutoScalingGroupRequest( )
.withAvailabilityZones( AVAILABILITY_ZONE ) );
assertThat(false, "Expected error when creating scaling group with missing required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Create scaling group
Expand All @@ -166,6 +170,8 @@ public void run() {
assertThat(false, "Expected error when creating tag on invalid group");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Register cleanup for launch configs
Expand All @@ -190,6 +196,8 @@ public void run() {
assertThat(false, "Expected error when creating invalid scaling policy");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Create invalid scaling policy
Expand All @@ -203,6 +211,102 @@ public void run() {
assertThat(false, "Expected error when creating invalid scaling policy");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Update group / set desired capacity with missing parameters
try {
as.updateAutoScalingGroup( new UpdateAutoScalingGroupRequest( ) );
assertThat(false, "Expected error when updating scaling group without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}
try {
as.setDesiredCapacity( new SetDesiredCapacityRequest( ) );
assertThat(false, "Expected error when setting desired capacity for scaling group without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Enable/disable metrics collection with missing parameters
try {
as.enableMetricsCollection( new EnableMetricsCollectionRequest( )
.withMetrics( "GroupMinSize" )
.withGranularity( "1Minute" )
);
assertThat(false, "Expected error when enabling metrics collection without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}
try {
as.disableMetricsCollection( new DisableMetricsCollectionRequest( )
.withMetrics( "GroupMinSize" ) );
assertThat(false, "Expected error when disabling metrics collection without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Suspend/resume scaling processes with missing parameters
try {
as.suspendProcesses( new SuspendProcessesRequest( ) );
assertThat(false, "Expected error when suspending processes without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}
try {
as.resumeProcesses( new ResumeProcessesRequest( ) );
assertThat(false, "Expected error when resuming processes without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Put / execute scaling policies with missing parameters
try {
as.putScalingPolicy( new PutScalingPolicyRequest( ) );
assertThat(false, "Expected error when putting scaling policy without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}
try {
as.executePolicy( new ExecutePolicyRequest( ) );
assertThat(false, "Expected error when executing scaling policy without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

// Set instance health/terminate instance with missing parameters
try {
as.setInstanceHealth( new SetInstanceHealthRequest( ) );
assertThat(false, "Expected error when setting instance health without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}
try {
as.terminateInstanceInAutoScalingGroup( new TerminateInstanceInAutoScalingGroupRequest( ) );
assertThat(false, "Expected error when terminating scaling instance without required parameters");
} catch (AmazonServiceException e) {
print("Got expected exception: " + e);
assertThat( e.getErrorCode( ) != null, "Expected error code" );
assertThat( e.getErrorMessage( ) != null, "Expected error message" );
}

print("Test complete");
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/com/eucalyptus/tests/awssdk/TestSTSAssumeRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void STSAssumeRoleTest() throws Exception {
// create non-admin user in non-euca account then get credentials and connection for user
createAccount(account);
createUser(account, user);
createIAMPolicy(account, user, NAME_PREFIX + "policy", null);
createIAMPolicy( account, user, NAME_PREFIX + "policy",
"{\"Statement\":[{\"Effect\":\"Allow\",\"Resource\":\"*\",\"Action\":[\"iam:*\"]}]}" );

// get youAre connection for new user
AWSCredentialsProvider awsCredentialsProvider = new StaticCredentialsProvider(getUserCreds(account,user));
Expand Down Expand Up @@ -239,11 +240,26 @@ public void STSAssumeRoleTest() throws Exception {
} );

// Describe images using role
{
try {
final DescribeImagesResult imagesResult = getImagesUsingRole(account, user, roleName, roleArn, "222222222222");
assertThat(imagesResult.getImages().size() > 0, "Image not found when using role");
final String imageId = imagesResult.getImages().get(0).getImageId();
print("Found image: " + imageId);
} catch ( AmazonServiceException e ) {
// TODO this catch block can be removed once this test no longer needs to pass against versions < 5.0
print( "WARNING" );
print( "WARNING: Unexpected exception assuming role with valid external id, assuming pre-5.0 behaviour: " + e);
print( "WARNING" );
print( "Authorizing actions on all services for user " + user );
createIAMPolicy( account, user, NAME_PREFIX + "policy", null );
print( "Sleeping to allow policy change to propagate" );
N4j.sleep( 5 );
{
final DescribeImagesResult imagesResult = getImagesUsingRole(account, user, roleName, roleArn, "222222222222");
assertThat(imagesResult.getImages().size() > 0, "Image not found when using role");
final String imageId = imagesResult.getImages().get(0).getImageId();
print("Found image: " + imageId);
}
}

// Describe images using role with incorrect external id
Expand All @@ -258,7 +274,6 @@ public void STSAssumeRoleTest() throws Exception {
"Expected 'Not authorized to perform sts:AssumeRole' error message" );
}


// Get caller identity using user credentials
{
print("Testing get caller identity for user credentials");
Expand Down
Loading

0 comments on commit 99bc4eb

Please sign in to comment.