diff --git a/controllers/rest/global_initializers.go b/controllers/rest/global_initializers.go index 378b70ee..41d7e879 100644 --- a/controllers/rest/global_initializers.go +++ b/controllers/rest/global_initializers.go @@ -1,6 +1,7 @@ package rest import ( + "fmt" "github.com/getkin/kin-openapi/openapi3" weosContext "github.com/wepala/weos/context" "golang.org/x/net/context" @@ -10,10 +11,16 @@ import ( func Security(ctxt context.Context, api *RESTAPI, swagger *openapi3.Swagger) (context.Context, error) { middlewares := GetOperationMiddlewares(ctxt) found := false - for _, scheme := range swagger.Components.SecuritySchemes { + for key, scheme := range swagger.Components.SecuritySchemes { //checks if the security scheme has type openIdConnect if scheme.Value.Type == "openIdConnect" { - found = true + for _, security := range swagger.Security { + if security[key] != nil { + found = true + break + } + } + } } if found { @@ -21,6 +28,9 @@ func Security(ctxt context.Context, api *RESTAPI, swagger *openapi3.Swagger) (co middlewares = append(middlewares, middleware) } ctxt = context.WithValue(ctxt, weosContext.MIDDLEWARES, middlewares) + } else { + api.EchoInstance().Logger.Errorf("unexpected error: security defined does not match any security schemes") + return ctxt, fmt.Errorf("unexpected error: security defined does not match any security schemes") } return ctxt, nil } diff --git a/end2end_test.go b/end2end_test.go index 08cae2b4..b1f9a71b 100644 --- a/end2end_test.go +++ b/end2end_test.go @@ -539,7 +539,7 @@ func theSpecificationIsParsed(arg1 string) error { openAPI = fmt.Sprintf(openAPI, dbconfig.Database, dbconfig.Driver, dbconfig.Host, dbconfig.Password, dbconfig.User, dbconfig.Port) tapi, err := api.New(openAPI) if err != nil { - return err + errs = err } tapi.DB = db API = *tapi @@ -548,7 +548,7 @@ func theSpecificationIsParsed(arg1 string) error { e.Logger.SetOutput(&buf) err = API.Initialize(scenarioContext) if err != nil { - return err + errs = err } proj, err := API.GetProjection("Default") if err == nil { @@ -558,7 +558,7 @@ func theSpecificationIsParsed(arg1 string) error { } } if err != nil { - return err + errs = err } return nil } @@ -1608,7 +1608,7 @@ func TestBDD(t *testing.T) { Options: &godog.Options{ Format: "pretty", Tags: "~long && ~skipped", - //Tags: "focus1", + //Tags: "WEOS-1343", //Tags: "WEOS-1110 && ~skipped", }, }.Run() diff --git a/features/security-schemes.feature b/features/security-schemes.feature index 5afff854..7052398a 100644 --- a/features/security-schemes.feature +++ b/features/security-schemes.feature @@ -544,6 +544,7 @@ Feature: Use OpenAPI Security Scheme to protect endpoints Auth0: type: openIdConnect openIdConnectUrl: https://dev-bhjqt6zc.us.auth0.com/.well-known/openid-configuration + skipExpiryCheck: true schemas: Blog: type: object @@ -655,7 +656,7 @@ Feature: Use OpenAPI Security Scheme to protect endpoints description: Invalid Category submitted """ When the "OpenAPI 3.0" specification is parsed - Then an error to be returned + Then an error should be returned Scenario: Request with missing required scope