Search in sources :

Example 46 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestVPCFlowLogsS3 method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String flowLogsStackName = "vpc-flow-logs-s3-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
        try {
            this.createStack(context, flowLogsStackName, "vpc/vpc-flow-logs-s3.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            // TODO how can we check if this stack works?
            this.emptyBucket(context, this.getStackOutputValue(flowLogsStackName, "LogBucketName"));
        } finally {
            this.deleteStack(context, flowLogsStackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 47 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestSecurityAuthProxy method testHAGitHubOrga.

@Test
public void testHAGitHubOrga() {
    final Context context = new Context();
    final String zoneStackName = "zone-" + this.random8String();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "auth-proxy-ha-github-orga-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    final String subDomainName = stackName;
    try {
        this.createKey(keyName);
        try {
            this.createStack(context, zoneStackName, "vpc/zone-legacy.yaml", new Parameter().withParameterKey("HostedZoneName").withParameterValue(Config.get(Config.Key.DOMAIN_SUFFIX)), new Parameter().withParameterKey("HostedZoneId").withParameterValue(Config.get(Config.Key.HOSTED_ZONE_ID)));
            try {
                this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
                try {
                    this.createStack(context, stackName, "security/auth-proxy-ha-github-orga.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("CertificateArn").withParameterValue(Config.get(Config.Key.ACM_CERTIFICATE_ARN)), new Parameter().withParameterKey("KeyName").withParameterValue(keyName), // fake value
                    new Parameter().withParameterKey("GitHubOrganization").withParameterValue("widdix"), // fake value
                    new Parameter().withParameterKey("GitHubClientId").withParameterValue("2bb8ab97cb147fa499f6"), // fake value
                    new Parameter().withParameterKey("GitHubClientSecret").withParameterValue("d3a1a8a9b6525fb0599d22fc750f17ef76032c62"), new Parameter().withParameterKey("Upstream").withParameterValue("https://widdix.net/"), // fake value
                    new Parameter().withParameterKey("CookieSecret").withParameterValue("ylLjZRVNRlzW7sqyQeERBQ=="), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."));
                    final String url = "https://" + subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
                    final Callable<String> callable = () -> {
                        final HttpResponse response = WS.url(url).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 403) {
                            throw new RuntimeException("403 expected, but saw " + WS.getStatus(response));
                        }
                        return WS.getResponseAsString(response);
                    };
                    final String response = this.retry(context, callable);
                    // check if OAuth2 Proxy appears in HTML
                    Assert.assertTrue("http response body contains \"OAuth2 Proxy\"", response.contains("OAuth2 Proxy"));
                } finally {
                    this.deleteStack(context, stackName);
                }
            } finally {
                this.deleteStack(context, vpcStackName);
            }
        } finally {
            this.deleteStack(context, zoneStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 48 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestDynamoDB method test.

@Test
public void test() {
    final Context context = new Context();
    final String stackName = "dynamodb-" + this.random8String();
    try {
        this.createStack(context, stackName, "state/dynamodb.yaml", new Parameter().withParameterKey("PartitionKeyName").withParameterValue("id"), new Parameter().withParameterKey("BackupRetentionPeriod").withParameterValue("0"));
    // TODO how can we check if this stack works?
    } finally {
        this.deleteStack(context, stackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 49 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestDynamoDB method testGSI.

@Test
public void testGSI() {
    final Context context = new Context();
    final String stackName = "dynamodb-" + this.random8String();
    try {
        this.createStack(context, stackName, "state/dynamodb.yaml", new Parameter().withParameterKey("PartitionKeyName").withParameterValue("id"), new Parameter().withParameterKey("SortKeyName").withParameterValue("timestamp"), new Parameter().withParameterKey("Attribute1Name").withParameterValue("organisation"), new Parameter().withParameterKey("Attribute2Name").withParameterValue("category"), new Parameter().withParameterKey("Index1PartitionKeyName").withParameterValue("timestamp"), new Parameter().withParameterKey("Index2PartitionKeyName").withParameterValue("organisation"), new Parameter().withParameterKey("Index2SortKeyName").withParameterValue("category"), new Parameter().withParameterKey("BackupRetentionPeriod").withParameterValue("0"));
    // TODO how can we check if this stack works?
    } finally {
        this.deleteStack(context, stackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 50 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestElastiCacheRedis method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String stackName = "elasticache-redis-" + this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml");
        try {
            this.createStack(context, clientStackName, "state/client-sg.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            try {
                this.createStack(context, stackName, "state/elasticache-redis.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName));
            // TODO how can we check if this stack works? start a bastion host and try to connect?
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, clientStackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Aggregations

Context (de.widdix.awscftemplates.Context)70 Test (org.junit.Test)70 Parameter (com.amazonaws.services.cloudformation.model.Parameter)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)62 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)2 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)2 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)2 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)2 Session (com.jcraft.jsch.Session)1 Ignore (org.junit.Ignore)1