Skip to content

Commit

Permalink
added additional handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kashifkhan0771 committed Dec 23, 2024
1 parent 795b34b commit c717615
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions pkg/detectors/meraki/meraki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,21 @@ func TestMeraki_Fake(t *testing.T) {

// create a fake HTTP handler function
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Verify the Authorization Header
if r.Header.Get("X-Cisco-Meraki-API-Key") != "e9e0f062f587b423bb6cc6328eb786d75b45783e" {
switch r.Header.Get("X-Cisco-Meraki-API-Key") {
case "e9e0f062f587b423bb6cc6328eb786d75b45783e":
// send back mock response for 200 OK
w.WriteHeader(http.StatusOK)
_, _ = w.Write(mockResponse)
return
case "e9e0f062f587b423bb6cc6328eb786d75b45783f":
// send back mock 401 error for mock expired key
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
case "":
// if not auth header is sent, return 400 with unexpected status code
http.Error(w, "got unexpected status code: 400", http.StatusBadRequest)
return
}

// Send back mock response for 200 OK
w.WriteHeader(http.StatusOK)
_, _ = w.Write(mockResponse)
})
// create a mock server
server := CreateMockServer(handler)
Expand All @@ -150,6 +156,12 @@ func TestMeraki_Fake(t *testing.T) {
verified: false,
wantErr: false,
},
{
name: "fail - 400 unexpected status code error",
secret: "",
verified: false,
wantErr: true,
},
}

for _, test := range tests {
Expand Down

0 comments on commit c717615

Please sign in to comment.