Path: blob/dev/pkg/fuzz/parts_frequency_test.go
4538 views
package fuzz12import (3"net/http"4"testing"56"github.com/projectdiscovery/nuclei/v3/pkg/fuzz/frequency"7"github.com/projectdiscovery/nuclei/v3/pkg/protocols"8retryablehttp "github.com/projectdiscovery/retryablehttp-go"9"github.com/stretchr/testify/require"10)1112// TestExecWithInputDoesNotUseNumericParameterIndexForFrequency verifies frequency13// checks do not key on numeric path segment indexes.14func TestExecWithInputDoesNotUseNumericParameterIndexForFrequency(t *testing.T) {15tracker := frequency.New(64, 1)16defer tracker.Close()1718const target = "https://example.com/users/55"19const templateID = "tmpl-frequency-check"2021req, err := retryablehttp.NewRequest(http.MethodGet, target, nil)22require.NoError(t, err)2324tracker.MarkParameter("2", req.String(), templateID)2526called := false27rule := &Rule{28options: &protocols.ExecutorOptions{29TemplateID: templateID,30FuzzParamsFrequency: tracker,31},32}33input := &ExecuteRuleInput{34Callback: func(GeneratedRequest) bool {35called = true36return true37},38}3940err = rule.execWithInput(input, req, nil, nil, "2", "55", "", "", "", "")41require.NoError(t, err)42require.True(t, called, "numeric path index should not be used as frequency key")43}4445// TestExecWithInputSkipsWhenActualParameterIsFrequent verifies requests are46// skipped when the normalized parameter value is marked frequent.47func TestExecWithInputSkipsWhenActualParameterIsFrequent(t *testing.T) {48tracker := frequency.New(64, 1)49defer tracker.Close()5051const target = "https://example.com/users/55"52const templateID = "tmpl-frequency-check"5354req, err := retryablehttp.NewRequest(http.MethodGet, target, nil)55require.NoError(t, err)5657tracker.MarkParameter("55", req.String(), templateID)5859called := false60rule := &Rule{61options: &protocols.ExecutorOptions{62TemplateID: templateID,63FuzzParamsFrequency: tracker,64},65}66input := &ExecuteRuleInput{67Callback: func(GeneratedRequest) bool {68called = true69return true70},71}7273err = rule.execWithInput(input, req, nil, nil, "2", "55", "", "", "", "")74require.NoError(t, err)75require.False(t, called, "frequent actual parameter should be skipped")76}777879