Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: WEOS-1343 Generate and Ensure BDD Test is passing #126

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions controllers/rest/global_initializers.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -10,17 +11,26 @@ 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 {
if middleware, _ := api.GetMiddleware("OpenIDMiddleware"); middleware != nil {
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
}
8 changes: 4 additions & 4 deletions end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -558,7 +558,7 @@ func theSpecificationIsParsed(arg1 string) error {
}
}
if err != nil {
return err
errs = err
}
return nil
}
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion features/security-schemes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down