diff --git a/auth/authorization.go b/auth/authorization.go index 5048228..8d3a14d 100644 --- a/auth/authorization.go +++ b/auth/authorization.go @@ -23,6 +23,6 @@ func (middleware AuthenticationMiddleware) Middleware(next http.Handler) http.Ha func CreateAuthenticationMiddleware(secret string) AuthenticationMiddleware { return AuthenticationMiddleware{ - secret: secret, + secret, } } diff --git a/auth/authorization_test.go b/auth/authorization_test.go index 139f416..36075ea 100644 --- a/auth/authorization_test.go +++ b/auth/authorization_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestAuthorizationMiddleware(t *testing.T) { +func TestAuthenticationMiddleware(t *testing.T) { token := faker.Word() middleware := CreateAuthenticationMiddleware(token) @@ -19,7 +19,7 @@ func TestAuthorizationMiddleware(t *testing.T) { middlewareHandler := middleware.Middleware(handler) - t.Run("AuthorizationMiddleware returns 403 response when authorization header is incorrect", func(t *testing.T) { + t.Run("AuthenticationMiddleware returns 403 response when authorization header is incorrect", func(t *testing.T) { request, _ := http.NewRequest("GET", "/", nil) responseRecorder := httptest.NewRecorder() @@ -28,7 +28,17 @@ func TestAuthorizationMiddleware(t *testing.T) { assert.Equal(t, 403, responseRecorder.Code) }) - t.Run("AuthorizationMiddleware continues when authorization header is correct", func(t *testing.T) { + t.Run("AuthenticationMiddleware returns 403 response when authorization header is missing Bearer prefix", func(t *testing.T) { + request, _ := http.NewRequest("GET", "/", nil) + request.Header.Set("Authorization", token) + responseRecorder := httptest.NewRecorder() + + middlewareHandler.ServeHTTP(responseRecorder, request) + + assert.Equal(t, 403, responseRecorder.Code) + }) + + t.Run("AuthenticationMiddleware continues when authorization header is correct", func(t *testing.T) { request, _ := http.NewRequest("GET", "/", nil) request.Header.Set("Authorization", "Bearer "+token) responseRecorder := httptest.NewRecorder() diff --git a/main_test.go b/main_test.go index 6f33974..1c0feeb 100644 --- a/main_test.go +++ b/main_test.go @@ -21,7 +21,7 @@ func TestIndexRoute(t *testing.T) { IndexHandler(responseRecorder, request) - assert.Equal(t, responseRecorder.Code, 200, "Response code should be 200") + assert.Equal(t, 200, responseRecorder.Code, "Response code should be 200") assert.NotNil(t, responseRecorder.Body, "Response should contain body") }) } @@ -44,7 +44,7 @@ func TestEndpointRoute(t *testing.T) { router.ServeHTTP(responseRecorder, request) - assert.Equal(t, responseRecorder.Code, 200) + assert.Equal(t, 200, responseRecorder.Code) body, _ := json.Marshal(data) assert.JSONEq(t, string(body), responseRecorder.Body.String()) }) @@ -57,6 +57,6 @@ func TestEndpointRoute(t *testing.T) { router.ServeHTTP(responseRecorder, request) - assert.Equal(t, responseRecorder.Code, 404) + assert.Equal(t, 404, responseRecorder.Code) }) } diff --git a/pipelines/executable_step.go b/pipelines/executable_step.go index 518b839..c0bfedb 100644 --- a/pipelines/executable_step.go +++ b/pipelines/executable_step.go @@ -3,8 +3,9 @@ package pipelines import ( "errors" "fmt" - "github.com/disintegration/imaging" "image" + + "github.com/disintegration/imaging" ) type IExecutableStep interface { diff --git a/pipelines/executable_step_test.go b/pipelines/executable_step_test.go index 4be7ae8..2445471 100644 --- a/pipelines/executable_step_test.go +++ b/pipelines/executable_step_test.go @@ -1,8 +1,9 @@ package pipelines import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestDeserializeOptionsResizeImage(t *testing.T) { diff --git a/pipelines/pipeline.go b/pipelines/pipeline.go index e9a783a..c5cc9b8 100644 --- a/pipelines/pipeline.go +++ b/pipelines/pipeline.go @@ -5,12 +5,13 @@ import ( "encoding/json" "errors" "fmt" - "github.com/disintegration/imaging" - "github.com/geplauder/lithium/storage" "io/fs" "log" "os" "path/filepath" + + "github.com/disintegration/imaging" + "github.com/geplauder/lithium/storage" ) // Pipelines diff --git a/pipelines/pipeline_test.go b/pipelines/pipeline_test.go index 4bee961..0b2a20c 100644 --- a/pipelines/pipeline_test.go +++ b/pipelines/pipeline_test.go @@ -1,12 +1,13 @@ package pipelines import ( - "github.com/geplauder/lithium/storage" "image" "os" "path/filepath" "testing" + "github.com/geplauder/lithium/storage" + "github.com/stretchr/testify/assert" ) diff --git a/pipelines/step_test.go b/pipelines/step_test.go index f731f5f..d7d4595 100644 --- a/pipelines/step_test.go +++ b/pipelines/step_test.go @@ -1,8 +1,9 @@ package pipelines import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestTranslateStep(t *testing.T) {