14
14
*/
15
15
package com .amazonaws .services .dynamodbv2 .datamodeling ;
16
16
17
- import static org .junit .Assert .assertEquals ;
18
- import static org .junit .Assert .assertNotNull ;
19
- import static org .junit .Assert .assertNull ;
20
- import static org .junit .Assert .assertThat ;
21
- import static org .junit .Assert .assertTrue ;
22
-
23
- import java .nio .ByteBuffer ;
24
- import java .security .KeyPair ;
25
- import java .security .KeyPairGenerator ;
26
- import java .security .NoSuchAlgorithmException ;
27
- import java .util .Collection ;
28
- import java .util .Collections ;
29
- import java .util .HashMap ;
30
- import java .util .HashSet ;
31
- import java .util .Map ;
32
- import java .util .Set ;
33
-
34
- import javax .crypto .KeyGenerator ;
35
- import javax .crypto .SecretKey ;
36
-
37
- import org .junit .Assert ;
38
- import org .junit .Before ;
39
- import org .junit .BeforeClass ;
40
- import org .junit .Test ;
41
-
42
17
import com .amazonaws .services .dynamodbv2 .datamodeling .AttributeTransformer .Parameters ;
43
18
import com .amazonaws .services .dynamodbv2 .datamodeling .encryption .providers .EncryptionMaterialsProvider ;
44
19
import com .amazonaws .services .dynamodbv2 .datamodeling .encryption .providers .SymmetricStaticProvider ;
58
33
import com .amazonaws .services .dynamodbv2 .testing .types .UntouchedWithNewAttribute ;
59
34
import com .amazonaws .services .dynamodbv2 .testing .types .UntouchedWithUnknownAttributeAnnotation ;
60
35
import com .amazonaws .services .dynamodbv2 .testing .types .UntouchedWithUnknownAttributeAnnotationWithNewAttribute ;
36
+ import org .junit .Assert ;
37
+ import org .junit .Before ;
38
+ import org .junit .BeforeClass ;
39
+ import org .junit .Test ;
40
+
41
+ import javax .crypto .KeyGenerator ;
42
+ import javax .crypto .SecretKey ;
43
+ import java .nio .ByteBuffer ;
44
+ import java .security .KeyPair ;
45
+ import java .security .KeyPairGenerator ;
46
+ import java .security .NoSuchAlgorithmException ;
47
+ import java .util .Collection ;
48
+ import java .util .Collections ;
49
+ import java .util .HashMap ;
50
+ import java .util .HashSet ;
51
+ import java .util .Map ;
52
+ import java .util .Set ;
53
+
54
+ import static org .junit .Assert .assertEquals ;
55
+ import static org .junit .Assert .assertNotNull ;
56
+ import static org .junit .Assert .assertNull ;
57
+ import static org .junit .Assert .assertThat ;
58
+ import static org .junit .Assert .assertTrue ;
61
59
62
60
public class AttributeEncryptorTest {
63
61
private static final String RANGE_KEY = "rangeKey" ;
@@ -84,14 +82,14 @@ public static void setUpClass() throws Exception {
84
82
@ Before
85
83
public void setUp () throws Exception {
86
84
prov = new SymmetricStaticProvider (encryptionKey , macKey ,
87
- Collections .<String , String > emptyMap ());
85
+ Collections .<String , String >emptyMap ());
88
86
encryptor = new AttributeEncryptor (prov );
89
87
90
88
attribs = new HashMap <String , AttributeValue >();
91
89
attribs .put ("intValue" , new AttributeValue ().withN ("123" ));
92
90
attribs .put ("stringValue" , new AttributeValue ().withS ("Hello world!" ));
93
91
attribs .put ("byteArrayValue" ,
94
- new AttributeValue ().withB (ByteBuffer .wrap (new byte [] { 0 , 1 , 2 , 3 , 4 , 5 })));
92
+ new AttributeValue ().withB (ByteBuffer .wrap (new byte []{ 0 , 1 , 2 , 3 , 4 , 5 })));
95
93
attribs .put ("stringSet" , new AttributeValue ().withSS ("Goodbye" , "Cruel" , "World" , "?" ));
96
94
attribs .put ("intSet" , new AttributeValue ().withNS ("1" , "200" , "10" , "15" , "0" ));
97
95
attribs .put (HASH_KEY , new AttributeValue ().withN ("5" ));
@@ -132,7 +130,7 @@ public void fullEncryption() {
132
130
@ Test (expected = DynamoDBMappingException .class )
133
131
public void rejectsPartialUpdate () {
134
132
Parameters <BaseClass > params = FakeParameters .getInstance (BaseClass .class , attribs , null ,
135
- TABLE_NAME , HASH_KEY , RANGE_KEY , true );
133
+ TABLE_NAME , HASH_KEY , RANGE_KEY , true );
136
134
encryptor .transform (params );
137
135
}
138
136
@@ -187,7 +185,7 @@ public void signedOnly() {
187
185
188
186
@ Test
189
187
public void signedOnlyNullCryptoKey () {
190
- prov = new SymmetricStaticProvider (null , macKey , Collections .<String , String > emptyMap ());
188
+ prov = new SymmetricStaticProvider (null , macKey , Collections .<String , String >emptyMap ());
191
189
encryptor = new AttributeEncryptor (prov );
192
190
Parameters <SignOnly > params = FakeParameters .getInstance (SignOnly .class , attribs , null ,
193
191
TABLE_NAME , HASH_KEY , RANGE_KEY );
@@ -235,7 +233,7 @@ public void RsaSignedOnly() throws NoSuchAlgorithmException {
235
233
rsaGen .initialize (2048 , Utils .getRng ());
236
234
KeyPair sigPair = rsaGen .generateKeyPair ();
237
235
encryptor = new AttributeEncryptor (new SymmetricStaticProvider (encryptionKey , sigPair ,
238
- Collections .<String , String > emptyMap ()));
236
+ Collections .<String , String >emptyMap ()));
239
237
240
238
Parameters <SignOnly > params = FakeParameters .getInstance (SignOnly .class , attribs , null ,
241
239
TABLE_NAME , HASH_KEY , RANGE_KEY );
@@ -261,7 +259,7 @@ public void RsaSignedOnlyBadSignature() throws NoSuchAlgorithmException {
261
259
rsaGen .initialize (2048 , Utils .getRng ());
262
260
KeyPair sigPair = rsaGen .generateKeyPair ();
263
261
encryptor = new AttributeEncryptor (new SymmetricStaticProvider (encryptionKey , sigPair ,
264
- Collections .<String , String > emptyMap ()));
262
+ Collections .<String , String >emptyMap ()));
265
263
Parameters <SignOnly > params = FakeParameters .getInstance (SignOnly .class , attribs , null ,
266
264
TABLE_NAME , HASH_KEY , RANGE_KEY );
267
265
Map <String , AttributeValue > encryptedAttributes = encryptor .transform (params );
@@ -321,7 +319,7 @@ public void mixedBadSignature() {
321
319
@ Test (expected = DynamoDBMappingException .class )
322
320
public void tableNameRespected () {
323
321
Parameters <BaseClass > params = FakeParameters .getInstance (BaseClass .class , attribs , null , "firstTable" ,
324
- HASH_KEY , RANGE_KEY );
322
+ HASH_KEY , RANGE_KEY );
325
323
Map <String , AttributeValue > encryptedAttributes = encryptor .transform (params );
326
324
assertThat (encryptedAttributes , AttrMatcher .invert (attribs ));
327
325
params = FakeParameters .getInstance (BaseClass .class , encryptedAttributes , null , "secondTable" ,
@@ -332,7 +330,7 @@ public void tableNameRespected() {
332
330
@ Test
333
331
public void tableNameOverridden () {
334
332
Parameters <TableOverride > params = FakeParameters .getInstance (TableOverride .class , attribs , null , "firstTable" ,
335
- HASH_KEY , RANGE_KEY );
333
+ HASH_KEY , RANGE_KEY );
336
334
Map <String , AttributeValue > encryptedAttributes = encryptor .transform (params );
337
335
assertThat (encryptedAttributes , AttrMatcher .invert (attribs ));
338
336
params = FakeParameters .getInstance (TableOverride .class , encryptedAttributes , null , "secondTable" ,
@@ -341,7 +339,7 @@ public void tableNameOverridden() {
341
339
Map <String , AttributeValue > decryptedAttributes = encryptor .untransform (params );
342
340
assertThat (decryptedAttributes , AttrMatcher .match (attribs ));
343
341
}
344
-
342
+
345
343
@ Test (expected = DynamoDBMappingException .class )
346
344
public void testUnknownAttributeFails () {
347
345
Map <String , AttributeValue > attributes = new HashMap <>(attribs );
@@ -403,7 +401,7 @@ public void testSignOnlyWithUnknownAttributeAnnotation() {
403
401
Map <String , AttributeValue > decryptedAttributes = encryptor .untransform (params );
404
402
assertThat (decryptedAttributes , AttrMatcher .match (attributes ));
405
403
}
406
-
404
+
407
405
@ Test (expected = DynamoDBMappingException .class )
408
406
public void testSignOnlyWithUnknownAttributeAnnotationBadSignature () {
409
407
Map <String , AttributeValue > attributes = new HashMap <>(attribs );
@@ -436,7 +434,7 @@ public void testEncryptWithUnknownAttributeAnnotation() {
436
434
Map <String , AttributeValue > decryptedAttributes = encryptor .untransform (params );
437
435
assertThat (decryptedAttributes , AttrMatcher .match (attributes ));
438
436
}
439
-
437
+
440
438
@ Test (expected = DynamoDBMappingException .class )
441
439
public void testEncryptWithUnknownAttributeAnnotationBadSignature () {
442
440
Map <String , AttributeValue > attributes = new HashMap <>(attribs );
0 commit comments