Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ To compare two results files you already have, without scanning, use `subenum di

No flags required. Fill in the form and press `ctrl+r` to start scanning. Last-used values are saved to `last.json` in your user config directory (`~/.config/subenum/` on Linux, `~/Library/Application Support/subenum/` on macOS, `%AppData%\subenum\` on Windows) and restored on next launch.

Leaving a numeric field blank uses its built-in default.

<img src="docs/assets/tui-form.png" alt="subenum interactive TUI" width="640"/>

<details>
Expand Down
27 changes: 15 additions & 12 deletions internal/tui/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,14 @@ func (m *formModel) validate() (formValues, string) {

// The form only parses its text fields here; ranges and the resolver are
// checked by scan.Options.Validate, the same validator the CLI uses (#80).
num := func(f int, name string, blank int) int {
// Blank values use the same defaults as remembered().
num := func(f int, name string) int {
s := strings.TrimSpace(text(f))
if err != nil || s == "" {
keep(f, strconv.Itoa(blank))
return blank
if err != nil {
return 0
}
if s == "" {
s = formFields[f].def
}
n, perr := strconv.Atoi(s)
if perr != nil {
Expand All @@ -563,22 +566,22 @@ func (m *formModel) validate() (formValues, string) {
keep(f, strconv.Itoa(n))
return n
}
concurrency := num(fieldConcurrency, "Concurrency", 0)
timeout := num(fieldTimeout, "Timeout", 0)
attempts := num(fieldAttempts, "Attempts", 0)
concurrency := num(fieldConcurrency, "Concurrency")
timeout := num(fieldTimeout, "Timeout")
attempts := num(fieldAttempts, "Attempts")
// Hit rate only matters in simulation mode, and depth only when
// recursive is on; otherwise their fields must not block the scan.
hitRate := scan.DefaultHitRate
if m.shown(fieldHitRate) {
hitRate = num(fieldHitRate, "Hit rate", 0)
hitRate = num(fieldHitRate, "Hit rate")
}
depth := 1
if m.shown(fieldDepth) {
depth = num(fieldDepth, "Depth", 1)
depth = num(fieldDepth, "Depth")
}
rate := num(fieldRate, "Rate", 0) // blank means unlimited
maxQueries := num(fieldMaxQueries, "Max queries", 0) // blank means unlimited
ratePerResolver := num(fieldRatePerResolver, formFields[fieldRatePerResolver].name(), 0)
rate := num(fieldRate, "Rate") // blank means unlimited
maxQueries := num(fieldMaxQueries, "Max queries") // blank means unlimited
ratePerResolver := num(fieldRatePerResolver, formFields[fieldRatePerResolver].name())
var maxDuration time.Duration // blank means unlimited, as -max-duration 0
if s := strings.TrimSpace(text(fieldMaxDuration)); err == nil && s != "" {
var perr error
Expand Down
46 changes: 42 additions & 4 deletions internal/tui/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func TestValidateNonPositiveConcurrency(t *testing.T) {
}
}

// Empty hit rate must be accepted when Simulate is OFF (it is never used),
// and rejected when Simulate is ON.
// Empty hit rate uses the default; explicit invalid values only matter
// when Simulate is ON.
func TestValidateHitRateOnlyWhenSimulate(t *testing.T) {
live := newFormModel(savedConfig{})
live.inputs[fieldDomain].SetValue("example.com")
Expand All @@ -64,8 +64,8 @@ func TestValidateHitRateOnlyWhenSimulate(t *testing.T) {
sim.inputs[fieldDomain].SetValue("example.com")
sim.inputs[fieldHitRate].SetValue("") // blank hit rate
sim.toggles[fieldSimulate] = true
if _, errStr := sim.validate(); errStr == "" {
t.Error("simulate mode should reject blank hit rate")
if vals, errStr := sim.validate(); errStr != "" || vals.HitRate != scan.DefaultHitRate {
t.Errorf("simulate mode with blank hit rate: rate %d, error %q", vals.HitRate, errStr)
}

sim.inputs[fieldHitRate].SetValue("500") // out of range
Expand All @@ -74,6 +74,44 @@ func TestValidateHitRateOnlyWhenSimulate(t *testing.T) {
}
}

func TestValidateBlankNumericFieldsUseDefaults(t *testing.T) {
for _, field := range []int{fieldConcurrency, fieldTimeout, fieldAttempts, fieldHitRate,
fieldDepth, fieldRate, fieldMaxQueries, fieldRatePerResolver} {
t.Run(formFields[field].name(), func(t *testing.T) {
for _, blank := range []string{"", " \t "} {
m := newFormModel(savedConfig{Domain: "example.com", Simulate: true, Recursive: true})
want, errStr := m.validate()
if errStr != "" {
t.Fatal(errStr)
}
m.inputs[field].SetValue(blank)
got, errStr := m.validate()
if errStr != "" {
t.Errorf("blank %q: %s", blank, errStr)
continue
}
if !reflect.DeepEqual(got.Options, want.Options) || !reflect.DeepEqual(got.saved, want.saved) {
t.Errorf("blank %q changed scan or saved defaults: got %+v, want %+v", blank, got, want)
}
}
})
}
}

func TestValidateExplicitInvalidNumericFields(t *testing.T) {
for _, field := range []int{fieldConcurrency, fieldTimeout, fieldAttempts, fieldHitRate} {
t.Run(formFields[field].name(), func(t *testing.T) {
for _, value := range []string{"0", "-1", "not-a-number"} {
m := newFormModel(savedConfig{Domain: "example.com", Simulate: true})
m.inputs[field].SetValue(value)
if _, errStr := m.validate(); errStr == "" {
t.Errorf("explicit %q must still fail validation", value)
}
}
})
}
}

func TestMoveFocusSkipsGatedFields(t *testing.T) {
m := newFormModel(savedConfig{})

Expand Down
Loading