Skip to content

Commit

Permalink
test(definitions): add example test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed May 23, 2024
1 parent d7d2106 commit 00c3025
Show file tree
Hide file tree
Showing 26 changed files with 167 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/apiKey/apiKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'API Key';
const jsonSchema = require('../../../../../definitions/3.0.0/apiKey.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('API Key', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
5 changes: 5 additions & 0 deletions test/definitions/3.0.0/security/apiKey/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "apiKey",
"description": "apiKey",
"in": "user"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'Asymmetric Encryption';
const jsonSchema = require('../../../../../definitions/3.0.0/asymmetricEncryption.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('Asymmetric Encryption', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "asymmetricEncryption",
"description": "asymmetricEncryption"
}
4 changes: 4 additions & 0 deletions test/definitions/3.0.0/security/gssapi/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "gssapi",
"description": "gssapi"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/gssapi/gssapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'GSS-API';
const jsonSchema = require('../../../../../definitions/3.0.0/SaslGssapiSecurityScheme.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('GSS-API', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
6 changes: 6 additions & 0 deletions test/definitions/3.0.0/security/httpApiKey/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "httpApiKey",
"description": "httpApiKey",
"name": "api_key",
"in": "header"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/httpApiKey/httpApiKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'HTTP API Key';
const jsonSchema = require('../../../../../definitions/3.0.0/APIKeyHTTPSecurityScheme.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('HTTP API Key', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
5 changes: 5 additions & 0 deletions test/definitions/3.0.0/security/httpBasic/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "http",
"description": "http",
"scheme": "basic"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/httpBasic/httpBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'HTTP Basic';
const jsonSchema = require('../../../../../definitions/3.0.0/NonBearerHTTPSecurityScheme.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('HTTP Basic', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
6 changes: 6 additions & 0 deletions test/definitions/3.0.0/security/httpBearer/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "http",
"description": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/httpBearer/httpBearer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'HTTP Bearer';
const jsonSchema = require('../../../../../definitions/3.0.0/BearerHTTPSecurityScheme.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('HTTP Bearer', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
9 changes: 9 additions & 0 deletions test/definitions/3.0.0/security/openIdconnect/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "openIdConnect",
"description": "openIdConnect",
"openIdConnectUrl": "https://server.com/.well-known/openid-configuration",
"scopes": [
"write:pets",
"read:pets"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'OpenID Connect';
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('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
4 changes: 4 additions & 0 deletions test/definitions/3.0.0/security/plain/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "plain",
"description": "plain"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/plain/plain.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'Plain';
const jsonSchema = require('../../../../../definitions/3.0.0/SaslPlainSecurityScheme.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('Plain', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
4 changes: 4 additions & 0 deletions test/definitions/3.0.0/security/scramSha256/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "scramSha256",
"description": "scramSha256"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/scramSha256/scramSha256.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'SCRAM-SHA-256';
const jsonSchema = require('../../../../../definitions/3.0.0/SaslScramSecurityScheme.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('SCRAM-SHA-256', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
4 changes: 4 additions & 0 deletions test/definitions/3.0.0/security/scramSha512/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "scramSha512",
"description": "scramSha512"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/scramSha512/scramSha512.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'SCRAM-SHA-512';
const jsonSchema = require('../../../../../definitions/3.0.0/SaslScramSecurityScheme.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('SCRAM-SHA-512', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "symmetricEncryption",
"description": "symmetricEncryption"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'Symmetric Encryption';
const jsonSchema = require('../../../../../definitions/3.0.0/symmetricEncryption.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('Symmetric Encryption', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
4 changes: 4 additions & 0 deletions test/definitions/3.0.0/security/userPassword/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "userPassword",
"description": "userPassword"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/userPassword/userPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'User Password';
const jsonSchema = require('../../../../../definitions/3.0.0/userPassword.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('User Password', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down
4 changes: 4 additions & 0 deletions test/definitions/3.0.0/security/x509/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "X509",
"description": "X509"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/security/x509/x509.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'X509';
const jsonSchema = require('../../../../../definitions/3.0.0/X509.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

describe('X509', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const model = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(model);
Expand Down

0 comments on commit 00c3025

Please sign in to comment.