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.4 KB
Raw Blame
package opensuite.sequencer;

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

import java.util.List;

/** Token handling before analysis (padding, length filter, Base64), and the spectral test. */
public final class TokenHandlingTest {

    public void run() {
        Harness.suite("sequencer token handling");

        Harness.test("short tokens are padded at the start", () -> {
            List<String> out = SequencerTool.prepare(List.of("abcd", "ab"), false, -1, true, '0');
            Expect.isTrue(out.equals(List.of("abcd", "00ab")), "padded at the start: " + out);
        });

        Harness.test("short tokens are padded at the end", () -> {
            List<String> out = SequencerTool.prepare(List.of("abcd", "ab"), false, -1, false, 'x');
            Expect.isTrue(out.equals(List.of("abcd", "abxx")), "padded at the end: " + out);
        });

        Harness.test("tokens that stray from the usual length are dropped", () -> {
            List<String> out = SequencerTool.prepare(List.of("aaaaaaaa", "bbbbbbbb", "cccccccc", "d"), false, 5, true, '0');
            Expect.isTrue(out.size() == 3, "three tokens remain: " + out);
            Expect.isFalse(out.contains("0000000d"), "the stray token is gone");
        });

        Harness.test("Base64 tokens are decoded when asked", () -> {
            List<String> out = SequencerTool.prepare(List.of("aGVsbG8="), true, -1, true, '0');
            Expect.isTrue(out.equals(List.of("hello")), "decoded: " + out);
        });

        Harness.test("the padding character is one character or a hex code", () -> {
            Expect.isTrue(SequencerTool.padChar("41") == 'A', "two hex digits name the character");
            Expect.isTrue(SequencerTool.padChar("x") == 'x', "one character is itself");
            Expect.isTrue(SequencerTool.padChar("") == '0', "empty falls back to 0");
        });

        Harness.test("the spectral test passes random bits and fails a periodic stream", () -> {
            java.util.Random r = new java.util.Random(7);
            boolean[] random = new boolean[4096], periodic = new boolean[4096];
            for (int i = 0; i < random.length; i++) { random[i] = r.nextBoolean(); periodic[i] = (i % 4) < 2; }
            Expect.isTrue(SequencerTool.spectral(random).contains("PASS"), "random bits pass");
            Expect.isTrue(SequencerTool.spectral(periodic).contains("FAIL"), "a periodic stream fails");
        });
    }
}