Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/tmplexec/flow/util_test.go
2843 views
1
package flow
2
3
import (
4
"testing"
5
6
"github.com/projectdiscovery/nuclei/v3/pkg/operators"
7
"github.com/stretchr/testify/require"
8
)
9
10
func TestHasMatchersPanicRegression(t *testing.T) {
11
// This test ensures that hasMatchers does not panic when passed a slice containing nil.
12
// This was the source of a reported panic when a request had no local operators.
13
14
require.NotPanics(t, func() {
15
all := []*operators.Operators{nil}
16
result := hasMatchers(all)
17
require.False(t, result)
18
}, "hasMatchers should not panic with nil element in slice")
19
20
require.NotPanics(t, func() {
21
all := []*operators.Operators{nil, {}}
22
result := hasMatchers(all)
23
require.False(t, result)
24
}, "hasMatchers should not panic with mix of nil and empty operators")
25
}
26
27
func TestHasOperatorsPanicRegression(t *testing.T) {
28
// Also ensure hasOperators is safe
29
require.NotPanics(t, func() {
30
all := []*operators.Operators{nil}
31
result := hasOperators(all)
32
require.False(t, result)
33
}, "hasOperators should not panic with nil element in slice")
34
}
35
36