use of com.amazonaws.services.rds.model.CreateDBSecurityGroupRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseSecuritySetupTest method testCreateSecurityGroup.
/**
* Test that that the data is passed to the client as expected.
*/
@Test
public void testCreateSecurityGroup() {
CreateDBSecurityGroupRequest request = new CreateDBSecurityGroupRequest();
request.setDBSecurityGroupName("name");
request.setDBSecurityGroupDescription("description");
when(mockClient.createDBSecurityGroup(request)).thenReturn(new DBSecurityGroup());
databaseSecuritySetup.createSecurityGroup(request);
verify(mockClient, times(1)).createDBSecurityGroup(request);
}
use of com.amazonaws.services.rds.model.CreateDBSecurityGroupRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseSecuritySetupTest method testCreateSecurityGroupDuplicate.
/**
* Duplicate error codes are expected and should be ignored.
*/
@Test
public void testCreateSecurityGroupDuplicate() {
CreateDBSecurityGroupRequest request = new CreateDBSecurityGroupRequest();
request.setDBSecurityGroupName("name");
request.setDBSecurityGroupDescription("description");
AmazonServiceException exception = new AmazonServiceException("unknown");
exception.setErrorCode(ERROR_CODE_DB_SECURITY_GROUP_ALREADY_EXISTS);
when(mockClient.createDBSecurityGroup(request)).thenThrow(exception);
databaseSecuritySetup.createSecurityGroup(request);
verify(mockClient, times(1)).createDBSecurityGroup(request);
}
use of com.amazonaws.services.rds.model.CreateDBSecurityGroupRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseSecuritySetupTest method testCreateSecurityGroupUnknownError.
/**
* Unknown error codes should be re-thrown.
*/
@Test(expected = AmazonServiceException.class)
public void testCreateSecurityGroupUnknownError() {
CreateDBSecurityGroupRequest request = new CreateDBSecurityGroupRequest();
request.setDBSecurityGroupName("name");
request.setDBSecurityGroupDescription("description");
AmazonServiceException exception = new AmazonServiceException("unknown");
exception.setErrorCode("unknown error code");
when(mockClient.createDBSecurityGroup(request)).thenThrow(exception);
databaseSecuritySetup.createSecurityGroup(request);
}
use of com.amazonaws.services.rds.model.CreateDBSecurityGroupRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseSecuritySetup method setupDatabaseAllSecurityGroups.
/**
* Setup all of the database security groups needed for the stack.
* @param rdsClient
* @param config
* @param elasticSecurityGroup
* @return
*/
public void setupDatabaseAllSecurityGroups() {
// Create the ID generator security group
CreateDBSecurityGroupRequest request = new CreateDBSecurityGroupRequest();
request.setDBSecurityGroupDescription(config.getIdGeneratorDatabaseSecurityGroupDescription());
request.setDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName());
createSecurityGroup(request);
// Grant the EC2 security group access the ID generator database
addEC2SecurityGroup(request.getDBSecurityGroupName(), resources.getElasticBeanstalkEC2SecurityGroup());
// Allow anyone in the CIDR used for the stack SSH access to access this database.
addCIDRToGroup(request.getDBSecurityGroupName(), config.getCIDRForSSH());
// capture the group info.
resources.setIdGeneratorDatabaseSecurityGroup(describeDBSecurityGroup(request.getDBSecurityGroupName()));
// Create Stack database security group
request = new CreateDBSecurityGroupRequest();
request.setDBSecurityGroupDescription(config.getStackDatabaseSecurityGroupDescription());
request.setDBSecurityGroupName(config.getStackDatabaseSecurityGroupName());
createSecurityGroup(request);
// Grant the EC2 security group access the Stack MySQL database
addEC2SecurityGroup(request.getDBSecurityGroupName(), resources.getElasticBeanstalkEC2SecurityGroup());
// Allow anyone in the CIDR used for the stack SSH access to access this database.
addCIDRToGroup(request.getDBSecurityGroupName(), config.getCIDRForSSH());
// capture the group info.
resources.setStackInstancesDatabaseSecurityGroup(describeDBSecurityGroup(request.getDBSecurityGroupName()));
}
use of com.amazonaws.services.rds.model.CreateDBSecurityGroupRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class DatabaseSecuritySetupTest method testSetupDatabaseAllSecurityGroups.
/**
* Test that the expected security groups are created.
*/
@Test
public void testSetupDatabaseAllSecurityGroups() {
// Id gen
DBSecurityGroup expectedIdGroup = new DBSecurityGroup().withDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName());
DescribeDBSecurityGroupsResult result = new DescribeDBSecurityGroupsResult().withDBSecurityGroups(expectedIdGroup);
when(mockClient.describeDBSecurityGroups(new DescribeDBSecurityGroupsRequest().withDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName()))).thenReturn(result);
// stack
DBSecurityGroup expectedStackGroup = new DBSecurityGroup().withDBSecurityGroupName(config.getStackDatabaseSecurityGroupName());
result = new DescribeDBSecurityGroupsResult().withDBSecurityGroups(expectedStackGroup);
when(mockClient.describeDBSecurityGroups(new DescribeDBSecurityGroupsRequest().withDBSecurityGroupName(config.getStackDatabaseSecurityGroupName()))).thenReturn(result);
// Make the call
databaseSecuritySetup.setupDatabaseAllSecurityGroups();
// Verify the expected calls
// Id gen db security group
CreateDBSecurityGroupRequest request = new CreateDBSecurityGroupRequest();
request.setDBSecurityGroupDescription(config.getIdGeneratorDatabaseSecurityGroupDescription());
request.setDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName());
verify(mockClient, times(1)).createDBSecurityGroup(request);
// Stack db security group
request = new CreateDBSecurityGroupRequest();
request.setDBSecurityGroupDescription(config.getStackDatabaseSecurityGroupDescription());
request.setDBSecurityGroupName(config.getStackDatabaseSecurityGroupName());
verify(mockClient, times(1)).createDBSecurityGroup(request);
// Check the access adds
// Add to id gen group
AuthorizeDBSecurityGroupIngressRequest ingressRequest = new AuthorizeDBSecurityGroupIngressRequest(config.getIdGeneratorDatabaseSecurityGroupName());
ingressRequest.setEC2SecurityGroupOwnerId(elasticSecurityGroup.getOwnerId());
ingressRequest.setEC2SecurityGroupName(elasticSecurityGroup.getGroupName());
verify(mockClient, times(1)).authorizeDBSecurityGroupIngress(ingressRequest);
// add id gen CIDR
ingressRequest = new AuthorizeDBSecurityGroupIngressRequest(config.getIdGeneratorDatabaseSecurityGroupName());
ingressRequest.setCIDRIP(config.getCIDRForSSH());
verify(mockClient, times(1)).authorizeDBSecurityGroupIngress(ingressRequest);
// add to the stack db group
// Check the access adds
ingressRequest = new AuthorizeDBSecurityGroupIngressRequest(config.getStackDatabaseSecurityGroupName());
ingressRequest.setEC2SecurityGroupOwnerId(elasticSecurityGroup.getOwnerId());
ingressRequest.setEC2SecurityGroupName(elasticSecurityGroup.getGroupName());
verify(mockClient, times(1)).authorizeDBSecurityGroupIngress(ingressRequest);
// add stack CIDR
ingressRequest = new AuthorizeDBSecurityGroupIngressRequest(config.getStackDatabaseSecurityGroupName());
ingressRequest.setCIDRIP(config.getCIDRForSSH());
verify(mockClient, times(1)).authorizeDBSecurityGroupIngress(ingressRequest);
// Make sure the groups are set in the resources
assertEquals(expectedIdGroup, resources.getIdGeneratorDatabaseSecurityGroup());
assertEquals(expectedStackGroup, resources.getStackInstancesDatabaseSecurityGroup());
}
Aggregations