Skip to content
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
1 change: 1 addition & 0 deletions DynamoDbEncryption/runtimes/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ dependencies {

// For the DDB-EC with SDK v1
compileOnly("com.amazonaws:aws-java-sdk-dynamodb:1.12.780")

// For the DDB-EC with SDK V2
implementation("io.netty:netty-common:4.2.9.Final")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.stream.Collectors;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -349,6 +350,14 @@ public void decryptWithECConfigTest()
);
}

@AfterTest
public void tearDownDDBLocal() {
if (client != null) {
client.shutdown();
client = null;
}
}

@Test(dataProvider = "getDecryptTestVectors")
public void decryptTestVector(Scenario scenario) throws IOException {
client = DynamoDBEmbedded.create().amazonDynamoDB();
Expand Down Expand Up @@ -1583,6 +1592,9 @@ private static String stripFilePath(String path) {
return path.replaceFirst("file://", "");
}

@JsonDeserialize(using = AttributeValueDeserializer.class)
public static class DeserializedAttributeValue extends AttributeValue {}
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(
using = AttributeValueDeserializer.class
)
public static class DeserializedAttributeValue
extends com.amazonaws.services.dynamodbv2.model.AttributeValue {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import java.util.Map;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

Expand All @@ -47,30 +50,48 @@ public class CachingMostRecentProviderTests {
private static final DynamoDBEncryptor ENCRYPTOR =
DynamoDBEncryptor.getInstance(BASE_PROVIDER);

private AmazonDynamoDB client;
private Map<String, Integer> methodCalls;
private static AmazonDynamoDB rawClient;
private static AmazonDynamoDB instrumentedClient;
private static Map<String, Integer> methodCalls;
private ProviderStore store;
private EncryptionContext ctx;

// DDB Local client is created once per class since DynamoDBEmbedded.create() is expensive.
// Table is created/deleted per method to ensure test isolation, as tests assert
// exact DynamoDB call counts and expect a clean table with no leftover data.
@BeforeClass
public static void setupClient() {
methodCalls = new HashMap<String, Integer>();
rawClient = DynamoDBEmbedded.create().amazonDynamoDB();
instrumentedClient =
instrument(rawClient, AmazonDynamoDB.class, methodCalls);
}

@AfterClass
public static void tearDownDDBLocal() {
if (rawClient != null) {
rawClient.shutdown();
rawClient = null;
}
}

@BeforeMethod
public void setup() {
methodCalls = new HashMap<String, Integer>();
client =
instrument(
DynamoDBEmbedded.create().amazonDynamoDB(),
AmazonDynamoDB.class,
methodCalls
);
MetaStore.createTable(
client,
instrumentedClient,
TABLE_NAME,
new ProvisionedThroughput(1L, 1L)
);
store = new MetaStore(client, TABLE_NAME, ENCRYPTOR);
store = new MetaStore(instrumentedClient, TABLE_NAME, ENCRYPTOR);
ctx = new EncryptionContext.Builder().build();
methodCalls.clear();
}

@AfterMethod
public void tearDown() {
rawClient.deleteTable(TABLE_NAME);
}

@Test
public void testConstructors() {
final CachingMostRecentProvider prov = new CachingMostRecentProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.testng.annotations.AfterClass;

public class DynamoDBTestBase {

Expand All @@ -30,6 +31,14 @@ public static void setUpTestBase() {
dynamo = DynamoDBEmbedded.create().amazonDynamoDB();
}

@AfterClass
public static void tearDownDDBLocal() {
if (dynamo != null) {
dynamo.shutdown();
dynamo = null;
}
}

public static AmazonDynamoDB getClient() {
if (dynamo == null) {
setUpTestBase();
Expand Down
Loading