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

Function searchHandler

pkg/cticlient/client_test.go:154–201  ·  view source on GitHub ↗
(req *http.Request)

Source from the content-addressed store, hash-verified

152}
153
154func searchHandler(req *http.Request) *http.Response {
155 apiKey := req.Header.Get("X-Api-Key")
156 if apiKey != validApiKey {
157 return &http.Response{
158 StatusCode: http.StatusForbidden,
159 Body: nil,
160 Header: make(http.Header),
161 }
162 }
163
164 url, _ := url.Parse(req.URL.String())
165
166 ipsParam := url.Query().Get("ips")
167 if ipsParam == "" {
168 return &http.Response{
169 StatusCode: http.StatusBadRequest,
170 Body: nil,
171 Header: make(http.Header),
172 }
173 }
174
175 totalIps := 0
176 notFound := 0
177
178 ips := strings.Split(ipsParam, ",")
179 for _, ip := range ips {
180 _, ok := smokeResponses[ip]
181 if ok {
182 totalIps++
183 } else {
184 notFound++
185 }
186 }
187
188 response := fmt.Sprintf(`{"total": %d, "not_found": %d, "items": [`, totalIps, notFound)
189 for _, ip := range ips {
190 response += smokeResponses[ip]
191 }
192
193 response += "]}"
194 reader := io.NopCloser(strings.NewReader(response))
195
196 return &http.Response{
197 StatusCode: http.StatusOK,
198 Body: reader,
199 Header: make(http.Header),
200 }
201}
202
203func TestBadFireAuth(t *testing.T) {
204 ctiClient := NewCrowdsecCTIClient(WithAPIKey("asdasd"), WithHTTPClient(&http.Client{

Callers

nothing calls this directly

Calls 5

NewReaderMethod · 0.80
GetMethod · 0.45
ParseMethod · 0.45
StringMethod · 0.45
QueryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…