From 5b42dbdaa18f6885f3a13b91b0198b40e70f1cc1 Mon Sep 17 00:00:00 2001 From: odinkh <odinkh@stud.ntnu.no> Date: Mon, 16 May 2022 00:06:36 +0200 Subject: [PATCH] Added test to see if an unspecified endpoint returns 404 --- main_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/main_test.go b/main_test.go index 9151adf..c62471f 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 -- GitLab