Skip to content

Commit

Permalink
add tests for x- and X- prefixed security schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
rpmccarter committed Oct 25, 2023
1 parent 4dc693a commit 6da78cb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
10 changes: 9 additions & 1 deletion datamodel/high/v3/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func TestNewDocument_Components_Responses(t *testing.T) {
func TestNewDocument_Components_SecuritySchemes(t *testing.T) {
initTest()
h := NewDocument(lowDoc)
assert.Len(t, h.Components.SecuritySchemes, 3)
assert.Len(t, h.Components.SecuritySchemes, 5)

api := h.Components.SecuritySchemes["APIKeyScheme"]
assert.Equal(t, "an apiKey security scheme", api.Description)
Expand All @@ -295,6 +295,14 @@ func TestNewDocument_Components_SecuritySchemes(t *testing.T) {
assert.Equal(t, "read all burgers", oAuth.Flows.Implicit.Scopes["read:burgers"])
assert.Equal(t, "https://pb33f.io/oauth", oAuth.Flows.AuthorizationCode.AuthorizationUrl)

basic := h.Components.SecuritySchemes["x-basic"]
assert.NotNil(t, basic)
assert.Equal(t, "a basic security scheme", basic.Description)

bearer := h.Components.SecuritySchemes["X-Bearer"]
assert.NotNil(t, bearer)
assert.Equal(t, "a bearer security scheme", bearer.Description)

// check the lowness is low.
assert.Equal(t, 380, oAuth.Flows.GoLow().Implicit.Value.Scopes.KeyNode.Line)
assert.Equal(t, 11, oAuth.Flows.GoLow().Implicit.Value.Scopes.KeyNode.Column)
Expand Down
10 changes: 9 additions & 1 deletion datamodel/low/v3/create_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func TestCreateDocument_Components_SecuritySchemes(t *testing.T) {
initTest()
components := doc.Components.Value
securitySchemes := components.SecuritySchemes.Value
assert.Len(t, securitySchemes, 3)
assert.Len(t, securitySchemes, 5)

apiKey := components.FindSecurityScheme("APIKeyScheme").Value
assert.NotNil(t, apiKey)
Expand All @@ -473,6 +473,14 @@ func TestCreateDocument_Components_SecuritySchemes(t *testing.T) {
assert.NotNil(t, oAuth.Flows.Value.Implicit.Value)
assert.NotNil(t, oAuth.Flows.Value.AuthorizationCode.Value)

basic := components.FindSecurityScheme("x-basic").Value
assert.NotNil(t, basic)
assert.Equal(t, "a basic security scheme", basic.Description.Value)

bearer := components.FindSecurityScheme("X-Bearer").Value
assert.NotNil(t, bearer)
assert.Equal(t, "a bearer security scheme", bearer.Description.Value)

scopes := oAuth.Flows.Value.Implicit.Value.Scopes.Value
assert.NotNil(t, scopes)

Expand Down
8 changes: 8 additions & 0 deletions test_specs/burgershop.openapi-modified.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@ components:
scopes:
write:burgers: modify burgers and stuff
read:burgers: read all the burgers
x-basic:
description: a basic security scheme
type: http
scheme: basic
X-Bearer:
description: a bearer security scheme
type: http
scheme: bearer
parameters:
BurgerHeader:
in: header
Expand Down
8 changes: 8 additions & 0 deletions test_specs/burgershop.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ components:
scopes:
write:burgers: modify burgers and stuff
read:burgers: read all the burgers
x-basic:
description: a basic security scheme
type: http
scheme: basic
X-Bearer:
description: a bearer security scheme
type: http
scheme: bearer
parameters:
BurgerHeader:
in: header
Expand Down

0 comments on commit 6da78cb

Please sign in to comment.