diff --git a/main_test.go b/main_test.go index 9151adf872a41f096303bf004af0c36aef0b1f5e..c62471f70eb9ad1da4e8a319408a035d62e3134d 100644 --- a/main_test.go +++ b/main_test.go @@ -293,4 +293,32 @@ func TestHash_IntelligenceValidOutput(t *testing.T) { if jsonResponse.FrontendResponse[1].EN.Status != "Risk"{ t.Fatalf("The status of AlienVault has is not as expected Risk, Status is: %s", jsonResponse.FrontendResponse[1].EN.Status) } +} + +/** +* This API test checks if an unspecified endpoint in the API returns 404 as expected +* +*/ + +func TestNotSpecifiedEndpoint(t *testing.T){ + + url := "http://localhost:8081/ThisShouldNotExist" + + req, err := http.NewRequest("GET", url, nil) + if err != nil { + t.Fatalf("Error in request") + } + req.Header.Set("Content-Type", "application/json; charset=UTF-8") + + client := &http.Client{} + + res, err := client.Do(req) + if err != nil { + t.Fatalf("Request to Hash-Intelligence failed") + } + defer res.Body.Close() + + if res.StatusCode != http.StatusNotFound { + t.Fatalf("Staus code did not return 404 as expected, code returned %d", res.StatusCode) + } } \ No newline at end of file