Port `arm`-specific changes into `develop` (#1025)

* bring all the accumulated changes from enable-armid-only branch
* update package version and npm update
* populate payload file
This commit is contained in:
Scott Beddall 2024-02-20 13:57:17 -08:00 коммит произвёл GitHub
Родитель cfd51d250a
Коммит 186bb06af3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
8 изменённых файлов: 548 добавлений и 295 удалений

Просмотреть файл

@ -1,5 +1,13 @@
# Change Log - oav
## 02/12/2024 3.3.3
- #1014 Set armId format validation to always enabled, but allow suppression of errors when `isArmCall` validator argument is set to `false`. Update the special casing on additionalProperties validation. This error was was erroneously skipping validation validation error when isArmCall is set to `true`. This value is _defaulted_ to `true` when used for `Model Validation` and `Semantic Validation`.
## 01/29/2024 3.3.2
- Remove `mockjs` dependency.
## 11/14/2023 3.3.1
- #1019 Fixing edge case caused by introduction of fake property `refWithReadOnly` used to handle `readonly` errors thrown when placed alongside a `ref` node in a swagger schema.

Просмотреть файл

@ -305,7 +305,7 @@ export const schemaValidateIssueToLiveValidationIssue = (
skipIssue = true;
return "";
}
} else if (issue.code === "INVALID_TYPE" && isArmCall === true) {
} else if (issue.code === "INVALID_TYPE" && isArmCall === false) {
// See Azure/oav#983 for additional information as to why this special case is present.
// RPs working with the RPaaS team were having dificulty with additionalProperties validation due to the fact
// that when we turned it on, a LOT of real, live requests were being rejected due to invalid additionalProperties settings.
@ -313,6 +313,8 @@ export const schemaValidateIssueToLiveValidationIssue = (
// We need oav to have the capability to skip this if we are invoking an arm call, but when we roll any new versions of OAV
// out to azure/azure-rest-api-specs, we need the errors actually pop there! When enough of the RPs have resolved this problem,
// we can re-enable loud failures in the validation image.
//
// Model and Semantic validation both run with isArmCall set to TRUE, so by setting FALSE a user will activate this special skip logic.
if (issue.schemaPath.includes("additionalProperties")) {
skipIssue = true;
if (logging) {
@ -327,6 +329,22 @@ export const schemaValidateIssueToLiveValidationIssue = (
}
return "";
}
} else if (
issue.code === "INVALID_FORMAT" &&
isArmCall === false &&
issue.message.includes("Object didn't pass validation for format arm-id")
) {
skipIssue = true;
if (logging) {
logging(
`armId format validation failed: ${JSON.stringify(issue, undefined, 2)}`,
LiveValidatorLoggingLevels.error,
LiveValidatorLoggingTypes.trace,
"Oav.OperationValidator.schemaValidateIssueToLiveValidationIssue",
undefined,
operationContext.validationRequest
);
}
}
const isMissingRequiredProperty = issue.code === "OBJECT_MISSING_REQUIRED_PROPERTY";

Просмотреть файл

@ -197,5 +197,4 @@ export const ajvEnableAll = (ajv: Ajv, jsonLoader: JsonLoader) => {
export const ajvEnableArmRule = (ajv: Ajv) => {
ajvEnableXmsAzureResource(ajv);
ajvEnableArmIdFormat(ajv);
};

Просмотреть файл

@ -23,7 +23,7 @@ import { getOavErrorMeta, TrafficValidationErrorCode } from "../util/errorDefini
import { Severity } from "../util/severity";
import { Writable } from "../util/utils";
import { SourceLocation } from "../util/validationError";
import { ajvEnableAll, ajvEnableArmRule } from "./ajv";
import { ajvEnableAll, ajvEnableArmRule, ajvEnableArmIdFormat } from "./ajv";
import {
getIncludeErrorsMap,
SchemaValidateContext,
@ -65,6 +65,9 @@ export class AjvSchemaValidator implements SchemaValidator {
});
ajvEnableAll(this.ajv, loader);
// always enable the armId format validation
ajvEnableArmIdFormat(this.ajv);
if (schemaValidatorOption?.isArmCall === true) {
ajvEnableArmRule(this.ajv);
}

772
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "oav",
"version": "3.3.2",
"version": "3.3.3",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",

Просмотреть файл

@ -0,0 +1,13 @@
{
"liveRequest": {
"method": "POST",
"url": "/format/armid"
},
"liveResponse": {
"statusCode": "200",
"body": {
"NotARMIDValue": "test123",
"ARMIDValue": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/abcd/providers/Microsoft.Compute/snapshots/snapshot"
}
}
}

Просмотреть файл

@ -1063,7 +1063,7 @@ describe("Live Validator", () => {
git: {
shouldClone: false,
},
isArmCall: true,
isArmCall: false,
};
const liveValidator = new LiveValidator(options);
await liveValidator.initialize();
@ -1072,6 +1072,26 @@ describe("Live Validator", () => {
assert.strictEqual(result.responseValidationResult.isSuccessful, true);
assert.strictEqual(result.requestValidationResult.isSuccessful, true);
});
it(`should only log error invalid format on arm-id if isArmCall is set to false`, async () => {
const options = {
directory: `${__dirname}/modelValidation/swaggers/`,
isPathCaseSensitive: false,
useRelativeSourceLocationUrl: true,
swaggerPathsPattern: [
"specification/formatValidation/format.json",
],
git: {
shouldClone: false,
},
isArmCall: false,
};
const liveValidator = new LiveValidator(options);
await liveValidator.initialize();
const payload = require(`${__dirname}/liveValidation/payloads/invalid_armid_format.json`);
const result = await liveValidator.validateLiveRequestResponse(payload);
assert.strictEqual(result.responseValidationResult.errors.some((err) => err.code === "INVALID_FORMAT"), false)
});
});
});
describe("Live validator snapshot validation", () => {