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
7 changed files
with
104 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
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/openIdconnect/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 @@ | ||
{ | ||
"type": "openIdConnect", | ||
"description": "openIdConnect", | ||
"openIdConnectUrl": "https://server.com/.well-known/openid-configuration", | ||
"scopes": [ | ||
"write:pets", | ||
"read:pets" | ||
], | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
test/definitions/3.0.0/security/openIdconnect/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,4 @@ | ||
{ | ||
"type": "openIdConnect", | ||
"openIdConnectUrl": "https://server.com/.well-known/openid-configuration" | ||
} |
66 changes: 66 additions & 0 deletions
66
test/definitions/3.0.0/security/openIdconnect/openIdconnect.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,66 @@ | ||
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/openIdConnect.json'); | ||
const validator = ajv | ||
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json')) | ||
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json')) | ||
.compile(jsonSchema); | ||
|
||
describe('OpenID Connect', () => { | ||
it('empty', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === false, 'OpenID Connect with empty body is not valid'); | ||
assert(validator.errors[0].message === 'must have required property \'type\''); | ||
assert(validator.errors[1].message === 'must have required property \'openIdConnectUrl\''); | ||
assert(validator.errors.length === 2); | ||
}); | ||
|
||
it('without required properties', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === false, 'OpenID Connect without required properties is not valid'); | ||
assert(validator.errors[0].message === 'must have required property \'type\''); | ||
assert(validator.errors[1].message === 'must have required property \'openIdConnectUrl\''); | ||
assert(validator.errors.length === 2); | ||
}); | ||
|
||
it('only required properties', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, 'OpenID Connect 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, 'OpenID Connect 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, 'OpenID Connect 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); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
test/definitions/3.0.0/security/openIdconnect/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,3 @@ | ||
{ | ||
"description": "openIdConnect" | ||
} |
15 changes: 15 additions & 0 deletions
15
test/definitions/3.0.0/security/openIdconnect/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 @@ | ||
{ | ||
"type": "openIdConnect", | ||
"description": "openIdConnect", | ||
"openIdConnectUrl": "https://server.com/.well-known/openid-configuration", | ||
"scopes": [ | ||
"write:pets", | ||
"read:pets" | ||
], | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
}, | ||
"ext-number": 1 | ||
} |