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.3 KB
Raw Blame
package opensuite.ui;

import opensuite.core.HttpService;
import opensuite.core.Issue;
import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

/** Settings > Display > Issues: grouped or ungrouped evidence, and whether a group is listed in full. */
public final class AdvisoryEvidenceTest {

    private static Issue issue(int places) {
        Issue i = Issue.builder("Reflected input").medium().service(new HttpService("a.test", 443, true))
                .path("/p0").evidence("<b>seen</b>").build();
        for (int n = 1; n < places; n++) i.addLocation("/p" + n, "");
        return i;
    }

    private static int count(String text, String part) {
        int n = 0;
        for (int at = text.indexOf(part); at >= 0; at = text.indexOf(part, at + part.length())) n++;
        return n;
    }

    public void run() {
        Harness.suite("advisory evidence layout");

        Harness.test("grouped and not expanded lists the first few places and counts the rest", () -> {
            String html = Advisory.render(issue(8), true, true, false);
            Expect.isTrue(html.contains("Affected locations (8)"), "one group");
            Expect.equal(count(html, "<li>"), Advisory.COLLAPSED, "listed");
            Expect.isTrue(html.contains("and 3 more"), "the rest counted");
            Expect.equal(count(html, "<h3>Evidence</h3>"), 1, "one evidence block");
        });

        Harness.test("grouped and expanded lists every place", () -> {
            String html = Advisory.render(issue(8), true, true, true);
            Expect.equal(count(html, "<li>"), 8, "all listed");
            Expect.isFalse(html.contains(" more."), "nothing left out");
        });

        Harness.test("ungrouped gives each place an item of its own", () -> {
            String html = Advisory.render(issue(3), true, false, false);
            Expect.isFalse(html.contains("Affected locations"), "no group");
            for (int n = 1; n <= 3; n++) Expect.isTrue(html.contains("<h3>Evidence " + n + "</h3>"), "item " + n);
            Expect.equal(count(html, "&lt;b&gt;seen&lt;/b&gt;"), 1, "the evidence text once, escaped");
        });

        Harness.test("an issue at one place reads the same either way", () -> {
            Expect.equal(Advisory.render(issue(1), true, false, false), Advisory.render(issue(1), true, true, true), "same");
        });
    }
}