-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding flag to specify where to save scan output & optimizing scan logic
- Loading branch information
Showing
26 changed files
with
503 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cmd | ||
|
||
import "github.com/stefanoj3/dirstalk/pkg/scan" | ||
|
||
type OutputSaver interface { | ||
Save(scan.Result) error | ||
Close() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
out/* | ||
!out/.gitkeep | ||
out/* |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ type Config struct { | |
UseCookieJar bool | ||
Cookies []*http.Cookie | ||
Headers map[string]string | ||
Out string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package scan | ||
|
||
type ResultFilter interface { | ||
ShouldIgnore(Result) bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package filter | ||
|
||
import ( | ||
"github.com/stefanoj3/dirstalk/pkg/scan" | ||
) | ||
|
||
func NewHTTPStatusResultFilter(httpStatusesToIgnore []int) HTTPStatusResultFilter { | ||
httpStatusesToIgnoreMap := make(map[int]struct{}, len(httpStatusesToIgnore)) | ||
for _, statusToIgnore := range httpStatusesToIgnore { | ||
httpStatusesToIgnoreMap[statusToIgnore] = struct{}{} | ||
} | ||
|
||
return HTTPStatusResultFilter{httpStatusesToIgnoreMap: httpStatusesToIgnoreMap} | ||
} | ||
|
||
type HTTPStatusResultFilter struct { | ||
httpStatusesToIgnoreMap map[int]struct{} | ||
} | ||
|
||
func (f HTTPStatusResultFilter) ShouldIgnore(result scan.Result) bool { | ||
_, found := f.httpStatusesToIgnoreMap[result.StatusCode] | ||
return found | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package filter_test | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stefanoj3/dirstalk/pkg/scan" | ||
"github.com/stefanoj3/dirstalk/pkg/scan/filter" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHTTPStatusResultFilter(t *testing.T) { | ||
testCases := []struct { | ||
statusCodesToIgnore []int | ||
result scan.Result | ||
expectedResult bool | ||
}{ | ||
{ | ||
statusCodesToIgnore: []int{http.StatusCreated, http.StatusNotFound}, | ||
result: scan.Result{StatusCode: http.StatusOK}, | ||
expectedResult: false, | ||
}, | ||
{ | ||
statusCodesToIgnore: []int{http.StatusCreated, http.StatusNotFound}, | ||
result: scan.Result{StatusCode: http.StatusNotFound}, | ||
expectedResult: true, | ||
}, | ||
{ | ||
statusCodesToIgnore: []int{}, | ||
result: scan.Result{StatusCode: http.StatusNotFound}, | ||
expectedResult: false, | ||
}, | ||
{ | ||
statusCodesToIgnore: []int{}, | ||
result: scan.Result{StatusCode: http.StatusOK}, | ||
expectedResult: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc // Pinning ranged variable, more info: https://github.com/kyoh86/scopelint | ||
|
||
scenario := fmt.Sprintf("ignored: %v, result: %d", tc.statusCodesToIgnore, tc.result.StatusCode) | ||
|
||
t.Run(scenario, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
actual := filter.NewHTTPStatusResultFilter(tc.statusCodesToIgnore).ShouldIgnore(tc.result) | ||
assert.Equal(t, tc.expectedResult, actual) | ||
}) | ||
} | ||
} | ||
|
||
func TestHTTPStatusResultFilterShouldWorkConcurrently(t *testing.T) { | ||
sut := filter.NewHTTPStatusResultFilter(nil) | ||
|
||
wg := sync.WaitGroup{} | ||
for i := 0; i < 1000; i++ { | ||
wg.Add(1) | ||
|
||
go func(i int) { | ||
sut.ShouldIgnore(scan.Result{StatusCode: i}) | ||
wg.Done() | ||
}(i) | ||
} | ||
|
||
wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package output | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/stefanoj3/dirstalk/pkg/scan" | ||
) | ||
|
||
func convertResultToRawData(r scan.Result) ([]byte, error) { | ||
return json.Marshal(r) | ||
} |
Oops, something went wrong.