1
1
package org .testcontainers .containers .localstack ;
2
2
3
3
4
+ import com .amazonaws .services .kms .AWSKMS ;
5
+ import com .amazonaws .services .kms .AWSKMSClientBuilder ;
6
+ import com .amazonaws .services .kms .model .CreateKeyRequest ;
7
+ import com .amazonaws .services .kms .model .CreateKeyResult ;
8
+ import com .amazonaws .services .kms .model .Tag ;
4
9
import com .amazonaws .services .logs .AWSLogs ;
5
10
import com .amazonaws .services .logs .AWSLogsClientBuilder ;
6
11
import com .amazonaws .services .logs .model .CreateLogGroupRequest ;
38
43
import static org .rnorth .visibleassertions .VisibleAssertions .assertEquals ;
39
44
import static org .rnorth .visibleassertions .VisibleAssertions .assertThat ;
40
45
import static org .rnorth .visibleassertions .VisibleAssertions .assertTrue ;
41
- import static org .testcontainers .containers .localstack .LocalStackContainer .Service .S3 ;
42
- import static org .testcontainers .containers .localstack .LocalStackContainer .Service .SQS ;
43
- import static org .testcontainers .containers .localstack .LocalStackContainer .Service .CLOUDWATCHLOGS ;
46
+ import static org .testcontainers .containers .localstack .LocalStackContainer .Service .*;
44
47
45
48
/**
46
49
* Tests for Localstack Container, used both in bridge network (exposed to host) and docker network modes.
@@ -58,7 +61,7 @@ public static class WithoutNetwork {
58
61
// without_network {
59
62
@ ClassRule
60
63
public static LocalStackContainer localstack = new LocalStackContainer ()
61
- .withServices (S3 , SQS , CLOUDWATCHLOGS );
64
+ .withServices (S3 , SQS , CLOUDWATCHLOGS , KMS );
62
65
// }
63
66
64
67
@ Test
@@ -135,6 +138,21 @@ public void cloudWatchLogsTestOverBridgeNetwork() {
135
138
assertEquals ("One log group should be created" , 1 , groups .size ());
136
139
assertEquals ("Name of created log group is [foo]" , "foo" , groups .get (0 ).getLogGroupName ());
137
140
}
141
+
142
+ @ Test
143
+ public void kmsKeyCreationTest () {
144
+ AWSKMS awskms = AWSKMSClientBuilder .standard ()
145
+ .withEndpointConfiguration (localstack .getEndpointConfiguration (KMS ))
146
+ .withCredentials (localstack .getDefaultCredentialsProvider ())
147
+ .build ();
148
+
149
+ String desc = String .format ("AWS CMK Description" );
150
+ Tag createdByTag = new Tag ().withTagKey ("CreatedBy" ).withTagValue ("StorageService" );
151
+ CreateKeyRequest req = new CreateKeyRequest ().withDescription (desc ).withTags (createdByTag );
152
+ CreateKeyResult key = awskms .createKey (req );
153
+
154
+ assertEquals ("AWS KMS Customer Managed Key should be created " , key .getKeyMetadata ().getDescription (), desc );
155
+ }
138
156
}
139
157
140
158
public static class WithNetwork {
0 commit comments