-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fuzz tests to multiple receivers and processors
Signed-off-by: Adam Korczynski <[email protected]>
- Loading branch information
Showing
12 changed files
with
503 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package groupbyattrsprocessor | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
"go.opentelemetry.io/collector/processor/processortest" | ||
) | ||
|
||
func FuzzProcessTraces(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte) { | ||
ju := &ptrace.JSONUnmarshaler{} | ||
traces, err := ju.UnmarshalTraces(data) | ||
if err != nil { | ||
return | ||
} | ||
gap, err := createGroupByAttrsProcessor(processortest.NewNopSettings(), []string{}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_, _ = gap.processTraces(context.Background(), traces) | ||
}) | ||
} | ||
|
||
func FuzzProcessLogs(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte) { | ||
ju := &plog.JSONUnmarshaler{} | ||
logs, err := ju.UnmarshalLogs(data) | ||
if err != nil { | ||
return | ||
} | ||
gap, err := createGroupByAttrsProcessor(processortest.NewNopSettings(), []string{}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_, _ = gap.processLogs(context.Background(), logs) | ||
}) | ||
} | ||
|
||
func FuzzProcessMetrics(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte) { | ||
ju := &pmetric.JSONUnmarshaler{} | ||
metrics, err := ju.UnmarshalMetrics(data) | ||
if err != nil { | ||
return | ||
} | ||
gap, err := createGroupByAttrsProcessor(processortest.NewNopSettings(), []string{}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_, _ = gap.processMetrics(context.Background(), metrics) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package logdedupprocessor | ||
|
||
import ( | ||
"context" | ||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.opentelemetry.io/collector/processor/processortest" | ||
"testing" | ||
) | ||
|
||
func FuzzConsumeLogs(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte) { | ||
ju := &plog.JSONUnmarshaler{} | ||
logs, err := ju.UnmarshalLogs(data) | ||
if err != nil { | ||
return | ||
} | ||
sink := new(consumertest.LogsSink) | ||
set := processortest.NewNopSettings() | ||
cfg := &Config{} | ||
lp, err := newProcessor(cfg, sink, set) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_ = lp.ConsumeLogs(context.Background(), logs) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package probabilisticsamplerprocessor | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
"go.opentelemetry.io/collector/processor/processortest" | ||
) | ||
|
||
func FuzzConsumeTraces(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte) { | ||
ju := &ptrace.JSONUnmarshaler{} | ||
traces, err := ju.UnmarshalTraces(data) | ||
if err != nil { | ||
return | ||
} | ||
sink := new(consumertest.TracesSink) | ||
set := processortest.NewNopSettings() | ||
cfg := &Config{} | ||
tsp, err := newTracesProcessor(context.Background(), set, cfg, sink) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_ = tsp.ConsumeTraces(context.Background(), traces) | ||
}) | ||
} | ||
|
||
func FuzzConsumeLogs(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte) { | ||
ju := &plog.JSONUnmarshaler{} | ||
logs, err := ju.UnmarshalLogs(data) | ||
if err != nil { | ||
return | ||
} | ||
nextConsumer := consumertest.NewNop() | ||
cfg := &Config{} | ||
lp, err := newLogsProcessor(context.Background(), processortest.NewNopSettings(), nextConsumer, cfg) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_ = lp.ConsumeLogs(context.Background(), logs) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package sumologicprocessor | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
) | ||
|
||
func FuzzProcessTraces(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte, processorType uint8) { | ||
ju := &ptrace.JSONUnmarshaler{} | ||
traces, err := ju.UnmarshalTraces(data) | ||
if err != nil { | ||
return | ||
} | ||
switch int(processorType) % 4 { | ||
case 0: | ||
proc := &aggregateAttributesProcessor{} | ||
proc.processTraces(traces) | ||
case 1: | ||
proc := &cloudNamespaceProcessor{} | ||
proc.processTraces(traces) | ||
case 2: | ||
proc := &NestingProcessor{} | ||
proc.processTraces(traces) | ||
case 3: | ||
proc := &translateAttributesProcessor{} | ||
proc.processTraces(traces) | ||
} | ||
}) | ||
} | ||
|
||
func FuzzProcessLogs(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte, processorType uint8) { | ||
ju := &plog.JSONUnmarshaler{} | ||
logs, err := ju.UnmarshalLogs(data) | ||
if err != nil { | ||
return | ||
} | ||
switch int(processorType) % 4 { | ||
case 0: | ||
proc := &aggregateAttributesProcessor{} | ||
proc.processLogs(logs) | ||
case 1: | ||
proc := &cloudNamespaceProcessor{} | ||
proc.processLogs(logs) | ||
case 2: | ||
proc := &NestingProcessor{} | ||
proc.processLogs(logs) | ||
case 3: | ||
proc := &translateAttributesProcessor{} | ||
proc.processLogs(logs) | ||
} | ||
}) | ||
} | ||
|
||
func FuzzProcessMetrics(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte, processorType uint8) { | ||
ju := &pmetric.JSONUnmarshaler{} | ||
metrics, err := ju.UnmarshalMetrics(data) | ||
if err != nil { | ||
return | ||
} | ||
switch int(processorType) % 4 { | ||
case 0: | ||
proc := &aggregateAttributesProcessor{} | ||
proc.processMetrics(metrics) | ||
case 1: | ||
proc := &cloudNamespaceProcessor{} | ||
proc.processMetrics(metrics) | ||
case 2: | ||
proc := &NestingProcessor{} | ||
proc.processMetrics(metrics) | ||
case 3: | ||
proc := &translateAttributesProcessor{} | ||
proc.processMetrics(metrics) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package tailsamplingprocessor | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
"go.opentelemetry.io/collector/processor/processortest" | ||
) | ||
|
||
func FuzzConsumeTraces(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte) { | ||
ju := &ptrace.JSONUnmarshaler{} | ||
traces, err := ju.UnmarshalTraces(data) | ||
if err != nil { | ||
return | ||
} | ||
sink := new(consumertest.TracesSink) | ||
set := processortest.NewNopSettings() | ||
cfg := &Config{} | ||
tsp, err := newTracesProcessor(context.Background(), set, sink, *cfg) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_ = tsp.ConsumeTraces(context.Background(), traces) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cloudflarereceiver | ||
|
||
import ( | ||
"bytes" | ||
"net/http" | ||
|
||
"net/http/httptest" | ||
"testing" | ||
|
||
"go.opentelemetry.io/collector/config/configtls" | ||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
) | ||
|
||
func FuzzHandleReq(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, reqBody []byte, gZip bool) { | ||
|
||
req, err := http.NewRequest("POST", "http://example.com", bytes.NewReader(reqBody)) | ||
if err != nil { | ||
t.Skip() | ||
} | ||
req.Header.Add(secretHeaderName, "abc123") | ||
req.Header.Add("Content-Type", "text/plain; charset=utf-8") | ||
if gZip { | ||
req.Header.Add("Content-Encoding", "gzip") | ||
} | ||
consumer := &consumertest.LogsSink{} | ||
|
||
r := newReceiver(t, &Config{ | ||
Logs: LogsConfig{ | ||
Endpoint: "localhost:0", | ||
Secret: "abc123", | ||
TimestampField: "MyTimestamp", | ||
Attributes: map[string]string{ | ||
"ClientIP": "http_request.client_ip", | ||
}, | ||
TLS: &configtls.ServerConfig{}, | ||
}, | ||
}, | ||
consumer, | ||
) | ||
rec := httptest.NewRecorder() | ||
r.handleRequest(rec, req) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package internal | ||
|
||
import ( | ||
"bytes" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func FuzzParseRequest(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte, headerType uint8) { | ||
req, err := http.NewRequest("POST", "http://example.com", bytes.NewReader(data)) | ||
if err != nil { | ||
t.Skip() | ||
} | ||
switch int(headerType) % 3 { | ||
case 0: | ||
req.Header.Add("Content-Encoding", "snappy") | ||
case 1: | ||
req.Header.Add("Content-Encoding", "gzip") | ||
case 2: | ||
req.Header.Add("Content-Encoding", "deflat") | ||
} | ||
_, _ = ParseRequest(req) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package mongodbatlasreceiver | ||
|
||
import ( | ||
"bytes" | ||
"net/http" | ||
|
||
"net/http/httptest" | ||
"testing" | ||
|
||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/receiver/receivertest" | ||
"go.uber.org/zap/zaptest" | ||
) | ||
|
||
func FuzzHandleReq(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, reqBody []byte, payloadSigHeader string) { | ||
|
||
req, err := http.NewRequest("POST", "http://example.com", bytes.NewReader(reqBody)) | ||
if err != nil { | ||
t.Skip() | ||
} | ||
req.Header.Add(signatureHeaderName, payloadSigHeader) | ||
consumer := &consumertest.LogsSink{} | ||
|
||
set := receivertest.NewNopSettings() | ||
set.Logger = zaptest.NewLogger(t) | ||
ar, err := newAlertsReceiver(set, &Config{Alerts: AlertConfig{Secret: "some_secret"}}, consumer) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
rec := httptest.NewRecorder() | ||
ar.handleRequest(rec, req) | ||
}) | ||
} |
Oops, something went wrong.