-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added owasp-api8-2023-define-cors-origin
- Loading branch information
1 parent
015bb7f
commit 5174d1d
Showing
2 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { DiagnosticSeverity } from "@stoplight/types"; | ||
import testRule from "./__helpers__/helper"; | ||
|
||
testRule("owasp:api8:2023-define-cors-origin", [ | ||
{ | ||
name: "valid case", | ||
document: { | ||
openapi: "3.1.0", | ||
info: { version: "1.0", contact: {} }, | ||
paths: { | ||
"/": { | ||
get: { | ||
responses: { | ||
"200": { | ||
description: "ok", | ||
headers: { | ||
"Access-Control-Allow-Origin": { | ||
schema: { | ||
type: "string", | ||
examples: ["*"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: "invalid case", | ||
document: { | ||
openapi: "3.1.0", | ||
info: { version: "1.0", contact: {} }, | ||
paths: { | ||
"/a": { | ||
get: { | ||
responses: { | ||
"200": { | ||
description: "ok", | ||
headers: { | ||
"Some-Other-Headers": { | ||
schema: { | ||
type: "string", | ||
examples: ["*"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"/b": { | ||
get: { | ||
responses: { | ||
"200": { | ||
description: "ok", | ||
headers: {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: | ||
"Header `headers.Access-Control-Allow-Origin` should be defined on all responses.", | ||
path: ["paths", "/a", "get", "responses", "200", "headers"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
{ | ||
message: | ||
"Header `headers.Access-Control-Allow-Origin` should be defined on all responses.", | ||
path: ["paths", "/b", "get", "responses", "200", "headers"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters