Skip to content

Commit

Permalink
Addressed #458
Browse files Browse the repository at this point in the history
Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Feb 20, 2024
1 parent d4dbd0b commit f1ac2f0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
54 changes: 54 additions & 0 deletions functions/owasp/header_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,57 @@ paths:
assert.Len(t, res, 4)

}

func TestHeaderDefinition_RateLimit(t *testing.T) {

yml := `openapi: 3.1'
paths:
/pizza/:
get:
responses:
499:
headers:
"Rate-Limit":
schema:
type: string
461:
headers:
"Content-Type":
schema:
type: string
450:
headers:
"Accept":
schema:
type: string
"Cache-Control":
schema:
type: string
`

// create a new document from specification bytes
document, err := libopenapi.NewDocument([]byte(yml))
// if anything went wrong, an error is thrown
if err != nil {
panic(fmt.Sprintf("cannot create new document: %e", err))
}

m, _ := document.BuildV3Model()
path := "$"

nodes, _ := utils.FindNodes([]byte(yml), path)

rule := buildOpenApiTestRuleAction(path, "header_definition", "", nil)
ctx := buildOpenApiTestContext(model.CastToRuleAction(rule.Then), map[string]interface{}{
"headers": []string{"Accept||Cache-Control", "Content-Type", "Rate-Limit"},
})
drDocument := drModel.NewDrDocument(m)
ctx.DrDocument = drDocument
def := HeaderDefinition{}
ctx.Rule = &rule

res := def.RunRule(nodes, ctx)

assert.Len(t, res, 0)

}
2 changes: 2 additions & 0 deletions rulesets/owasp_ruleset_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func GetOWASPRateLimitRule() *model.Rule {
xRatelimitLimit = "X-RateLimit-Limit"
xRateLimitLimit = "X-Rate-Limit-Limit"
ratelimitLimit = "RateLimit-Limit||RateLimit-Reset"
ratelimit = "RateLimit-Limit"
)

return &model.Rule{
Expand All @@ -294,6 +295,7 @@ func GetOWASPRateLimitRule() *model.Rule {
xRatelimitLimit,
xRateLimitLimit,
ratelimitLimit,
ratelimit,
},
},
},
Expand Down

0 comments on commit f1ac2f0

Please sign in to comment.