Skip to content

Commit 12b1941

Browse files
authored
[KeyVault] - Enable multi-version tests for KV secrets (Azure#19354)
## What - Add support for multi-version testing for keyvault-secrets ## Why Our commitment is to support the last N versions of the KeyVault service. To ensure neither we nor the service introduce breaking changes to prior versions, multi-version test support was added. We ported keys over and have already reaped the benefits of version based filtering. This commit adds the same support for keyvault-secrets Resolves Azure#17892
1 parent 4257a1c commit 12b1941

File tree

10 files changed

+73
-13
lines changed

10 files changed

+73
-13
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"include": [
3+
{
4+
"Agent": {
5+
"ubuntu-20.04": {
6+
"OSVmImage": "MMSUbuntu20.04",
7+
"Pool": "azsdk-pool-mms-ubuntu-2004-general"
8+
}
9+
},
10+
"TestType": "node",
11+
"NodeTestVersion": "16.x",
12+
"ServiceVersion": ["7.0", "7.1", "7.2"]
13+
}
14+
],
15+
"displayNames": {
16+
"7.0": "service_version_7_0",
17+
"7.1": "service_version_7_1",
18+
"7.2": "service_version_7_2"
19+
}
20+
}

sdk/keyvault/keyvault-secrets/test/internal/challengeBasedAuthenticationPolicy.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { authenticate } from "../utils/testAuthentication";
1717
import TestClient from "../utils/testClient";
1818
import { ClientSecretCredential } from "@azure/identity";
1919
import { WebResource } from "@azure/core-http";
20+
import { getServiceVersion } from "../utils/utils.common";
2021

2122
// Following the philosophy of not testing the insides if we can test the outsides...
2223
// I present you with this "Get Out of Jail Free" card (in reference to Monopoly).
@@ -31,7 +32,7 @@ describe("Challenge based authentication tests", () => {
3132
let recorder: Recorder;
3233

3334
beforeEach(async function(this: Context) {
34-
const authentication = await authenticate(this);
35+
const authentication = await authenticate(this, getServiceVersion());
3536
secretSuffix = authentication.secretSuffix;
3637
client = authentication.client;
3738
testClient = authentication.testClient;

sdk/keyvault/keyvault-secrets/test/public/CRUD.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { env, Recorder } from "@azure-tools/test-recorder";
88
import { AbortController } from "@azure/abort-controller";
99

1010
import { SecretClient } from "../../src";
11-
import { assertThrowsAbortError } from "../utils/utils.common";
11+
import { assertThrowsAbortError, getServiceVersion } from "../utils/utils.common";
1212
import { testPollerProperties } from "../utils/recorderUtils";
1313
import { authenticate } from "../utils/testAuthentication";
1414
import TestClient from "../utils/testClient";
@@ -22,7 +22,7 @@ describe("Secret client - create, read, update and delete operations", () => {
2222
let recorder: Recorder;
2323

2424
beforeEach(async function(this: Context) {
25-
const authentication = await authenticate(this);
25+
const authentication = await authenticate(this, getServiceVersion());
2626
secretSuffix = authentication.secretSuffix;
2727
client = authentication.client;
2828
testClient = authentication.testClient;

sdk/keyvault/keyvault-secrets/test/public/list.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import chai from "chai";
77
import { env, Recorder, isRecordMode } from "@azure-tools/test-recorder";
88

99
import { SecretClient } from "../../src";
10-
import { assertThrowsAbortError } from "../utils/utils.common";
10+
import { assertThrowsAbortError, getServiceVersion } from "../utils/utils.common";
1111
import { testPollerProperties } from "../utils/recorderUtils";
1212
import { authenticate } from "../utils/testAuthentication";
1313
import TestClient from "../utils/testClient";
@@ -23,7 +23,7 @@ describe("Secret client - list secrets in various ways", () => {
2323
let recorder: Recorder;
2424

2525
beforeEach(async function(this: Context) {
26-
const authentication = await authenticate(this);
26+
const authentication = await authenticate(this, getServiceVersion());
2727
secretSuffix = authentication.secretSuffix;
2828
client = authentication.client;
2929
testClient = authentication.testClient;

sdk/keyvault/keyvault-secrets/test/public/lro.delete.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { env, Recorder } from "@azure-tools/test-recorder";
77
import { PollerStoppedError } from "@azure/core-lro";
88

99
import { SecretClient, DeletedSecret } from "../../src";
10-
import { assertThrowsAbortError } from "../utils/utils.common";
10+
import { assertThrowsAbortError, getServiceVersion } from "../utils/utils.common";
1111
import { testPollerProperties } from "../utils/recorderUtils";
1212
import { authenticate } from "../utils/testAuthentication";
1313
import TestClient from "../utils/testClient";
@@ -20,7 +20,7 @@ describe("Secrets client - Long Running Operations - delete", () => {
2020
let recorder: Recorder;
2121

2222
beforeEach(async function(this: Context) {
23-
const authentication = await authenticate(this);
23+
const authentication = await authenticate(this, getServiceVersion());
2424
secretSuffix = authentication.secretSuffix;
2525
client = authentication.client;
2626
testClient = authentication.testClient;

sdk/keyvault/keyvault-secrets/test/public/lro.recover.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { env, Recorder } from "@azure-tools/test-recorder";
77
import { PollerStoppedError } from "@azure/core-lro";
88

99
import { SecretClient, SecretProperties } from "../../src";
10-
import { assertThrowsAbortError } from "../utils/utils.common";
10+
import { assertThrowsAbortError, getServiceVersion } from "../utils/utils.common";
1111
import { testPollerProperties } from "../utils/recorderUtils";
1212
import { authenticate } from "../utils/testAuthentication";
1313
import TestClient from "../utils/testClient";
@@ -20,7 +20,7 @@ describe("Secrets client - Long Running Operations - recoverDelete", () => {
2020
let recorder: Recorder;
2121

2222
beforeEach(async function(this: Context) {
23-
const authentication = await authenticate(this);
23+
const authentication = await authenticate(this, getServiceVersion());
2424
secretSuffix = authentication.secretSuffix;
2525
client = authentication.client;
2626
testClient = authentication.testClient;

sdk/keyvault/keyvault-secrets/test/public/recoverBackupRestore.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isNode } from "@azure/core-http";
77
import { env, isPlaybackMode, Recorder, isRecordMode } from "@azure-tools/test-recorder";
88

99
import { SecretClient } from "../../src";
10-
import { assertThrowsAbortError } from "../utils/utils.common";
10+
import { assertThrowsAbortError, getServiceVersion } from "../utils/utils.common";
1111
import { testPollerProperties } from "../utils/recorderUtils";
1212
import { authenticate } from "../utils/testAuthentication";
1313
import TestClient from "../utils/testClient";
@@ -20,7 +20,7 @@ describe("Secret client - restore secrets and recover backups", () => {
2020
let recorder: Recorder;
2121

2222
beforeEach(async function(this: Context) {
23-
const authentication = await authenticate(this);
23+
const authentication = await authenticate(this, getServiceVersion());
2424
secretSuffix = authentication.secretSuffix;
2525
client = authentication.client;
2626
testClient = authentication.testClient;

sdk/keyvault/keyvault-secrets/test/utils/testAuthentication.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import { env, record, RecorderEnvironmentSetup } from "@azure-tools/test-recorde
77
import { uniqueString } from "./recorderUtils";
88
import TestClient from "./testClient";
99
import { Context } from "mocha";
10+
import { getServiceVersion } from "./utils.common";
1011

11-
export async function authenticate(that: Context): Promise<any> {
12+
export async function authenticate(
13+
that: Context,
14+
serviceVersion: ReturnType<typeof getServiceVersion>
15+
): Promise<any> {
1216
const secretSuffix = uniqueString();
1317
const recorderEnvSetup: RecorderEnvironmentSetup = {
1418
replaceableVariables: {
@@ -41,7 +45,7 @@ export async function authenticate(that: Context): Promise<any> {
4145
throw new Error("Missing KEYVAULT_URI environment variable.");
4246
}
4347

44-
const client = new SecretClient(keyVaultUrl, credential);
48+
const client = new SecretClient(keyVaultUrl, credential, { serviceVersion });
4549
const testClient = new TestClient(client);
4650

4751
return { recorder, client, testClient, secretSuffix, credential };

sdk/keyvault/keyvault-secrets/test/utils/utils.common.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Licensed under the MIT license.
33

44
import { assert } from "chai";
5+
import { SupportedVersions, supports, TestFunctionWrapper } from "@azure/test-utils";
6+
import { env } from "@azure-tools/test-recorder";
7+
import { LATEST_API_VERSION, SecretClientOptions } from "../../src/secretsModels";
58

69
export async function assertThrowsAbortError(cb: () => Promise<any>): Promise<void> {
710
let passed = false;
@@ -18,3 +21,30 @@ export async function assertThrowsAbortError(cb: () => Promise<any>): Promise<vo
1821
throw new Error("Expected cb to throw an AbortError");
1922
}
2023
}
24+
/**
25+
* The known API versions that we support.
26+
*/
27+
export const serviceVersions = ["7.0", "7.1", "7.2", "7.3-preview"] as const;
28+
29+
/**
30+
* Fetches the service version to test against. This version could be configured as part of CI
31+
* and then passed through the environment in order to support testing prior service versions.
32+
* @returns - The service version to test
33+
*/
34+
export function getServiceVersion(): NonNullable<SecretClientOptions["serviceVersion"]> {
35+
return env.SERVICE_VERSION || LATEST_API_VERSION;
36+
}
37+
38+
/**
39+
* A convenience wrapper allowing us to limit service versions without using the `versionsToTest` wrapper.
40+
*
41+
* @param supportedVersions - The {@link SupportedVersions} to limit this test against.
42+
* @param serviceVersion - The service version we want to test support for. If omitted we will default to the version returned from {@link getServiceVersion}.
43+
* @returns A Mocha Wrapper which will skip or execute the chained tests depending the currently tested service version and the supported versions.
44+
*/
45+
export function onVersions(
46+
supportedVersions: SupportedVersions,
47+
serviceVersion?: SecretClientOptions["serviceVersion"]
48+
): TestFunctionWrapper {
49+
return supports(serviceVersion || getServiceVersion(), supportedVersions, serviceVersions);
50+
}

sdk/keyvault/keyvault-secrets/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ stages:
77
ServiceDirectory: keyvault
88
TimeoutInMinutes: 59
99
SupportedClouds: 'Public,UsGov,China'
10+
AdditionalMatrixConfigs:
11+
- Name: Keyvault_live_test_base
12+
Path: sdk/keyvault/keyvault-secrets/platform-matrix.json
13+
Selection: sparse
14+
GenerateVMJobs: true
1015
EnvVars:
1116
AZURE_CLIENT_ID: $(KEYVAULT_CLIENT_ID)
1217
AZURE_TENANT_ID: $(KEYVAULT_TENANT_ID)

0 commit comments

Comments
 (0)