package com.github.mlk.junit.rules;

import com.amazonaws.services.dynamodbv2.local.main.ServerRunner;
import com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer;
import java.util.regex.Pattern;
import org.junit.rules.ExternalResource;

/** Runs a DynamoDB server exposed over HTTP.
 * It handles all the SQLite native libraries stuff for you.
 *
 * Heavily inspired by the answers here: https://stackoverflow.com/questions/26901613/easier-dynamodb-local-testing
 */
public class HttpDynamoDbRule extends ExternalResource {
  private NativeLibraryRule nativeLibraryRule;
  private DynamoDBProxyServer server;
  private final int defaultPort;
  private int port;

  public HttpDynamoDbRule() {
    this(-1);
  }

  public HttpDynamoDbRule(int defaultPort) {
    this.defaultPort = defaultPort;
    nativeLibraryRule = new NativeLibraryRule(Pattern.compile(".*sqlite.*"));
  }

  @Override
  protected void before() throws Throwable {
    nativeLibraryRule.before();
    System.setProperty("sqlite4java.library.path", nativeLibraryRule.getNativeLibrariesFolder().toString());

    if(defaultPort > -1) {
      port = defaultPort;
    } else {
      port = Helper.findRandomOpenPortOnAllLocalInterfaces();
    }


    final String[] localArgs = { "-inMemory", "-port", Integer.toString(port) };
    server = ServerRunner.createServerFromCommandLineArgs(localArgs);
    server.start();
  }

  @Override
  protected void after() {
    try {
      server.stop();
    } catch (Exception e) {
      e.printStackTrace();
    }

    nativeLibraryRule.after();
  }

  public int getPort() {
    return port;
  }

  public String getEndpoint() {
    return "http://localhost:" + getPort();
  }
}

@@ -650,16 +650,54 @@
 ltPort;%0A
+  private final boolean useFakeCreds;%0A
   privat
@@ -750,16 +750,22 @@
  this(-1
+, true
 );%0A  %7D%0A%0A
@@ -805,16 +805,38 @@
 aultPort
+, boolean useFakeCreds
 ) %7B%0A    
@@ -863,24 +863,62 @@
 efaultPort;%0A
+    this.useFakeCreds = useFakeCreds;%0A
     nativeLi
@@ -1187,16 +1187,145 @@
 ng());%0A%0A
+    if (useFakeCreds) %7B%0A      System.setProperty(%22aws.accessKeyId%22, %22x%22);%0A      System.setProperty(%22aws.secretKey%22, %22x%22);%0A    %7D%0A%0A
     if(d

Support for setting fake AWS creds