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

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

import java.io.File;
import java.util.List;

/**
 * A change of text size, scale or theme starts the application again. It asks first and says
 * what that costs, and a project in a file is opened again afterwards.
 */
public final class RestartTest {
    public void run() {
        Harness.suite("restart");

        Harness.test("the question says what the restart costs", () -> {
            String temp = Restart.cost("the new text size", true, true, false);
            Expect.isTrue(temp.contains("the new text size") && temp.contains("will be lost"), "a temporary project with work in it is lost: " + temp);
            Expect.isTrue(!Restart.cost("x", true, false, false).contains("lost"), "an empty temporary project loses nothing");
            String disk = Restart.cost("the dark theme", false, true, false);
            Expect.isTrue(disk.contains("saved first and opened again") && !disk.contains("lost"), "a project in a file: " + disk);
            Expect.isTrue(Restart.cost("x", false, true, true).contains("scan is running"), "a running scan is named");
        });

        Harness.test("the project in a file is handed to the next start", () -> {
            File p = new File("work.osuite").getAbsoluteFile();
            Expect.equal(List.of(Restart.arguments(new String[]{"--debug"}, p)), List.of("--debug", p.getPath()), "flags kept, the project added");
            Expect.equal(List.of(Restart.arguments(new String[]{"old.osuite", "--debug"}, p)), List.of("--debug", p.getPath()), "the project it was started with gives way to the open one");
            Expect.equal(List.of(Restart.arguments(new String[]{"old.osuite"}, null)), List.<String>of(), "a temporary project: none is named");
        });

        Harness.test("only the application's own arguments are replaced", () -> {
            Expect.equal(UiScale.argumentsFor(new String[]{"-Xmx1g", "-cp", "a:b", "opensuite.ui.Main", "--debug"}, new String[]{"--debug"}, new String[]{"--debug", "/p.osuite"}),
                    List.of("-Xmx1g", "-cp", "a:b", "opensuite.ui.Main", "--debug", "/p.osuite"), "a copy started by hand keeps Java's options");
            Expect.equal(UiScale.argumentsFor(new String[0], new String[0], new String[]{"/p.osuite"}), List.of("/p.osuite"), "a packaged launcher gets just the project");
            Expect.equal(UiScale.argumentsFor(new String[0], new String[]{"old.osuite"}, new String[]{"/p.osuite"}), List.of("/p.osuite"), "Windows shows a process none of its arguments: the new ones are all it gets");
            Expect.equal(UiScale.argumentsFor(new String[]{"--strange"}, new String[]{"old.osuite"}, new String[]{"/p.osuite"}), List.of("--strange"), "a command line it does not know is started as it was");
        });
    }
}