forked from asyncapi/spec-json-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
615 additions
and
0 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
63 changes: 63 additions & 0 deletions
63
...ions/3.0.0/security/oauth2/flows/authorizationCodeOAuthFlow/authorizationCodeOAuthFlow.js
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,63 @@ | ||
const Ajv = require('ajv'); | ||
const assert = require('assert'); | ||
const addFormats = require('ajv-formats'); | ||
const fs = require('fs'); | ||
|
||
const ajv = new Ajv({ | ||
jsonPointers: true, | ||
allErrors: true, | ||
schemaId: '$id', | ||
logger: false, | ||
validateFormats: true, | ||
strict: false, | ||
}); | ||
addFormats(ajv); | ||
|
||
const jsonSchema = require('../../../../../../../definitions/3.0.0/oauth2Flow.json'); | ||
const validator = ajv | ||
.addMetaSchema(require('../../../../../../../definitions/3.0.0/schema.json')) | ||
.addMetaSchema(require('../../../../../../../definitions/3.0.0/oauth2Scopes.json')) | ||
.addSchema(require('../../../../../../../definitions/3.0.0/specificationExtension.json')) | ||
.compile(jsonSchema); | ||
|
||
const schemaName = 'Authorization Code Flow'; | ||
|
||
describe(`${schemaName}`, () => { | ||
it('empty', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} is valid with empty body`); | ||
}); | ||
|
||
it('without required properties', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} is valid without required properties`); | ||
}); | ||
|
||
it('only required properties', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} is valid with only required properties`); | ||
}); | ||
|
||
it('extended', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} can be extended`); | ||
}); | ||
|
||
it('wrongly extended', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === false, `${schemaName} is not valid when was wrongly extended`); | ||
assert(validator.errors[0].message === 'must NOT have additional properties'); | ||
assert(validator.errors[0].params.additionalProperty === 'ext-number'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
test/definitions/3.0.0/security/oauth2/flows/authorizationCodeOAuthFlow/empty.json
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 @@ | ||
{} |
14 changes: 14 additions & 0 deletions
14
test/definitions/3.0.0/security/oauth2/flows/authorizationCodeOAuthFlow/extended.json
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,14 @@ | ||
{ | ||
"authorizationUrl": "https://example.com/api/oauth/dialog", | ||
"tokenUrl": "https://example.com/api/oauth/token", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
}, | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ions/3.0.0/security/oauth2/flows/authorizationCodeOAuthFlow/only required properties.json
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,9 @@ | ||
{ | ||
"authorizationUrl": "https://example.com/api/oauth/dialog", | ||
"tokenUrl": "https://example.com/api/oauth/token", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...s/3.0.0/security/oauth2/flows/authorizationCodeOAuthFlow/without required properties.json
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 @@ | ||
{} |
15 changes: 15 additions & 0 deletions
15
.../definitions/3.0.0/security/oauth2/flows/authorizationCodeOAuthFlow/wrongly extended.json
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,15 @@ | ||
{ | ||
"authorizationUrl": "https://example.com/api/oauth/dialog", | ||
"tokenUrl": "https://example.com/api/oauth/token", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
}, | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
}, | ||
"ext-number": 1 | ||
} |
63 changes: 63 additions & 0 deletions
63
...ions/3.0.0/security/oauth2/flows/clientCredentialsOAuthFlow/clientCredentialsOAuthFlow.js
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,63 @@ | ||
const Ajv = require('ajv'); | ||
const assert = require('assert'); | ||
const addFormats = require('ajv-formats'); | ||
const fs = require('fs'); | ||
|
||
const ajv = new Ajv({ | ||
jsonPointers: true, | ||
allErrors: true, | ||
schemaId: '$id', | ||
logger: false, | ||
validateFormats: true, | ||
strict: false, | ||
}); | ||
addFormats(ajv); | ||
|
||
const jsonSchema = require('../../../../../../../definitions/3.0.0/oauth2Flow.json'); | ||
const validator = ajv | ||
.addMetaSchema(require('../../../../../../../definitions/3.0.0/schema.json')) | ||
.addMetaSchema(require('../../../../../../../definitions/3.0.0/oauth2Scopes.json')) | ||
.addSchema(require('../../../../../../../definitions/3.0.0/specificationExtension.json')) | ||
.compile(jsonSchema); | ||
|
||
const schemaName = 'Client Credentials Flow'; | ||
|
||
describe(`${schemaName}`, () => { | ||
it('empty', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} is valid with empty body`); | ||
}); | ||
|
||
it('without required properties', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} is valid without required properties`); | ||
}); | ||
|
||
it('only required properties', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} is valid with only required properties`); | ||
}); | ||
|
||
it('extended', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} can be extended`); | ||
}); | ||
|
||
it('wrongly extended', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === false, `${schemaName} is not valid when was wrongly extended`); | ||
assert(validator.errors[0].message === 'must NOT have additional properties'); | ||
assert(validator.errors[0].params.additionalProperty === 'ext-number'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
test/definitions/3.0.0/security/oauth2/flows/clientCredentialsOAuthFlow/empty.json
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 @@ | ||
{} |
13 changes: 13 additions & 0 deletions
13
test/definitions/3.0.0/security/oauth2/flows/clientCredentialsOAuthFlow/extended.json
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,13 @@ | ||
{ | ||
"tokenUrl": "https://example.com/api/oauth/token", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
}, | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ions/3.0.0/security/oauth2/flows/clientCredentialsOAuthFlow/only required properties.json
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,8 @@ | ||
{ | ||
"tokenUrl": "https://example.com/api/oauth/token", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...s/3.0.0/security/oauth2/flows/clientCredentialsOAuthFlow/without required properties.json
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 @@ | ||
{} |
14 changes: 14 additions & 0 deletions
14
.../definitions/3.0.0/security/oauth2/flows/clientCredentialsOAuthFlow/wrongly extended.json
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,14 @@ | ||
{ | ||
"tokenUrl": "https://example.com/api/oauth/token", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
}, | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
}, | ||
"ext-number": 1 | ||
} |
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 @@ | ||
{} |
45 changes: 45 additions & 0 deletions
45
test/definitions/3.0.0/security/oauth2/flows/extended.json
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,45 @@ | ||
{ | ||
"type": "oauth2", | ||
"description": "oauth2", | ||
"flows": { | ||
"authorizationCode": { | ||
"authorizationUrl": "https://example.com/api/oauth/dialog", | ||
"tokenUrl": "https://example.com/api/oauth/token", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
}, | ||
"clientCredentials": { | ||
"tokenUrl": "https://example.com/api/oauth/token", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
}, | ||
"implicit": { | ||
"authorizationUrl": "https://example.com/api/oauth/dialog", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
}, | ||
"password": { | ||
"tokenUrl": "https://example.com/api/oauth/token", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
} | ||
}, | ||
"scopes": [ "write:pets", "read:pets" ], | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
test/definitions/3.0.0/security/oauth2/flows/implicitOAuthFlow/empty.json
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 @@ | ||
{} |
13 changes: 13 additions & 0 deletions
13
test/definitions/3.0.0/security/oauth2/flows/implicitOAuthFlow/extended.json
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,13 @@ | ||
{ | ||
"authorizationUrl": "https://example.com/api/oauth/dialog", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
}, | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
test/definitions/3.0.0/security/oauth2/flows/implicitOAuthFlow/implicitOAuthFlow.js
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,63 @@ | ||
const Ajv = require('ajv'); | ||
const assert = require('assert'); | ||
const addFormats = require('ajv-formats'); | ||
const fs = require('fs'); | ||
|
||
const ajv = new Ajv({ | ||
jsonPointers: true, | ||
allErrors: true, | ||
schemaId: '$id', | ||
logger: false, | ||
validateFormats: true, | ||
strict: false, | ||
}); | ||
addFormats(ajv); | ||
|
||
const jsonSchema = require('../../../../../../../definitions/3.0.0/oauth2Flow.json'); | ||
const validator = ajv | ||
.addMetaSchema(require('../../../../../../../definitions/3.0.0/schema.json')) | ||
.addMetaSchema(require('../../../../../../../definitions/3.0.0/oauth2Scopes.json')) | ||
.addSchema(require('../../../../../../../definitions/3.0.0/specificationExtension.json')) | ||
.compile(jsonSchema); | ||
|
||
const schemaName = 'Implicit Flow'; | ||
|
||
describe(`${schemaName}`, () => { | ||
it('empty', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} is valid with empty body`); | ||
}); | ||
|
||
it('without required properties', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} is valid without required properties`); | ||
}); | ||
|
||
it('only required properties', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} is valid with only required properties`); | ||
}); | ||
|
||
it('extended', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, `${schemaName} can be extended`); | ||
}); | ||
|
||
it('wrongly extended', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === false, `${schemaName} is not valid when was wrongly extended`); | ||
assert(validator.errors[0].message === 'must NOT have additional properties'); | ||
assert(validator.errors[0].params.additionalProperty === 'ext-number'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
test/definitions/3.0.0/security/oauth2/flows/implicitOAuthFlow/only required properties.json
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 @@ | ||
{} |
8 changes: 8 additions & 0 deletions
8
...efinitions/3.0.0/security/oauth2/flows/implicitOAuthFlow/without required properties.json
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,8 @@ | ||
{ | ||
"authorizationUrl": "https://example.com/api/oauth/dialog", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
test/definitions/3.0.0/security/oauth2/flows/implicitOAuthFlow/wrongly extended.json
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,14 @@ | ||
{ | ||
"authorizationUrl": "https://example.com/api/oauth/dialog", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"availableScopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
}, | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
}, | ||
"ext-number": 1 | ||
} |
Oops, something went wrong.