mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 21:55:26 +00:00
* expose hosterrorscache as an interface, change signature to capture the error reason * use the hosterrorscache.CacheInterface as struct field so users of Nuclei embedded can provide their own cache implementation Co-authored-by: Mike Rheinheimer <mrheinheimer@atlassian.com>
32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
package hosterrorscache
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCacheCheckMarkFailed(t *testing.T) {
|
|
cache := New(3, DefaultMaxHostsCount)
|
|
|
|
cache.MarkFailed("http://example.com:80", fmt.Errorf("no address found for host"))
|
|
if value, err := cache.failedTargets.Get("http://example.com:80"); err == nil && value != nil {
|
|
require.Equal(t, 1, value, "could not get correct number of marked failed hosts")
|
|
}
|
|
cache.MarkFailed("example.com:80", fmt.Errorf("Client.Timeout exceeded while awaiting headers"))
|
|
if value, err := cache.failedTargets.Get("example.com:80"); err == nil && value != nil {
|
|
require.Equal(t, 2, value, "could not get correct number of marked failed hosts")
|
|
}
|
|
cache.MarkFailed("example.com", fmt.Errorf("could not resolve host"))
|
|
if value, err := cache.failedTargets.Get("example.com"); err == nil && value != nil {
|
|
require.Equal(t, 1, value, "could not get correct number of marked failed hosts")
|
|
}
|
|
for i := 0; i < 3; i++ {
|
|
cache.MarkFailed("test", fmt.Errorf("could not resolve host"))
|
|
}
|
|
|
|
value := cache.Check("test")
|
|
require.Equal(t, true, value, "could not get checked value")
|
|
}
|