Skip to content

Instantly share code, notes, and snippets.

@shrmpy
Last active November 3, 2021 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrmpy/14638c7b525cb09e6cf7cae712c4892c to your computer and use it in GitHub Desktop.
Save shrmpy/14638c7b525cb09e6cf7cae712c4892c to your computer and use it in GitHub Desktop.
Add the negative test to verify there is logic that enforces the correct extension secret
func TestWrongExtensionSecret(t *testing.T) {
// prepare data
wrongHeader := make(map[string]string)
wrongHeader["Authorization"] = "Bearer WRONG-KEY"
req := events.APIGatewayProxyRequest{
HTTPMethod: "GET",
Body: "",
Headers: wrongHeader,
}
// run request handlerlogic
result, err := handler(req)
assert.IsType(t, nil, err)
assert.Equal(t, http.StatusOK, result.StatusCode)
// case specific expectation
missing := newResponse("Wrong authorization header", http.StatusUnauthorized)
expected := ignoreTimestamp(missing.Body)
actual := ignoreTimestamp(result.Body)
// inspect content
assert.Equal(t, expected, actual)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment