MCPcopy
hub / github.com/crowdsecurity/crowdsec / smokeHandler

Function smokeHandler

pkg/cticlient/ctiexpr/expr_test.go:71–110  ·  view source on GitHub ↗
(req *http.Request)

Source from the content-addressed store, hash-verified

69}
70
71func smokeHandler(req *http.Request) *http.Response {
72 apiKey := req.Header.Get("X-Api-Key")
73 if apiKey != validApiKey {
74 return &http.Response{
75 StatusCode: http.StatusForbidden,
76 Body: nil,
77 Header: make(http.Header),
78 }
79 }
80
81 requestedIP := strings.Split(req.URL.Path, "/")[3]
82
83 sample, ok := sampledata[requestedIP]
84 if !ok {
85 return &http.Response{
86 StatusCode: http.StatusNotFound,
87 Body: nil,
88 Header: make(http.Header),
89 }
90 }
91
92 body, err := json.Marshal(sample)
93 if err != nil {
94 return &http.Response{
95 StatusCode: http.StatusInternalServerError,
96 Body: nil,
97 Header: make(http.Header),
98 }
99 }
100
101 reader := io.NopCloser(bytes.NewReader(body))
102
103 return &http.Response{
104 StatusCode: http.StatusOK,
105 // Send response to be tested
106 Body: reader,
107 Header: make(http.Header),
108 ContentLength: 0,
109 }
110}
111
112func TestNilClient(t *testing.T) {
113 defer ShutdownCrowdsecCTI()

Callers

nothing calls this directly

Calls 2

NewReaderMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…