Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

3.1 KB
Raw Blame
package opensuite.engine;

import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

import java.util.List;

/** What Open Suite writes for the engine's gate to read: the sites to hold and the time to hold them until. */
public final class ScanGateTest {

    public void run() {
        Harness.suite("scan gate");

        // The engine's memory limit follows the machine, as its own launcher does, within bounds.
        Harness.test("the engine's memory limit is a quarter of the machine, between 512 MB and 4 GB", () -> {
            Expect.isTrue(ZapEngine.javaOptions(8192).contains("-Xmx2048m"), "8 GB machine: 2 GB");
            Expect.isTrue(ZapEngine.javaOptions(65536).contains("-Xmx4096m"), "64 GB machine: capped at 4 GB");
            Expect.isTrue(ZapEngine.javaOptions(1024).contains("-Xmx512m"), "1 GB machine: 512 MB");
            Expect.isTrue(ZapEngine.javaOptions(0).contains("-Xmx2048m"), "unknown machine: 2 GB");
        });

        Harness.test("sites are written as host and port, the usual port filled in", () -> {
            Expect.equal(ScanGate.sitesValue(List.of("http://127.0.0.1:8394", "https://app.test", "http://api.test")),
                    "127.0.0.1:8394 app.test:443 api.test:80", "sites");
        });

        Harness.test("a site named twice is held once", () -> {
            Expect.equal(ScanGate.sitesValue(List.of("https://app.test", "https://app.test:443")), "app.test:443", "sites");
        });

        Harness.test("a hold is its time, then its sites", () -> {
            Expect.equal(ScanGate.value(1700000000000L, "app.test:443 api.test:80"), "1700000000000 app.test:443 api.test:80", "value");
        });

        Harness.test("a scan can tell that another scan is holding its site", () -> {
            // Port 9 on this machine refuses at once: the hold is kept here whether or not the engine can be told.
            ZapApi nowhere = new ZapApi("http://127.0.0.1:9", "none");
            ScanGate.hold(nowhere, 987001, List.of("http://app.test:3000"));
            try {
                Expect.equal(ScanGate.heldByOther(987002, List.of("http://app.test:3000")), Integer.valueOf(987001), "the same site");
                Expect.equal(ScanGate.heldByOther(987002, List.of("http://other.test", "http://app.test:3000/")), Integer.valueOf(987001), "one of several");
                Expect.isTrue(ScanGate.heldByOther(987002, List.of("http://app.test:3001")) == null, "another port is another site");
                Expect.isTrue(ScanGate.heldByOther(987001, List.of("http://app.test:3000")) == null, "its own hold is not another's");
            } finally {
                ScanGate.release(nowhere, 987001);
            }
            Expect.isTrue(ScanGate.heldByOther(987002, List.of("http://app.test:3000")) == null, "let go");
        });

        Harness.test("a task that was never held is not holding, and letting it go does nothing", () -> {
            Expect.isTrue(!ScanGate.holding(987654), "not holding");
            ScanGate.release(null, 987654);
            Expect.isTrue(!ScanGate.holding(987654), "still not holding");
        });
    }
}