use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.
the class LoginTest method test.
@Test
public void test() throws IOException, InterruptedException {
Process2 sl = new Process2.Builder().in(getExampleDir("login")).script("service-proxy").waitForMembrane().start();
try {
String form = AssertUtils.getAndAssert200("http://localhost:2000/");
AssertUtils.assertContains("Username:", form);
AssertUtils.assertContains("Password:", form);
form = AssertUtils.postAndAssert(200, "http://localhost:2000/login/", new String[] { "Content-Type", "application/x-www-form-urlencoded" }, "username=john&password=password");
AssertUtils.assertContains("token:", form);
String token = new OtpProvider().getNextCode("abcdefghijklmnop", System.currentTimeMillis());
form = AssertUtils.postAndAssert(200, "http://localhost:2000/login/", new String[] { "Content-Type", "application/x-www-form-urlencoded" }, "token=" + token);
// successful login?
AssertUtils.assertContains("This page has moved to", form);
// access the "protected" page
form = AssertUtils.getAndAssert200("http://localhost:2000/");
AssertUtils.assertContains("predic8.com", form);
// logout
form = AssertUtils.getAndAssert200("http://localhost:2000/login/logout");
AssertUtils.assertContains("Username:", form);
} finally {
sl.killScript();
}
}
use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.
the class RateLimiterTest method test.
@Test
public void test() throws IOException, InterruptedException {
Process2 sl = new Process2.Builder().in(getExampleDir("rateLimiter")).script("service-proxy").waitForMembrane().start();
try {
AssertUtils.getAndAssert200("http://localhost:2000/");
AssertUtils.getAndAssert200("http://localhost:2000/");
AssertUtils.getAndAssert200("http://localhost:2000/");
AssertUtils.getAndAssert(429, "http://localhost:2000/");
} finally {
sl.killScript();
}
}
use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.
the class ThrottleTest method test.
@Test
public void test() throws IOException, InterruptedException {
File baseDir = getExampleDir("throttle");
Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
try {
getAndAssert200("http://localhost:2000/");
long start = System.currentTimeMillis();
getAndAssert200("http://localhost:2000/");
long elapsedMillis = System.currentTimeMillis() - start;
Assert.assertTrue(elapsedMillis >= 1000);
} finally {
sl.killScript();
}
}
use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.
the class SSLClient method test.
@Test
public void test() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyManagementException {
File baseDir = getExampleDir("ssl-client");
AssertUtils.replaceInFile(new File(baseDir, "proxies.xml"), "8080", "3023");
Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
try {
AssertUtils.assertContains("<title>Google", getAndAssert200("http://localhost:3023/"));
} finally {
sl.killScript();
}
}
use of com.predic8.membrane.examples.Process2 in project service-proxy by membrane.
the class JSONSchemaValidationTest method test.
@Test
public void test() throws IOException, InterruptedException {
File baseDir = getExampleDir("validation" + File.separator + "json-schema");
Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
try {
for (int port : new int[] { 2000, 2001 }) {
postAndAssert(200, "http://localhost:" + port + "/", readFileToString(new File(baseDir, "good" + port + ".json")));
postAndAssert(400, "http://localhost:" + port + "/", readFileToString(new File(baseDir, "bad" + port + ".json")));
}
} finally {
sl.killScript();
}
}
Aggregations