@asyncapi/parser
Advanced tools
Comparing version 0.33.0 to 0.33.1
@@ -138,4 +138,2 @@ const ParserError = require('./errors/parser-error'); | ||
/* eslint-disable sonarjs/cognitive-complexity */ | ||
/* spliting it because it is 18 and not 15 lines would only make it more complex */ | ||
/** | ||
@@ -159,4 +157,3 @@ * Validates if server security is declared properly and the name has a corresponding security schema definition in components with the same name | ||
const missingSecSchema = new Map(), | ||
invalidSecurityValues = new Map(), | ||
missingScopesList = new Map(); | ||
invalidSecurityValues = new Map(); | ||
@@ -181,3 +178,2 @@ //we need to validate every server specified in the document | ||
if (!isSrvrSecProperArray(schemaType, specialSecTypes, secObj, secName)) invalidSecurityValues.set(srvrSecurityPath, schemaType); | ||
if (!hasSrvrSecScopes(schemaType, specialSecTypes, secObj, secName)) missingScopesList.set(srvrSecurityPath, schemaType); | ||
}); | ||
@@ -205,11 +201,2 @@ }); | ||
if (missingScopesList.size) { | ||
throw new ParserError({ | ||
type: validationError, | ||
title: 'Server security value must not be an empty array if corresponding security schema type is oauth2 or openIdConnect. Add list of required scopes.', | ||
parsedJSON, | ||
validationErrors: groupValidationErrors(root, 'security info must not have an empty array because its corresponding security schema type is', missingScopesList, asyncapiYAMLorJSON, initialFormat) | ||
}); | ||
} | ||
return true; | ||
@@ -259,21 +246,2 @@ } | ||
/** | ||
* Validates if given server security is not an empty array when security type requires it | ||
* @private | ||
* @param {String} schemaType security type, like httpApiKey or userPassword | ||
* @param {String[]} specialSecTypes list of special types that do not have to be an empty array | ||
* @param {Object} secObj server security object | ||
* @param {String} secName name os server security object | ||
* @returns {String[]} there are 2 elements in array, index 0 is the name of the security schema object and index 1 is it's type | ||
*/ | ||
function hasSrvrSecScopes(schemaType, specialSecTypes, secObj, secName) { | ||
if (specialSecTypes.includes(schemaType)) { | ||
const securityObjValue = secObj[String(secName)]; | ||
return !!securityObjValue.length; | ||
} | ||
return true; | ||
} | ||
module.exports = { | ||
@@ -280,0 +248,0 @@ validateChannelParams, |
{ | ||
"name": "@asyncapi/parser", | ||
"version": "0.33.0", | ||
"version": "0.33.1", | ||
"description": "JavaScript AsyncAPI parser.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -443,42 +443,2 @@ const { validateChannelParams, validateServerVariables, validateOperationId, validateServerSecurity } = require('../lib/customValidators.js'); | ||
it('should successfully validate server security for oauth2 that requires scopes', async function() { | ||
const inputString = `{ | ||
"asyncapi": "2.0.0", | ||
"info": { | ||
"version": "1.0.0" | ||
}, | ||
"servers": { | ||
"dummy": { | ||
"url": "http://localhost", | ||
"protocol": "kafka", | ||
"security": [ | ||
{ | ||
"oauthsec": ["read:pets"] | ||
} | ||
] | ||
} | ||
}, | ||
"components": { | ||
"securitySchemes": { | ||
"oauthsec": { | ||
"type": "oauth2", | ||
"flows": { | ||
"implicit": { | ||
"authorizationUrl": "https://example.com/api/oauth/auth", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"scopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
const parsedInput = JSON.parse(inputString); | ||
expect(validateServerSecurity(parsedInput, inputString, input, specialSecTypes)).to.equal(true); | ||
}); | ||
it('should successfully validate if server security not provided', async function() { | ||
@@ -588,62 +548,2 @@ const inputString = `{ | ||
it('should throw error that server security is missing scopes that are required for special security types like oauth2 and openIdConnect', async function() { | ||
const inputString = `{ | ||
"asyncapi": "2.0.0", | ||
"info": { | ||
"version": "1.0.0" | ||
}, | ||
"servers": { | ||
"dummy": { | ||
"url": "http://localhost", | ||
"protocol": "kafka", | ||
"security": [ | ||
{ | ||
"oauthsec": [] | ||
} | ||
] | ||
} | ||
}, | ||
"components": { | ||
"securitySchemes": { | ||
"oauthsec": { | ||
"type": "oauth2", | ||
"flows": { | ||
"implicit": { | ||
"authorizationUrl": "https://example.com/api/oauth/auth", | ||
"refreshUrl": "https://example.com/api/oauth/refresh", | ||
"scopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
const parsedInput = JSON.parse(inputString); | ||
try { | ||
validateServerSecurity(parsedInput, inputString, input, specialSecTypes); | ||
} catch (e) { | ||
expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); | ||
expect(e.title).to.equal('Server security value must not be an empty array if corresponding security schema type is oauth2 or openIdConnect. Add list of required scopes.'); | ||
expect(e.parsedJSON).to.deep.equal(parsedInput); | ||
expect(e.validationErrors).to.deep.equal([ | ||
{ | ||
title: 'dummy/security/oauthsec security info must not have an empty array because its corresponding security schema type is: oauth2', | ||
location: { | ||
jsonPointer: '/servers/dummy/security/oauthsec', | ||
startLine: 12, | ||
startColumn: 28, | ||
startOffset: offset(251, 12), | ||
endLine: 12, | ||
endColumn: 30, | ||
endOffset: offset(253, 12) | ||
} | ||
} | ||
]); | ||
} | ||
}); | ||
it('should throw error that server has no security schema provided when components schema object is not in the document', async function() { | ||
@@ -650,0 +550,0 @@ const inputString = `{ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1119544
9595