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.

2.6 KB
Raw Blame
package opensuite.core;

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

import java.util.List;

/** A task's log lines each carry the time they were logged, and keep it through a saved project. */
public final class ScanTaskEventsTest {

    public void run() {
        Harness.suite("task event times");

        Harness.test("each line has its own time, in order", () -> {
            ScanTask t = new ScanTask(ScanTask.Type.AUDIT, "t", "c");
            long before = System.currentTimeMillis();
            t.log("one");
            try { Thread.sleep(15); } catch (InterruptedException ignore) { }
            t.log("two");
            List<ScanTask.Event> ev = t.events();
            Expect.equal(ev.size(), 2, "two lines");
            Expect.equal(ev.get(1).line(), "two", "second line");
            Expect.isTrue(ev.get(0).at() >= before, "first is timed when it was logged");
            Expect.isTrue(ev.get(1).at() > ev.get(0).at(), "second is later than first");
        });

        Harness.test("times survive a saved project", () -> {
            ScanTask t = new ScanTask(ScanTask.Type.AUDIT, "t", "c");
            t.log("one");
            try { Thread.sleep(15); } catch (InterruptedException ignore) { }
            t.log("two");
            List<ScanTask.Event> was = t.events();
            List<ScanTask.Event> back = ScanTask.fromSnapshot(t.snapshot()).events();
            Expect.equal(back.get(0).at(), was.get(0).at(), "first time kept");
            Expect.equal(back.get(1).at(), was.get(1).at(), "second time kept");
        });

        Harness.test("a project saved without times gives its lines the task's start", () -> {
            ScanTask t = new ScanTask(ScanTask.Type.AUDIT, "t", "c");
            t.log("one");
            ScanTask.Snapshot s = t.snapshot();
            ScanTask.Snapshot old = new ScanTask.Snapshot(s.number(), s.type(), s.title(), s.configuration(), s.scope(),
                    s.high(), s.medium(), s.low(), s.info(), s.requests(), s.itemsTotal(), s.itemsDone(),
                    s.discoveredLocations(), s.auditItemsTotal(), 12345L, s.lastShot(), s.log(), null, null, null);
            Expect.equal(ScanTask.fromSnapshot(old).events().get(0).at(), 12345L, "the task's start");
        });

        Harness.test("the log keeps its newest 500 lines and their times", () -> {
            ScanTask t = new ScanTask(ScanTask.Type.AUDIT, "t", "c");
            for (int i = 0; i < 520; i++) t.log("line " + i);
            List<ScanTask.Event> ev = t.events();
            Expect.equal(ev.size(), 500, "capped");
            Expect.equal(ev.get(0).line(), "line 20", "oldest kept");
        });
    }
}