Skip to content

Commit

Permalink
test(definitions): sasl security scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed May 22, 2024
1 parent 97f2e91 commit 6f30129
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/definitions/3.0.0/security/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ describe('Security Schemes', () => {
require('./asymmetricEncryption/asymmetricEncryption.js');
require('./gssapi/gssapi.js');
require('./openIdconnect/openIdconnect.js');
require('./saslSecurityScheme/saslSecurityScheme.js')
require('./plain/plain.js');
require('./scramSha256/scramSha256.js');
require('./scramSha512/scramSha512.js');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "gssapi",
"description": "gssapi"
}
4 changes: 4 additions & 0 deletions test/definitions/3.0.0/security/saslSecurityScheme/plain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "plain",
"description": "plain"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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/SaslSecurityScheme.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/SaslScramSecurityScheme.json'))
.addSchema(require('../../../../../definitions/3.0.0/SaslPlainSecurityScheme.json'))
.addSchema(require('../../../../../definitions/3.0.0/SaslGssapiSecurityScheme.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(jsonSchema);

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

assert(validationResult === true, 'Plain is valid');
});

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

assert(validationResult === true, 'HTTP API Key is valid');
});

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

assert(validationResult === true, 'HTTP API Key is valid');
});

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

assert(validationResult === true, 'HTTP API Key is valid');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "scramSha256",
"description": "scramSha256"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "scramSha512",
"description": "scramSha512"
}

0 comments on commit 6f30129

Please sign in to comment.