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.ui;

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

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

/** The Help menu: diagnostics, the browser health check, and removing the suite's own files. */
public final class HelpActionsTest {

    private static Path temp() {
        try { return Files.createTempDirectory("ot-help"); } catch (java.io.IOException e) { throw new java.io.UncheckedIOException(e); }
    }

    public void run() {
        Harness.suite("help actions");

        Harness.test("diagnostics name the build, the runtime and the memory, and nothing about the user", () -> {
            String d = HelpActions.diagnostics();
            Expect.isTrue(d.startsWith("Open Suite " + Main.VERSION), "build first: " + d);
            Expect.isTrue(d.contains("Java: " + System.getProperty("java.version")), "java");
            Expect.isTrue(d.contains("MB limit"), "memory");
            Expect.isFalse(d.contains(System.getProperty("user.name") + "@"), "no account");
        });

        Harness.test("the browser check fails what is missing and passes what is there", () -> {
            List<HelpActions.Check> none = HelpActions.browserHealth(null, null, false, false);
            Expect.equal(none.size(), 5, "five checks");
            for (HelpActions.Check c : none) Expect.isFalse(c.ok(), c.name());
            Path dir = temp();
            Path bin = dir.resolve("browser");
            try {
                Files.writeString(bin, "#!/bin/sh\n");
                bin.toFile().setExecutable(true);
            } catch (java.io.IOException e) { throw new java.io.UncheckedIOException(e); }
            List<HelpActions.Check> all = HelpActions.browserHealth(bin.toString(), "/somewhere/driver", true, true);
            for (HelpActions.Check c : all) Expect.isTrue(c.ok(), c.name());
            // Windows has no runnable mark to take away: any file there counts as runnable.
            if (bin.toFile().setExecutable(false) && !Files.isExecutable(bin))
                Expect.isFalse(HelpActions.browserHealth(bin.toString(), null, true, true).get(1).ok(), "found but not runnable");
        });

        Harness.test("cleaning removes the folder and everything in it, and only that", () -> {
            Path root = temp();
            Path keep = temp();
            try {
                Files.createDirectories(root.resolve("ca/deep"));
                Files.writeString(root.resolve("ca/deep/key"), "k");
                Files.writeString(root.resolve("settings"), "s");
                Files.writeString(keep.resolve("project"), "p");
                Expect.equal(HelpActions.deleteTree(root), 5, "two files and three folders");
                Expect.isFalse(Files.exists(root), "gone");
                Expect.isTrue(Files.exists(keep.resolve("project")), "the other folder is untouched");
                Expect.equal(HelpActions.deleteTree(root), 0, "nothing to do the second time");
            } catch (java.io.IOException e) { throw new java.io.UncheckedIOException(e); }
        });
    }
}