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.

4.7 KB
Raw Blame
package opensuite.ui;

import opensuite.core.Settings;
import opensuite.core.SuiteContext;
import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

import java.util.LinkedHashMap;
import java.util.Map;

/** Settings > Suite > Startup behavior > Unrecognized project files. */
public final class ProjectTrustTest {

    public void run() {
        Harness.suite("project file trust");

        Harness.test("an untrusted file brings only what describes the project", () -> {
            Map<String, String> saved = new LinkedHashMap<>();
            saved.put("project.bodyCapKb", "64");
            saved.put("proxy.logOutOfScope", "false");
            saved.put("rest.running", "true");
            saved.put("rest.noKey", "true");
            saved.put("temp.dir", "/somewhere/else");
            saved.put("browser.binary", "/tmp/not-a-browser");
            saved.put("hotkey.Send to Repeater", "Ctrl+Q");
            Map<String, String> kept = StateIO.harmless(saved);
            Expect.isTrue(kept.size() == 2 && kept.containsKey("project.bodyCapKb") && kept.containsKey("proxy.logOutOfScope"), "kept " + kept.keySet());
        });

        Harness.test("a file is trusted when saved here, when trust is the default, or when the owner says so", () -> {
            SuiteContext ctx = new SuiteContext();
            Settings s = ctx.settings();
            String before = s.get(StateIO.INSTALL_ID, "");
            try {
                Map<String, String> foreign = new LinkedHashMap<>();
                foreign.put(StateIO.INSTALL_ID, "someone-else");
                Expect.isTrue(StateIO.trusted(ctx, foreign), "trusting is the default, as in the reference");
                s.setBool(StateIO.ALWAYS_TRUST, false);
                Expect.isTrue(!StateIO.trusted(ctx, foreign), "another installation's file");
                Expect.isTrue(!StateIO.trusted(ctx, new LinkedHashMap<>()), "a file with no mark at all");
                Map<String, String> ours = new LinkedHashMap<>();
                ours.put(StateIO.INSTALL_ID, StateIO.installId(s));
                Expect.isTrue(StateIO.trusted(ctx, ours), "our own file");
            } finally {
                s.remove(StateIO.ALWAYS_TRUST);
                if (before.isEmpty()) s.remove(StateIO.INSTALL_ID); else s.set(StateIO.INSTALL_ID, before);
                opensuite.core.HttpClient.setGate(null);
            }
        });

        Harness.test("a block travels with the project only while its override switch is on", () -> {
            java.util.Map<String, String> all = new java.util.LinkedHashMap<>();
            all.put("socks.host", "10.0.0.1");
            all.put("socks.overrideProject", "true");
            all.put("upstream.proxies", "a\tb");
            all.put("auth.platform.rows", "row");
            all.put("auth.overrideProject", "false");
            all.put("tls.client.rows", "cert");
            all.put("tls.min", "TLSv1.2");
            all.put("project.name", "p");
            java.util.Map<String, String> kept = StateIO.projectSettings(all);
            Expect.equal(kept.get("socks.host"), "10.0.0.1", "overridden block kept");
            Expect.isFalse(kept.containsKey("upstream.proxies"), "no switch: left out");
            Expect.isFalse(kept.containsKey("auth.platform.rows"), "switch off: left out");
            Expect.isFalse(kept.containsKey("tls.client.rows"), "client certificates left out");
            Expect.equal(kept.get("tls.min"), "TLSv1.2", "the rest of TLS is not an overridable block");
            Expect.equal(kept.get("project.name"), "p", "project settings kept");
            Expect.isTrue(StateIO.projectSettings(null).isEmpty(), "nothing in, nothing out");
        });

        Harness.test("extension settings stay with the computer, whatever else a project file carries", () -> {
            java.util.Map<String, String> all = new java.util.LinkedHashMap<>();
            all.put(opensuite.extensions.ExtensionLoader.JAVA_LIBS, "/home/someone/jars");
            all.put("ext.jython", "/home/someone/jython-standalone.jar");
            all.put("ext.reloadOnStartup", "true");
            all.put("project.name", "p");
            all.put("http.timeout", "30");
            java.util.Map<String, String> kept = StateIO.projectSettings(all);
            Expect.isFalse(kept.containsKey(opensuite.extensions.ExtensionLoader.JAVA_LIBS),
                    "the library folder is not written into a project file");
            Expect.isTrue(kept.keySet().stream().noneMatch(k -> k.startsWith("ext.")),
                    "nor any other extension setting: " + kept.keySet());
            Expect.equal(kept.get("project.name"), "p", "the project's own settings still travel");
            Expect.equal(kept.get("http.timeout"), "30", "and the suite's");
        });
    }
}