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.0 KB
Raw Blame
package opensuite.proxy;

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

import java.util.List;

/** The built-in browser's new tabs: which pages count as one, and how the browser is started for it. */
public final class NewTabPageTest {
    public static void run() {
        Harness.test("the browser's own new-tab page is told from any other page", () -> {
            Expect.isTrue(NewTabPage.isNewTab("chrome://newtab/"), "the new-tab address");
            Expect.isTrue(NewTabPage.isNewTab("chrome://new-tab-page/"), "and the page it resolves to");
            Expect.isTrue(!NewTabPage.isNewTab("http://opensuite/"), "the start page is left alone");
            Expect.isTrue(!NewTabPage.isNewTab("https://example.com/chrome://newtab/"), "as is a site that only mentions it");
            Expect.isTrue(!NewTabPage.isNewTab(null), "and nothing at all");
        });
        Harness.test("the browser is started with a private channel and its own arguments unchanged", () -> {
            List<String> w = NewTabPage.wrapped(List.of("/opt/browser", "--flag", "http://opensuite/"));
            Expect.equal(w.get(0), "/bin/sh", "through the shell, which opens the pipes");
            Expect.equal(w.get(4), "/opt/browser", "the browser itself");
            Expect.equal(w.get(5), "--remote-debugging-pipe", "a pipe, never a network port");
            Expect.equal(w.get(w.size() - 1), "http://opensuite/", "the first page still last");
            for (String a : w) Expect.isTrue(!a.contains("remote-debugging-port"), "no port is opened");
        });
        Harness.test("a site's browser storage is read with which storage each name came from", () -> {
            java.util.Map<String, String> out = new java.util.LinkedHashMap<>();
            NewTabPage.readStorage("{\"l\":{\"token\":\"abc\"},\"s\":{\"bid\":\"7\"}}", out);
            Expect.equal(out.get("local:token"), "abc", "kept between visits");
            Expect.equal(out.get("session:bid"), "7", "kept for the tab");
            Expect.isTrue(NewTabPage.storageOf("http://app.example").isEmpty(), "nothing when no browser is open");
        });
        Harness.test("the crawl's browser is given what is missing and reloads once", () -> {
            java.util.Map<String, String> items = new java.util.LinkedHashMap<>();
            items.put("local:token", "a\"b");
            items.put("session:bid", "7");
            String js = opensuite.engine.CrawlWatch.seedScript(items);
            Expect.isTrue(js.contains("{\"token\":\"a\\\"b\"}"), "local items, safely quoted");
            Expect.isTrue(js.contains("{\"bid\":\"7\"}"), "session items apart");
            Expect.isTrue(js.contains("getItem(k)===null") && js.contains("location.reload()"), "only what is missing, then one reload");
            Expect.equal(opensuite.engine.CrawlWatch.siteOf("http://127.0.0.1:8396/a?b"), "http://127.0.0.1:8396", "a page's site");
            Expect.equal(opensuite.engine.CrawlWatch.siteOf("https://app.example/x"), "https://app.example", "the usual port left out");
        });
    }
}