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.testkit.Expect;
import opensuite.testkit.Harness;

import java.util.List;

/** Settings > Message editor: how the editor's search reads its term, and what a selection decodes to on hover. */
public final class EditorSearchTest {

    private static String spans(List<int[]> found) {
        StringBuilder sb = new StringBuilder();
        for (int[] m : found) sb.append(m[0]).append('-').append(m[1]).append(' ');
        return sb.toString().trim();
    }

    public void run() {
        Harness.suite("editor search and hover decode");

        Harness.test("a plain term is found with or without regard to case", () -> {
            Expect.equal(spans(MessageEditor.findAll("Host: host HOST", "host", false, false)), "0-4 6-10 11-15", "any case");
            Expect.equal(spans(MessageEditor.findAll("Host: host HOST", "host", true, false)), "6-10", "exact case");
            Expect.equal(spans(MessageEditor.findAll("aaa", "aa", true, false)), "0-2 1-3", "overlapping");
            Expect.isTrue(MessageEditor.findAll("abc", "", false, false).isEmpty(), "no term");
        });

        Harness.test("a regex finds its matches and a broken one finds nothing", () -> {
            Expect.equal(spans(MessageEditor.findAll("id=12&uid=345", "\\d+", false, true)), "3-5 10-13", "digits");
            Expect.equal(spans(MessageEditor.findAll("a.b", "a.b", false, false)), "0-3", "a plain dot is a dot");
            Expect.isTrue(MessageEditor.findAll("abc", "(", false, true).isEmpty(), "will not compile");
            Expect.isTrue(MessageEditor.findAll("abc", "x*", false, true).isEmpty(), "matches nothing at all, and ends");
        });

        Harness.test("a selection decodes from URL, entity and Base64 forms", () -> {
            Expect.equal(MessageEditor.hoverDecode("a%20b%3Dc"), "a b=c", "URL");
            Expect.equal(MessageEditor.hoverDecode("&lt;b&gt;"), "<b>", "entities");
            Expect.equal(MessageEditor.hoverDecode("aGVsbG8gd29ybGQ="), "hello world", "Base64");
            Expect.isNull(MessageEditor.hoverDecode("plain words"), "already plain");
            Expect.isNull(MessageEditor.hoverDecode("ab"), "too short to mean anything");
            Expect.isNull(MessageEditor.hoverDecode(null), "nothing selected");
        });
    }
}