|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func withArgs(args []string, fn func()) { |
| 9 | + orig := osArgs() |
| 10 | + setOsArgs(args) |
| 11 | + defer setOsArgs(orig) |
| 12 | + fn() |
| 13 | +} |
| 14 | + |
| 15 | +func TestNormalizeLegacySetup(t *testing.T) { |
| 16 | + withArgs([]string{"macaron", "-setup"}, func() { |
| 17 | + normalizeLegacyArgs() |
| 18 | + if osArgs()[1] != "--setup" { |
| 19 | + t.Fatalf("expected --setup, got %s", osArgs()[1]) |
| 20 | + } |
| 21 | + }) |
| 22 | +} |
| 23 | + |
| 24 | +func TestNormalizeCommandScan(t *testing.T) { |
| 25 | + withArgs([]string{"macaron", "scan", "example.com", "--fast"}, func() { |
| 26 | + normalizeCommandArgs() |
| 27 | + args := osArgs() |
| 28 | + want := []string{"macaron", "--scan", "example.com", "--fast"} |
| 29 | + if len(args) != len(want) { |
| 30 | + t.Fatalf("unexpected len: %#v", args) |
| 31 | + } |
| 32 | + for i := range want { |
| 33 | + if args[i] != want[i] { |
| 34 | + t.Fatalf("idx %d: got %q want %q", i, args[i], want[i]) |
| 35 | + } |
| 36 | + } |
| 37 | + }) |
| 38 | +} |
| 39 | + |
| 40 | +func TestApplyProfilePassive(t *testing.T) { |
| 41 | + mode := "wide" |
| 42 | + rate := 150 |
| 43 | + threads := 30 |
| 44 | + stages := "all" |
| 45 | + applyProfile("passive", &mode, &rate, &threads, &stages) |
| 46 | + if mode != "osint" || rate != 40 || threads != 10 || stages != "subdomains,http,urls" { |
| 47 | + t.Fatalf("unexpected passive values: mode=%s rate=%d threads=%d stages=%s", mode, rate, threads, stages) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +func TestApplyProfileAggressive(t *testing.T) { |
| 52 | + mode := "wide" |
| 53 | + rate := 150 |
| 54 | + threads := 30 |
| 55 | + stages := "all" |
| 56 | + applyProfile("aggressive", &mode, &rate, &threads, &stages) |
| 57 | + if rate != 350 || threads != 70 || stages != "all" { |
| 58 | + t.Fatalf("unexpected aggressive values: rate=%d threads=%d stages=%s", rate, threads, stages) |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +func osArgs() []string { |
| 63 | + return append([]string(nil), os.Args...) |
| 64 | +} |
| 65 | + |
| 66 | +func setOsArgs(v []string) { |
| 67 | + os.Args = append([]string(nil), v...) |
| 68 | +} |
0 commit comments