mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-02-02 08:43:09 +08:00
adds -track-error option to add custom errors to max-host-error watchlist (#3399)
* Allow user to specify for "context deadline exceeded" errors to count toward the max host error count * Convert flag to a string slice `--track-error` * Minimize diff * Add documentation for `-track-error` * adds unit test & minor improvements * update flag description --------- Co-authored-by: Austin Traver <austin_traver@intuit.com> Co-authored-by: Tarun Koyalwar <tarun@projectdiscovery.io>
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCacheCheck(t *testing.T) {
|
||||
cache := New(3, DefaultMaxHostsCount)
|
||||
cache := New(3, DefaultMaxHostsCount, nil)
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
cache.MarkFailed("test", fmt.Errorf("could not resolve host"))
|
||||
@@ -28,6 +28,24 @@ func TestCacheCheck(t *testing.T) {
|
||||
require.Equal(t, true, value, "could not get checked value")
|
||||
}
|
||||
|
||||
func TestTrackErrors(t *testing.T) {
|
||||
cache := New(3, DefaultMaxHostsCount, []string{"custom error"})
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
cache.MarkFailed("custom", fmt.Errorf("got: nested: custom error"))
|
||||
got := cache.Check("custom")
|
||||
if i < 2 {
|
||||
// till 3 the host is not flagged to skip
|
||||
require.False(t, got)
|
||||
} else {
|
||||
// above 3 it must remain flagged to skip
|
||||
require.True(t, got)
|
||||
}
|
||||
}
|
||||
value := cache.Check("custom")
|
||||
require.Equal(t, true, value, "could not get checked value")
|
||||
}
|
||||
|
||||
func TestCacheItemDo(t *testing.T) {
|
||||
var (
|
||||
count int
|
||||
@@ -51,7 +69,7 @@ func TestCacheItemDo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCacheMarkFailed(t *testing.T) {
|
||||
cache := New(3, DefaultMaxHostsCount)
|
||||
cache := New(3, DefaultMaxHostsCount, nil)
|
||||
|
||||
tests := []struct {
|
||||
host string
|
||||
@@ -76,7 +94,7 @@ func TestCacheMarkFailed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCacheMarkFailedConcurrent(t *testing.T) {
|
||||
cache := New(3, DefaultMaxHostsCount)
|
||||
cache := New(3, DefaultMaxHostsCount, nil)
|
||||
|
||||
tests := []struct {
|
||||
host string
|
||||
|
||||
Reference in New Issue
Block a user