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
4 changes: 4 additions & 0 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import (

// Runner is a client for running the enumeration process.
type Runner struct {
seenMux sync.Mutex
options *Options
hp *httpx.HTTPX
wappalyzer *wappalyzer.Wappalyze
Expand Down Expand Up @@ -675,6 +676,9 @@ func (r *Runner) classifyPage(headlessBody, body string, pHash uint64) map[strin
}

func (r *Runner) testAndSet(k string) bool {
r.seenMux.Lock()
defer r.seenMux.Unlock()

// skip empty lines
k = strings.TrimSpace(k)
if k == "" {
Expand Down
62 changes: 62 additions & 0 deletions runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -324,6 +325,67 @@ func TestRunner_CSVRow(t *testing.T) {
}
}

func TestRunner_testAndSet(t *testing.T) {
r, err := New(&Options{})
require.Nil(t, err, "could not create httpx runner")

t.Run("first insert returns true", func(t *testing.T) {
require.True(t, r.testAndSet("example.com"))
})

t.Run("duplicate returns false", func(t *testing.T) {
require.False(t, r.testAndSet("example.com"))
})

t.Run("different key returns true", func(t *testing.T) {
require.True(t, r.testAndSet("other.com"))
})

t.Run("empty string returns false", func(t *testing.T) {
require.False(t, r.testAndSet(""))
})

t.Run("whitespace-only returns false", func(t *testing.T) {
require.False(t, r.testAndSet(" "))
})

t.Run("trimmed duplicate returns false", func(t *testing.T) {
require.False(t, r.testAndSet(" example.com "))
})
}

func TestRunner_testAndSet_concurrent(t *testing.T) {
r, err := New(&Options{})
require.Nil(t, err, "could not create httpx runner")

const goroutines = 100
key := "race-target.com"
wins := make([]bool, goroutines)

var wg sync.WaitGroup
wg.Add(goroutines)
start := make(chan struct{})

for i := 0; i < goroutines; i++ {
go func(idx int) {
defer wg.Done()
<-start
wins[idx] = r.testAndSet(key)
}(i)
}

close(start)
wg.Wait()

winCount := 0
for _, w := range wins {
if w {
winCount++
}
}
require.Equal(t, 1, winCount, "exactly one goroutine should win testAndSet for the same key")
}

func TestCreateNetworkpolicyInstance_AllowDenyFlags(t *testing.T) {
runner := &Runner{}

Expand Down
Loading