| 69 | } |
| 70 | |
| 71 | func 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 | |
| 112 | func TestNilClient(t *testing.T) { |
| 113 | defer ShutdownCrowdsecCTI() |