зеркало из https://github.com/Azure/sway.git
Update x-ms-secret validation logic for live validation (#86)
* Update live validation logic for "x-ms-secret", specifically, check if x-ms-secret is "true" in the response. If so, throw an error
This commit is contained in:
Родитель
b3798c1795
Коммит
ece6f1bc98
|
@ -216,8 +216,9 @@ function checkSecretPropertyInResponse (validateOptions, schema, json, report) {
|
||||||
|
|
||||||
var isResponse = validateOptions && validateOptions.isResponse
|
var isResponse = validateOptions && validateOptions.isResponse
|
||||||
var xMsSecret = schema && schema['x-ms-secret']
|
var xMsSecret = schema && schema['x-ms-secret']
|
||||||
|
var isXmsSecretTrue = xMsSecret && typeof xMsSecret === 'string' && xMsSecret.toLowerCase() === 'true'
|
||||||
|
|
||||||
if (isResponse && schema && xMsSecret && json !== undefined) {
|
if (isResponse && schema && isXmsSecretTrue && json !== undefined) {
|
||||||
let errorMessage = 'Secret property `"{0}": ';
|
let errorMessage = 'Secret property `"{0}": ';
|
||||||
|
|
||||||
if (schema && schema.type === 'string' && typeof json === 'string') {
|
if (schema && schema.type === 'string' && typeof json === 'string') {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "yasway",
|
"name": "yasway",
|
||||||
"version": "1.8.7",
|
"version": "1.8.8",
|
||||||
"description": "A library that simplifies Swagger integrations.",
|
"description": "A library that simplifies Swagger integrations.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
|
|
|
@ -682,7 +682,10 @@ definitions:
|
||||||
- "sold"
|
- "sold"
|
||||||
secret:
|
secret:
|
||||||
type: "string"
|
type: "string"
|
||||||
x-ms-secret: ["secret"]
|
x-ms-secret: "true"
|
||||||
|
nonSecret:
|
||||||
|
type: "string"
|
||||||
|
x-ms-secret: "false"
|
||||||
writeOnly:
|
writeOnly:
|
||||||
type: "string"
|
type: "string"
|
||||||
x-ms-mutability: ["create", "update"]
|
x-ms-mutability: ["create", "update"]
|
||||||
|
|
|
@ -153,6 +153,12 @@ describe('Response', function () {
|
||||||
secret: 'password'
|
secret: 'password'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nonSecretPet = {
|
||||||
|
name: 'Test Pet',
|
||||||
|
photoUrls: [],
|
||||||
|
nonSecret: 'notAnySecret'
|
||||||
|
}
|
||||||
|
|
||||||
describe('validate Content-Type', function () {
|
describe('validate Content-Type', function () {
|
||||||
describe('operation level produces', function () {
|
describe('operation level produces', function () {
|
||||||
var cSway;
|
var cSway;
|
||||||
|
@ -649,7 +655,7 @@ describe('Response', function () {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test if response has secret property marked with x-ms-secret', function (done) {
|
it('Test if response has secret property marked with x-ms-secret that equals to TRUE', function (done) {
|
||||||
var cSwaggerDoc = _.cloneDeep(helpers.swaggerDoc);
|
var cSwaggerDoc = _.cloneDeep(helpers.swaggerDoc);
|
||||||
|
|
||||||
Sway.create({
|
Sway.create({
|
||||||
|
@ -685,6 +691,30 @@ describe('Response', function () {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Test if response has secret property marked with x-ms-secret that equals to FALSE', function (done) {
|
||||||
|
var cSwaggerDoc = _.cloneDeep(helpers.swaggerDoc);
|
||||||
|
|
||||||
|
Sway.create({
|
||||||
|
definition: cSwaggerDoc
|
||||||
|
})
|
||||||
|
.then(function (api) {
|
||||||
|
var results = api.getOperation('/pet/{petId}', 'get').validateResponse({
|
||||||
|
body: nonSecretPet,
|
||||||
|
encoding: 'utf-8',
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
statusCode: 200
|
||||||
|
});
|
||||||
|
|
||||||
|
// should not return any errors
|
||||||
|
assert.deepEqual(results.errors, []);
|
||||||
|
assert.equal(results.warnings.length, 0);
|
||||||
|
})
|
||||||
|
.then(done, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Test if response has WRITE only property marked with x-ms-mutability', function (done) {
|
it('Test if response has WRITE only property marked with x-ms-mutability', function (done) {
|
||||||
var cSwaggerDoc = _.cloneDeep(helpers.swaggerDoc);
|
var cSwaggerDoc = _.cloneDeep(helpers.swaggerDoc);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче