mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-10 20:05:55 +02:00
parent
a203d8ebbf
commit
12a3c70860
13 changed files with 34 additions and 36 deletions
|
@ -214,7 +214,6 @@ linters-settings:
|
|||
enable-all: true
|
||||
disabled-checks:
|
||||
- paramTypeCombine
|
||||
- httpNoBody
|
||||
- ifElseChain
|
||||
- importShadow
|
||||
- hugeParam
|
||||
|
|
|
@ -113,7 +113,7 @@ func (cli *cliSupport) dumpMetrics(ctx context.Context, db *database.Client, zw
|
|||
return fmt.Errorf("could not format prometheus metrics: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cfg.Cscli.PrometheusUrl, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cfg.Cscli.PrometheusUrl, http.NoBody)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create request to prometheus endpoint: %w", err)
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ func (cli *cliSupport) dumpPprof(ctx context.Context, zw *zip.Writer, prometheus
|
|||
),
|
||||
endpoint,
|
||||
),
|
||||
nil,
|
||||
http.NoBody,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create request to pprof endpoint: %w", err)
|
||||
|
|
|
@ -25,7 +25,7 @@ func lookupLatest(ctx context.Context) (string, error) {
|
|||
|
||||
url := "https://version.crowdsec.net/latest"
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to create request for %s: %w", url, err)
|
||||
}
|
||||
|
|
|
@ -377,7 +377,7 @@ func (w *AppsecSource) IsAuth(ctx context.Context, apiKey string) bool {
|
|||
Timeout: 200 * time.Millisecond,
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodHead, w.lapiURL, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodHead, w.lapiURL, http.NoBody)
|
||||
if err != nil {
|
||||
log.Errorf("Error creating request: %s", err)
|
||||
return false
|
||||
|
|
|
@ -302,7 +302,7 @@ func (lc *LokiClient) QueryRange(ctx context.Context, infinite bool) chan *LokiQ
|
|||
|
||||
// Create a wrapper for http.Get to be able to set headers and auth
|
||||
func (lc *LokiClient) Get(ctx context.Context, url string) (*http.Response, error) {
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -370,7 +370,7 @@ func (lc *VLClient) QueryRange(ctx context.Context, infinite bool) chan *Log {
|
|||
}
|
||||
|
||||
func (lc *VLClient) Get(ctx context.Context, url string) (*http.Response, error) {
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ func (s *DecisionsService) GetDecisionsFromBlocklist(ctx context.Context, blockl
|
|||
|
||||
client := http.Client{}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, *blocklist.URL, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, *blocklist.URL, http.NoBody)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ func TestUnknownPath(t *testing.T) {
|
|||
router, _ := NewAPITest(t, ctx)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test", nil)
|
||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test", http.NoBody)
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
|
@ -396,7 +396,7 @@ func TestLoggingDebugToFileConfig(t *testing.T) {
|
|||
require.NotNil(t, api)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test42", nil)
|
||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test42", http.NoBody)
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
api.router.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||
|
@ -448,7 +448,7 @@ func TestLoggingErrorToFileConfig(t *testing.T) {
|
|||
require.NotNil(t, api)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test42", nil)
|
||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test42", http.NoBody)
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
api.router.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||
|
|
|
@ -160,7 +160,7 @@ func (p *Papi) GetPermissions(ctx context.Context) (PapiPermCheckSuccess, error)
|
|||
httpClient := p.apiClient.GetClient()
|
||||
papiCheckUrl := fmt.Sprintf("%s%s%s", p.URL, types.PAPIVersion, types.PAPIPermissionsUrl)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, papiCheckUrl, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, papiCheckUrl, http.NoBody)
|
||||
if err != nil {
|
||||
return PapiPermCheckSuccess{}, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ func TestJA4H_A(t *testing.T) {
|
|||
{
|
||||
name: "basic GET request - HTTP1.1 - no accept-language header",
|
||||
request: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
return req
|
||||
},
|
||||
expectedResult: "ge11nn000000",
|
||||
|
@ -37,7 +37,7 @@ func TestJA4H_A(t *testing.T) {
|
|||
{
|
||||
name: "basic GET request - HTTP1.1 - with accept-language header",
|
||||
request: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.Header.Set("Accept-Language", "en-US")
|
||||
return req
|
||||
},
|
||||
|
@ -46,7 +46,7 @@ func TestJA4H_A(t *testing.T) {
|
|||
{
|
||||
name: "basic POST request - HTTP1.1 - no accept-language header - cookies - referer",
|
||||
request: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodPost, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodPost, "http://example.com", http.NoBody)
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"})
|
||||
req.Header.Set("Referer", "http://example.com")
|
||||
return req
|
||||
|
@ -56,7 +56,7 @@ func TestJA4H_A(t *testing.T) {
|
|||
{
|
||||
name: "bad accept-language header",
|
||||
request: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.Header.Set("Accept-Language", "aksjdhaslkdhalkjsd")
|
||||
return req
|
||||
},
|
||||
|
@ -65,7 +65,7 @@ func TestJA4H_A(t *testing.T) {
|
|||
{
|
||||
name: "bad accept-language header 2",
|
||||
request: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.Header.Set("Accept-Language", ",")
|
||||
return req
|
||||
},
|
||||
|
@ -94,7 +94,7 @@ func TestJA4H_B(t *testing.T) {
|
|||
{
|
||||
name: "no headers",
|
||||
request: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
return req
|
||||
},
|
||||
expectedResult: "e3b0c44298fc",
|
||||
|
@ -102,7 +102,7 @@ func TestJA4H_B(t *testing.T) {
|
|||
{
|
||||
name: "header with arbitrary content",
|
||||
request: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.Header.Set("X-Custom-Header", "some value")
|
||||
return req
|
||||
},
|
||||
|
@ -111,7 +111,7 @@ func TestJA4H_B(t *testing.T) {
|
|||
{
|
||||
name: "header with multiple headers",
|
||||
request: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.Header.Set("X-Custom-Header", "some value")
|
||||
req.Header.Set("Authorization", "Bearer token")
|
||||
return req
|
||||
|
@ -121,7 +121,7 @@ func TestJA4H_B(t *testing.T) {
|
|||
{
|
||||
name: "curl-like request",
|
||||
request: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
|
||||
req.Header.Set("Host", "localhost")
|
||||
req.Header.Set("User-Agent", "curl/8.12.1")
|
||||
req.Header.Set("Accept", "*/*")
|
||||
|
@ -150,7 +150,7 @@ func TestJA4H_C(t *testing.T) {
|
|||
{
|
||||
name: "no cookies",
|
||||
cookies: func() []*http.Cookie {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
return req.Cookies()
|
||||
},
|
||||
expectedResult: "000000000000",
|
||||
|
@ -158,7 +158,7 @@ func TestJA4H_C(t *testing.T) {
|
|||
{
|
||||
name: "one cookie",
|
||||
cookies: func() []*http.Cookie {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"})
|
||||
return req.Cookies()
|
||||
},
|
||||
|
@ -167,7 +167,7 @@ func TestJA4H_C(t *testing.T) {
|
|||
{
|
||||
name: "duplicate cookies",
|
||||
cookies: func() []*http.Cookie {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"})
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar2"})
|
||||
return req.Cookies()
|
||||
|
@ -177,7 +177,7 @@ func TestJA4H_C(t *testing.T) {
|
|||
{
|
||||
name: "multiple cookies",
|
||||
cookies: func() []*http.Cookie {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"})
|
||||
req.AddCookie(&http.Cookie{Name: "bar", Value: "foo"})
|
||||
cookies := req.Cookies()
|
||||
|
@ -209,7 +209,7 @@ func TestJA4H_D(t *testing.T) {
|
|||
{
|
||||
name: "no cookies",
|
||||
cookies: func() []*http.Cookie {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
return req.Cookies()
|
||||
},
|
||||
expectedResult: "000000000000",
|
||||
|
@ -217,7 +217,7 @@ func TestJA4H_D(t *testing.T) {
|
|||
{
|
||||
name: "one cookie",
|
||||
cookies: func() []*http.Cookie {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"})
|
||||
return req.Cookies()
|
||||
},
|
||||
|
@ -226,7 +226,7 @@ func TestJA4H_D(t *testing.T) {
|
|||
{
|
||||
name: "duplicate cookies",
|
||||
cookies: func() []*http.Cookie {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"})
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar2"})
|
||||
return req.Cookies()
|
||||
|
@ -236,7 +236,7 @@ func TestJA4H_D(t *testing.T) {
|
|||
{
|
||||
name: "multiple cookies",
|
||||
cookies: func() []*http.Cookie {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"})
|
||||
req.AddCookie(&http.Cookie{Name: "bar", Value: "foo"})
|
||||
cookies := req.Cookies()
|
||||
|
@ -268,7 +268,7 @@ func TestJA4H(t *testing.T) {
|
|||
{
|
||||
name: "Basic GET - No cookies",
|
||||
req: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
return req
|
||||
},
|
||||
expectedHash: "ge11nn000000_e3b0c44298fc_000000000000_000000000000",
|
||||
|
@ -276,7 +276,7 @@ func TestJA4H(t *testing.T) {
|
|||
{
|
||||
name: "Basic GET - With cookies",
|
||||
req: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.AddCookie(&http.Cookie{Name: "session", Value: "12345"})
|
||||
return req
|
||||
},
|
||||
|
@ -285,7 +285,7 @@ func TestJA4H(t *testing.T) {
|
|||
{
|
||||
name: "Basic GET - Multiple cookies",
|
||||
req: func() *http.Request {
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
|
||||
req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"})
|
||||
req.AddCookie(&http.Cookie{Name: "baz", Value: "qux"})
|
||||
return req
|
||||
|
|
|
@ -42,8 +42,7 @@ func (c *CrowdsecCTIClient) doRequest(ctx context.Context, method string, endpoi
|
|||
url += fmt.Sprintf("%s=%s&", k, v)
|
||||
}
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, method, url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, method, url, http.NoBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -314,7 +314,7 @@ func TestJA4H(t *testing.T) {
|
|||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
req, err := http.NewRequest(test.method, test.url, nil)
|
||||
req, err := http.NewRequest(test.method, test.url, http.NoBody)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create request: %s", err)
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func (c *LongPollClient) doQuery(ctx context.Context) (*http.Response, error) {
|
|||
|
||||
logger.Debugf("Query parameters: %s", c.url.RawQuery)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.url.String(), nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.url.String(), http.NoBody)
|
||||
if err != nil {
|
||||
logger.Errorf("failed to create request: %s", err)
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue