Skip to content

Commit

Permalink
[KeyVault] - Enable multi-version tests for KV admin (#19956)
Browse files Browse the repository at this point in the history
Added support for multi-version testing for keyvault-admin.

Resolves #19791
  • Loading branch information
sadasant authored Jan 25, 2022
1 parent 68cc258 commit 0c4d2af
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 16 deletions.
12 changes: 10 additions & 2 deletions sdk/keyvault/keyvault-admin/platform-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@
"ArmTemplateParameters": "@{ enableHsm = $true }"
}
},
"TestType": "node",
"NodeTestVersion": "12.x"
"Versions": {
"12.x": {
"NodeTestVersion": "12.x"
},
"16.x_service_version_7_2": {
"NodeTestVersion": "16.x",
"ServiceVersion": "7.2"
}
},
"TestType": "node"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { env, Recorder } from "@azure-tools/test-recorder";
import { AbortController } from "@azure/abort-controller";

import { KeyVaultAccessControlClient } from "../../src";
import { assertThrowsAbortError } from "../utils/common";
import { assertThrowsAbortError, getServiceVersion } from "../utils/common";
import { authenticate } from "../utils/authentication";

describe("Aborting KeyVaultAccessControlClient's requests", () => {
Expand All @@ -15,7 +15,7 @@ describe("Aborting KeyVaultAccessControlClient's requests", () => {
const globalScope = "/";

beforeEach(async function () {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
client = authentication.accessControlClient;
recorder = authentication.recorder;
generateFakeUUID = authentication.generateFakeUUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "../../src";
import { authenticate } from "../utils/authentication";
import { supportsTracing } from "../utils/supportsTracing";
import { getServiceVersion } from "../utils/common";

describe("KeyVaultAccessControlClient", () => {
let client: KeyVaultAccessControlClient;
Expand All @@ -23,7 +24,7 @@ describe("KeyVaultAccessControlClient", () => {
const globalScope = "/";

beforeEach(async function () {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
client = authentication.accessControlClient;
recorder = authentication.recorder;
generateFakeUUID = authentication.generateFakeUUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AbortController } from "@azure/abort-controller";
import { KeyVaultBackupClient } from "../../src";
import { authenticate } from "../utils/authentication";
import { testPollerProperties } from "../utils/recorder";
import { assertThrowsAbortError, getSasToken } from "../utils/common";
import { assertThrowsAbortError, getSasToken, getServiceVersion } from "../utils/common";

describe("Aborting KeyVaultBackupClient's requests", () => {
let client: KeyVaultBackupClient;
Expand All @@ -18,7 +18,7 @@ describe("Aborting KeyVaultBackupClient's requests", () => {
let generateFakeUUID: () => string;

beforeEach(async function () {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
client = authentication.backupClient;
recorder = authentication.recorder;
generateFakeUUID = authentication.generateFakeUUID;
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/keyvault-admin/test/public/backupClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isPlaybackMode, Recorder } from "@azure-tools/test-recorder";
import { KeyVaultBackupClient } from "../../src";
import { authenticate } from "../utils/authentication";
import { testPollerProperties } from "../utils/recorder";
import { getSasToken } from "../utils/common";
import { getSasToken, getServiceVersion } from "../utils/common";
import { delay } from "@azure/core-util";
import { assert } from "chai";
import { KeyClient } from "@azure/keyvault-keys";
Expand All @@ -23,7 +23,7 @@ describe("KeyVaultBackupClient", () => {
let blobSasToken: string;

beforeEach(async function () {
const authentication = await authenticate(this);
const authentication = await authenticate(this, getServiceVersion());
client = authentication.backupClient;
keyClient = authentication.keyClient;
recorder = authentication.recorder;
Expand Down
16 changes: 11 additions & 5 deletions sdk/keyvault/keyvault-admin/test/utils/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import { ClientSecretCredential } from "@azure/identity";
import { env, isPlaybackMode, record, RecorderEnvironmentSetup } from "@azure-tools/test-recorder";
import { KeyClient } from "@azure/keyvault-keys";
import { v4 as uuidv4 } from "uuid";
import { Context } from "mocha";

import { KeyVaultAccessControlClient, KeyVaultBackupClient } from "../../src";
import { uniqueString } from "./recorder";
import { getEnvironmentVariable } from "./common";
import { getEnvironmentVariable, getServiceVersion } from "./common";

export async function authenticate(that: any): Promise<any> {
export async function authenticate(
that: Context,
serviceVersion: ReturnType<typeof getServiceVersion>
): Promise<any> {
const generatedUUIDs: string[] = [];
function generateFakeUUID(): string {
if (isPlaybackMode()) {
Expand Down Expand Up @@ -69,9 +73,11 @@ export async function authenticate(that: any): Promise<any> {

const keyVaultHsmUrl = getEnvironmentVariable("AZURE_MANAGEDHSM_URI");

const accessControlClient = new KeyVaultAccessControlClient(keyVaultHsmUrl, credential);
const keyClient = new KeyClient(keyVaultHsmUrl, credential);
const backupClient = new KeyVaultBackupClient(keyVaultHsmUrl, credential);
const accessControlClient = new KeyVaultAccessControlClient(keyVaultHsmUrl, credential, {
serviceVersion,
});
const keyClient = new KeyClient(keyVaultHsmUrl, credential, { serviceVersion });
const backupClient = new KeyVaultBackupClient(keyVaultHsmUrl, credential, { serviceVersion });

return { recorder, accessControlClient, backupClient, keyClient, suffix, generateFakeUUID };
}
30 changes: 30 additions & 0 deletions sdk/keyvault/keyvault-admin/test/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import { assert } from "chai";
import { env } from "@azure-tools/test-recorder";
import { SupportedVersions, supports, TestFunctionWrapper } from "@azure/test-utils";
import { LATEST_API_VERSION, SUPPORTED_API_VERSIONS } from "../../src/constants";

export async function assertThrowsAbortError(cb: () => Promise<any>): Promise<void> {
let passed = false;
Expand Down Expand Up @@ -56,3 +58,31 @@ export function getSasToken() {

return { blobStorageUri, blobSasToken };
}

/**
* The known API versions that we support.
*/
export const serviceVersions = ["7.2"] as const;

/**
* Fetches the service version to test against. This version could be configured as part of CI
* and then passed through the environment in order to support testing prior service versions.
* @returns - The service version to test
*/
export function getServiceVersion(): SUPPORTED_API_VERSIONS {
return env.SERVICE_VERSION || LATEST_API_VERSION;
}

/**
* A convenience wrapper allowing us to limit service versions without using the `versionsToTest` wrapper.
*
* @param supportedVersions - The {@link SupportedVersions} to limit this test against.
* @param serviceVersion - The service version we want to test support for. If omitted we will default to the version returned from {@link getServiceVersion}.
* @returns A Mocha Wrapper which will skip or execute the chained tests depending the currently tested service version and the supported versions.
*/
export function onVersions(
supportedVersions: SupportedVersions,
serviceVersion?: SUPPORTED_API_VERSIONS
): TestFunctionWrapper {
return supports(serviceVersion || getServiceVersion(), supportedVersions, serviceVersions);
}
4 changes: 2 additions & 2 deletions sdk/keyvault/keyvault-admin/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ stages:
PackageName: "@azure/keyvault-admin"
ServiceDirectory: keyvault
# KV HSM limitation prevents us from running live tests
# against multiple platforms in parallel (we're limited to a single
# instance per region per subscription) so we're only running
# against multiple platforms in parallel (we're limited to five
# instances per region per subscription) so we're only running
# live tests against a single instance.
Location: eastus2
MatrixConfigs:
Expand Down

0 comments on commit 0c4d2af

Please sign in to comment.