Skip to content

Whitespace and import cleanup on tests #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,6 @@
*/
package com.amazonaws.services.dynamodbv2.datamodeling;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.nio.ByteBuffer;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.amazonaws.services.dynamodbv2.datamodeling.AttributeTransformer.Parameters;
import com.amazonaws.services.dynamodbv2.datamodeling.encryption.providers.EncryptionMaterialsProvider;
import com.amazonaws.services.dynamodbv2.datamodeling.encryption.providers.SymmetricStaticProvider;
Expand All @@ -58,6 +33,29 @@
import com.amazonaws.services.dynamodbv2.testing.types.UntouchedWithNewAttribute;
import com.amazonaws.services.dynamodbv2.testing.types.UntouchedWithUnknownAttributeAnnotation;
import com.amazonaws.services.dynamodbv2.testing.types.UntouchedWithUnknownAttributeAnnotationWithNewAttribute;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.nio.ByteBuffer;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class AttributeEncryptorTest {
private static final String RANGE_KEY = "rangeKey";
Expand All @@ -84,14 +82,14 @@ public static void setUpClass() throws Exception {
@Before
public void setUp() throws Exception {
prov = new SymmetricStaticProvider(encryptionKey, macKey,
Collections.<String, String> emptyMap());
Collections.<String, String>emptyMap());
encryptor = new AttributeEncryptor(prov);

attribs = new HashMap<String, AttributeValue>();
attribs.put("intValue", new AttributeValue().withN("123"));
attribs.put("stringValue", new AttributeValue().withS("Hello world!"));
attribs.put("byteArrayValue",
new AttributeValue().withB(ByteBuffer.wrap(new byte[] { 0, 1, 2, 3, 4, 5 })));
new AttributeValue().withB(ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5})));
attribs.put("stringSet", new AttributeValue().withSS("Goodbye", "Cruel", "World", "?"));
attribs.put("intSet", new AttributeValue().withNS("1", "200", "10", "15", "0"));
attribs.put(HASH_KEY, new AttributeValue().withN("5"));
Expand Down Expand Up @@ -132,7 +130,7 @@ public void fullEncryption() {
@Test(expected = DynamoDBMappingException.class)
public void rejectsPartialUpdate() {
Parameters<BaseClass> params = FakeParameters.getInstance(BaseClass.class, attribs, null,
TABLE_NAME, HASH_KEY, RANGE_KEY, true);
TABLE_NAME, HASH_KEY, RANGE_KEY, true);
encryptor.transform(params);
}

Expand Down Expand Up @@ -187,7 +185,7 @@ public void signedOnly() {

@Test
public void signedOnlyNullCryptoKey() {
prov = new SymmetricStaticProvider(null, macKey, Collections.<String, String> emptyMap());
prov = new SymmetricStaticProvider(null, macKey, Collections.<String, String>emptyMap());
encryptor = new AttributeEncryptor(prov);
Parameters<SignOnly> params = FakeParameters.getInstance(SignOnly.class, attribs, null,
TABLE_NAME, HASH_KEY, RANGE_KEY);
Expand Down Expand Up @@ -235,7 +233,7 @@ public void RsaSignedOnly() throws NoSuchAlgorithmException {
rsaGen.initialize(2048, Utils.getRng());
KeyPair sigPair = rsaGen.generateKeyPair();
encryptor = new AttributeEncryptor(new SymmetricStaticProvider(encryptionKey, sigPair,
Collections.<String, String> emptyMap()));
Collections.<String, String>emptyMap()));

Parameters<SignOnly> params = FakeParameters.getInstance(SignOnly.class, attribs, null,
TABLE_NAME, HASH_KEY, RANGE_KEY);
Expand All @@ -261,7 +259,7 @@ public void RsaSignedOnlyBadSignature() throws NoSuchAlgorithmException {
rsaGen.initialize(2048, Utils.getRng());
KeyPair sigPair = rsaGen.generateKeyPair();
encryptor = new AttributeEncryptor(new SymmetricStaticProvider(encryptionKey, sigPair,
Collections.<String, String> emptyMap()));
Collections.<String, String>emptyMap()));
Parameters<SignOnly> params = FakeParameters.getInstance(SignOnly.class, attribs, null,
TABLE_NAME, HASH_KEY, RANGE_KEY);
Map<String, AttributeValue> encryptedAttributes = encryptor.transform(params);
Expand Down Expand Up @@ -321,7 +319,7 @@ public void mixedBadSignature() {
@Test(expected = DynamoDBMappingException.class)
public void tableNameRespected() {
Parameters<BaseClass> params = FakeParameters.getInstance(BaseClass.class, attribs, null, "firstTable",
HASH_KEY, RANGE_KEY);
HASH_KEY, RANGE_KEY);
Map<String, AttributeValue> encryptedAttributes = encryptor.transform(params);
assertThat(encryptedAttributes, AttrMatcher.invert(attribs));
params = FakeParameters.getInstance(BaseClass.class, encryptedAttributes, null, "secondTable",
Expand All @@ -332,7 +330,7 @@ public void tableNameRespected() {
@Test
public void tableNameOverridden() {
Parameters<TableOverride> params = FakeParameters.getInstance(TableOverride.class, attribs, null, "firstTable",
HASH_KEY, RANGE_KEY);
HASH_KEY, RANGE_KEY);
Map<String, AttributeValue> encryptedAttributes = encryptor.transform(params);
assertThat(encryptedAttributes, AttrMatcher.invert(attribs));
params = FakeParameters.getInstance(TableOverride.class, encryptedAttributes, null, "secondTable",
Expand All @@ -341,7 +339,7 @@ public void tableNameOverridden() {
Map<String, AttributeValue> decryptedAttributes = encryptor.untransform(params);
assertThat(decryptedAttributes, AttrMatcher.match(attribs));
}

@Test(expected = DynamoDBMappingException.class)
public void testUnknownAttributeFails() {
Map<String, AttributeValue> attributes = new HashMap<>(attribs);
Expand Down Expand Up @@ -403,7 +401,7 @@ public void testSignOnlyWithUnknownAttributeAnnotation() {
Map<String, AttributeValue> decryptedAttributes = encryptor.untransform(params);
assertThat(decryptedAttributes, AttrMatcher.match(attributes));
}

@Test(expected = DynamoDBMappingException.class)
public void testSignOnlyWithUnknownAttributeAnnotationBadSignature() {
Map<String, AttributeValue> attributes = new HashMap<>(attribs);
Expand Down Expand Up @@ -436,7 +434,7 @@ public void testEncryptWithUnknownAttributeAnnotation() {
Map<String, AttributeValue> decryptedAttributes = encryptor.untransform(params);
assertThat(decryptedAttributes, AttrMatcher.match(attributes));
}

@Test(expected = DynamoDBMappingException.class)
public void testEncryptWithUnknownAttributeAnnotationBadSignature() {
Map<String, AttributeValue> attributes = new HashMap<>(attribs);
Expand Down
Loading