Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW authored and daveshanley committed Apr 11, 2024
1 parent 997ed2e commit 8287065
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions parameters/validate_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,53 @@ components:
assert.Equal(t, 1, len(errors))
}

func TestParamValidator_ValidateSecurity_MissingSecuritySchemes(t *testing.T) {

spec := `openapi: 3.1.0
paths:
/products:
post:
security:
- ApiKeyAuth:
- write:products
components: {}
`

doc, _ := libopenapi.NewDocument([]byte(spec))

m, _ := doc.BuildV3Model()

v := NewParameterValidator(&m.Model)

request, _ := http.NewRequest(http.MethodPost, "https://things.com/products", nil)
valid, errors := v.ValidateSecurity(request)
assert.False(t, valid)
assert.Equal(t, 1, len(errors))
}

func TestParamValidator_ValidateSecurity_NoComponents(t *testing.T) {

spec := `openapi: 3.1.0
paths:
/products:
post:
security:
- ApiKeyAuth:
- write:products
`

doc, _ := libopenapi.NewDocument([]byte(spec))

m, _ := doc.BuildV3Model()

v := NewParameterValidator(&m.Model)

request, _ := http.NewRequest(http.MethodPost, "https://things.com/products", nil)
valid, errors := v.ValidateSecurity(request)
assert.False(t, valid)
assert.Equal(t, 1, len(errors))
}

func TestParamValidator_ValidateSecurity_PresetPath(t *testing.T) {

spec := `openapi: 3.1.0
Expand Down

0 comments on commit 8287065

Please sign in to comment.