|
|
@ -11,18 +11,15 @@ import ( |
|
|
|
|
|
|
|
func TestAuthorizationMiddleware(t *testing.T) { |
|
|
|
token := faker.Word() |
|
|
|
middleware := CreateAuthenticationMiddleware(token) |
|
|
|
|
|
|
|
t.Run("AuthorizationMiddleware returns 403 response when authorization header is incorrect", func(t *testing.T) { |
|
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
}) |
|
|
|
|
|
|
|
middleware := AuthenticationMiddleware{ |
|
|
|
Secret: token, |
|
|
|
} |
|
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
}) |
|
|
|
|
|
|
|
middlewareHandler := middleware.Middleware(handler) |
|
|
|
middlewareHandler := middleware.Middleware(handler) |
|
|
|
|
|
|
|
t.Run("AuthorizationMiddleware returns 403 response when authorization header is incorrect", func(t *testing.T) { |
|
|
|
request, _ := http.NewRequest("GET", "/", nil) |
|
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
@ -32,16 +29,6 @@ func TestAuthorizationMiddleware(t *testing.T) { |
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("AuthorizationMiddleware continues when authorization header is correct", func(t *testing.T) { |
|
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
}) |
|
|
|
|
|
|
|
middleware := AuthenticationMiddleware{ |
|
|
|
Secret: token, |
|
|
|
} |
|
|
|
|
|
|
|
middlewareHandler := middleware.Middleware(handler) |
|
|
|
|
|
|
|
request, _ := http.NewRequest("GET", "/", nil) |
|
|
|
request.Header.Set("Authorization", "Bearer "+token) |
|
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|