-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
572 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
kotlin/services/cloudtrail/src/test/kotlin/CloudtrailKotlinTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider | ||
import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient | ||
import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest | ||
import com.google.gson.Gson | ||
import com.kotlin.cloudtrail.createNewTrail | ||
import com.kotlin.cloudtrail.deleteSpecificTrail | ||
import com.kotlin.cloudtrail.describeSpecificTrails | ||
import com.kotlin.cloudtrail.getSelectors | ||
import com.kotlin.cloudtrail.lookupAllEvents | ||
import com.kotlin.cloudtrail.setSelector | ||
import com.kotlin.cloudtrail.startLog | ||
import com.kotlin.cloudtrail.stopLog | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Order | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import org.junit.jupiter.api.TestMethodOrder | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@TestMethodOrder(OrderAnnotation::class) | ||
class CloudtrailKotlinTest { | ||
private var trailName = "" | ||
private var s3BucketName = "" | ||
|
||
@BeforeAll | ||
fun setup() = runBlocking { | ||
val gson = Gson() | ||
val json: String = getSecretValues() | ||
val values: SecretValues = gson.fromJson<SecretValues>(json, SecretValues::class.java) | ||
trailName = values.trailName.toString() | ||
s3BucketName = values.s3BucketName.toString() | ||
|
||
// Uncomment this code block if you prefer using a config.properties file to retrieve AWS values required for these tests. | ||
/* | ||
val input: InputStream = this.javaClass.getClassLoader().getResourceAsStream("config.properties") | ||
val prop = Properties() | ||
// load the properties file. | ||
prop.load(input) | ||
trailName = prop.getProperty("trailName") | ||
s3BucketName = prop.getProperty("s3BucketName") | ||
*/ | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
fun createTrail() = runBlocking { | ||
createNewTrail(trailName, s3BucketName) | ||
println("Test 1 passed") | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
fun putEventSelectors() = runBlocking { | ||
setSelector(trailName) | ||
println("Test 2 passed") | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
fun getEventSelectors() = runBlocking { | ||
getSelectors(trailName) | ||
println("Test 3 passed") | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
fun lookupEvents() = runBlocking { | ||
lookupAllEvents() | ||
println("Test 4 passed") | ||
} | ||
|
||
@Test | ||
@Order(5) | ||
fun describeTrails() = runBlocking { | ||
describeSpecificTrails(trailName) | ||
println("Test 5 passed") | ||
} | ||
|
||
@Test | ||
@Order(6) | ||
fun startLogging() = runBlocking { | ||
startLog(trailName) | ||
stopLog(trailName) | ||
println("Test 6 passed") | ||
} | ||
|
||
@Test | ||
@Order(7) | ||
fun deleteTrail() = runBlocking { | ||
deleteSpecificTrail(trailName) | ||
println("Test 7 passed") | ||
} | ||
|
||
private suspend fun getSecretValues(): String { | ||
val secretName = "test/cloudtrail" | ||
val valueRequest = GetSecretValueRequest { | ||
secretId = secretName | ||
} | ||
SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient -> | ||
val valueResponse = secretClient.getSecretValue(valueRequest) | ||
return valueResponse.secretString.toString() | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("A class used to get test values from test/cloudtrail (an AWS Secrets Manager secret)") | ||
internal class SecretValues { | ||
val trailName: String? = null | ||
val s3BucketName: String? = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
{ | ||
"Version": "2020-12-01", | ||
"Metadata": {}, | ||
"Parameters": [ | ||
{ | ||
"Name": "parameter_execution_role", | ||
"Type": "String", | ||
"DefaultValue": "" | ||
}, | ||
{ | ||
"Name": "parameter_region", | ||
"Type": "String", | ||
"DefaultValue": "us-west-2" | ||
}, | ||
{ | ||
"Name": "parameter_queue_url", | ||
"Type": "String", | ||
"DefaultValue": "" | ||
}, | ||
{ | ||
"Name": "parameter_vej_input_config", | ||
"Type": "String", | ||
"DefaultValue": "" | ||
}, | ||
{ | ||
"Name": "parameter_vej_export_config", | ||
"Type": "String", | ||
"DefaultValue": "" | ||
}, | ||
{ | ||
"Name": "parameter_step_1_vej_config", | ||
"Type": "String", | ||
"DefaultValue": "" | ||
} | ||
], | ||
"PipelineExperimentConfig": { | ||
"ExperimentName": { | ||
"Get": "Execution.PipelineName" | ||
}, | ||
"TrialName": { | ||
"Get": "Execution.PipelineExecutionId" | ||
} | ||
}, | ||
"Steps": [ | ||
{ | ||
"Name": "vej-processing-step", | ||
"Type": "Lambda", | ||
"Arguments": { | ||
"role": { | ||
"Get": "Parameters.parameter_execution_role" | ||
}, | ||
"region": { | ||
"Get": "Parameters.parameter_region" | ||
}, | ||
"vej_input_config": { | ||
"Get": "Parameters.parameter_vej_input_config" | ||
}, | ||
"vej_config": { | ||
"Get": "Parameters.parameter_step_1_vej_config" | ||
}, | ||
"vej_name": "vej-pipeline-step-1" | ||
}, | ||
"FunctionArn": "*FUNCTION_ARN*", | ||
"OutputParameters": [ | ||
{ | ||
"OutputName": "statusCode", | ||
"OutputType": "String" | ||
}, | ||
{ | ||
"OutputName": "vej_arn", | ||
"OutputType": "String" | ||
} | ||
] | ||
}, | ||
{ | ||
"Name": "vej-callback-step", | ||
"Type": "Callback", | ||
"Arguments": { | ||
"role": { | ||
"Get": "Parameters.parameter_execution_role" | ||
}, | ||
"region": { | ||
"Get": "Parameters.parameter_region" | ||
}, | ||
"vej_arn": { | ||
"Get": "Steps.vej-processing-step.OutputParameters['vej_arn']" | ||
} | ||
}, | ||
"DependsOn": [ | ||
"vej-processing-step" | ||
], | ||
"SqsQueueUrl": { | ||
"Get": "Parameters.parameter_queue_url" | ||
}, | ||
"OutputParameters": [ | ||
{ | ||
"OutputName": "vej_status", | ||
"OutputType": "String" | ||
} | ||
] | ||
}, | ||
{ | ||
"Name": "export-vej-step", | ||
"Type": "Lambda", | ||
"Arguments": { | ||
"vej_arn": { | ||
"Get": "Steps.vej-processing-step.OutputParameters['vej_arn']" | ||
}, | ||
"role": { | ||
"Get": "Parameters.parameter_execution_role" | ||
}, | ||
"region": { | ||
"Get": "Parameters.parameter_region" | ||
}, | ||
"vej_export_config": { | ||
"Get": "Parameters.parameter_vej_export_config" | ||
} | ||
}, | ||
"DependsOn": [ | ||
"vej-callback-step" | ||
], | ||
"FunctionArn": "*FUNCTION_ARN*", | ||
"OutputParameters": [ | ||
{ | ||
"OutputName": "statusCode", | ||
"OutputType": "String" | ||
}, | ||
{ | ||
"OutputName": "vej_arn", | ||
"OutputType": "String" | ||
} | ||
] | ||
}, | ||
{ | ||
"Name": "export-vej-callback", | ||
"Type": "Callback", | ||
"Arguments": { | ||
"role": { | ||
"Get": "Parameters.parameter_execution_role" | ||
}, | ||
"region": { | ||
"Get": "Parameters.parameter_region" | ||
}, | ||
"vej_arn": { | ||
"Get": "Steps.export-vej-step.OutputParameters['vej_arn']" | ||
} | ||
}, | ||
"DependsOn": [ | ||
"export-vej-step" | ||
], | ||
"SqsQueueUrl": { | ||
"Get": "Parameters.parameter_queue_url" | ||
}, | ||
"OutputParameters": [ | ||
{ | ||
"OutputName": "statusJob", | ||
"OutputType": "String" | ||
} | ||
] | ||
} | ||
] | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,4 +73,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.