Search in sources :

Example 6 with Process2

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();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) OtpProvider(com.predic8.membrane.core.interceptor.authentication.session.totp.OtpProvider) Test(org.junit.Test)

Example 7 with Process2

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();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) Test(org.junit.Test)

Example 8 with Process2

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();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 9 with Process2

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();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Example 10 with Process2

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();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Aggregations

Process2 (com.predic8.membrane.examples.Process2)37 Test (org.junit.Test)36 File (java.io.File)30 BufferLogger (com.predic8.membrane.examples.util.BufferLogger)4 SubstringWaitableConsoleEvent (com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent)4 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)3 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)3 AssertUtils.replaceInFile (com.predic8.membrane.test.AssertUtils.replaceInFile)2 OtpProvider (com.predic8.membrane.core.interceptor.authentication.session.totp.OtpProvider)1 FilenameFilter (java.io.FilenameFilter)1 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)1