Skip to content

Commit 7d34a6c

Browse files
authored
[KeyVault] - Add multi-version tests for KeyVault Keys (Azure#14587)
## What - Adds support for live testing multiple service versions - Adds the matrix config and plumbing to pass service version as an environment variable - Adds a helper method to support skipping tests when the service version isn't supported ## Why KeyVault currently supports three service versions: 7.0, 7.1, and 7.2. Being able to ensure our live tests run against previous service versions is a way to future proof ourselves and allow us to ensure continued support. After a bit of discussion we agreed that it would be worthwhile to add the indirection of passing the service version as an environment variable and avoid having to run all service versions tests in sequence.
1 parent 5150d7b commit 7d34a6c

20 files changed

+384
-331
lines changed

eng/pipelines/templates/jobs/archetype-sdk-integration.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ jobs:
132132
condition: and(succeededOrFailed(),ne(variables['TestType'],'sample'),eq(variables['DependencyVersion'],''))
133133
env:
134134
TEST_MODE: "live"
135+
SERVICE_VERSION: $(ServiceVersion)
135136
${{ insert }}: ${{ parameters.EnvVars }}
136137
137138
- script: |
@@ -141,6 +142,7 @@ jobs:
141142
condition: and(succeeded(),ne(variables['TestType'],'sample'),ne(variables['DependencyVersion'],''))
142143
env:
143144
TEST_MODE: "live"
145+
SERVICE_VERSION: $(ServiceVersion)
144146
${{ insert }}: ${{ parameters.EnvVars }}
145147
146148
- ${{ parameters.PostSteps }}

eng/pipelines/templates/variables/globals.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ variables:
44
OSVmImage: "ubuntu-18.04"
55
skipComponentGovernanceDetection: true
66
coalesceResultFilter: $[ coalesce(variables['packageGlobFilter'], '**') ]
7+
ServiceVersion: ""

sdk/keyvault/keyvault-keys/platform-matrix.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
},
1111
"TestType": "node",
1212
"NodeTestVersion": "10.x"
13+
},
14+
{
15+
"Agent": {
16+
"ubuntu-18.04": {
17+
"OSVmImage": "MMSUbuntu18.04",
18+
"Pool": "azsdk-pool-mms-ubuntu-1804-general"
19+
}
20+
},
21+
"TestType": "node",
22+
"NodeTestVersion": "10.x",
23+
"ServiceVersion": ["7.0", "7.1"]
1324
}
14-
]
25+
],
26+
"displayNames": {
27+
"7.0": "service_version_7_0",
28+
"7.1": "service_version_7_1"
29+
}
1530
}

sdk/keyvault/keyvault-keys/review/keyvault-keys.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class KeyClient {
232232

233233
// @public
234234
export interface KeyClientOptions extends coreHttp.PipelineOptions {
235-
serviceVersion?: "7.0" | "7.1" | "7.2";
235+
serviceVersion?: string;
236236
}
237237

238238
// @public

sdk/keyvault/keyvault-keys/src/keysModels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export const LATEST_API_VERSION = "7.2";
2323
*/
2424
export interface KeyClientOptions extends coreHttp.PipelineOptions {
2525
/**
26-
* The accepted versions of the KeyVault's service API.
26+
* The version of the KeyVault's service API to make calls against.
2727
*/
28-
serviceVersion?: "7.0" | "7.1" | "7.2";
28+
serviceVersion?: string;
2929
}
3030

3131
/**

sdk/keyvault/keyvault-keys/test/internal/aesCryptography.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { authenticate } from "../utils/testAuthentication";
1818
import { env, Recorder } from "@azure/test-utils-recorder";
1919
import { RemoteCryptographyProvider } from "../../src/cryptography/remoteCryptographyProvider";
2020
import { ClientSecretCredential } from "@azure/identity";
21+
import { getServiceVersion } from "../utils/utils.common";
2122

2223
describe("AesCryptographyProvider browser tests", function() {
2324
it("uses the browser replacement when running in the browser", async function(this: Context) {
@@ -134,7 +135,7 @@ describe("AesCryptographyProvider internal tests", function() {
134135
let remoteProvider: RemoteCryptographyProvider;
135136

136137
beforeEach(async function(this: Context) {
137-
const authentication = await authenticate(this);
138+
const authentication = await authenticate(this, getServiceVersion());
138139
recorder = authentication.recorder;
139140

140141
if (!authentication.hsmClient) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { KeyClient } from "../../src";
1515
import { authenticate } from "../utils/testAuthentication";
1616
import TestClient from "../utils/testClient";
17+
import { getServiceVersion } from "../utils/utils.common";
1718

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

3031
beforeEach(async function(this: Context) {
31-
const authentication = await authenticate(this);
32+
const authentication = await authenticate(this, getServiceVersion());
3233
keySuffix = authentication.keySuffix;
3334
client = authentication.client;
3435
testClient = authentication.testClient;

sdk/keyvault/keyvault-keys/test/internal/serviceVersionParameter.spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { LATEST_API_VERSION } from "../../src/keysModels";
88
import { HttpClient, HttpOperationResponse, WebResourceLike, HttpHeaders } from "@azure/core-http";
99
import { ClientSecretCredential } from "@azure/identity";
1010
import { env } from "@azure/test-utils-recorder";
11+
import { versionsToTest } from "@azure/test-utils-multi-version";
12+
import { serviceVersions } from "../utils/utils.common";
1113

1214
describe("The Keys client should set the serviceVersion", () => {
1315
const keyVaultUrl = `https://keyVaultName.vault.azure.net`;
@@ -58,14 +60,10 @@ describe("The Keys client should set the serviceVersion", () => {
5860
);
5961
});
6062

61-
// Adding this to the source would change the public API.
62-
type ApIVersions = "7.0" | "7.1" | "7.2";
63-
64-
it("it should allow us to specify an API version from a specific set of versions", async function() {
65-
const versions: ApIVersions[] = ["7.0", "7.1", "7.2"];
66-
for (const serviceVersion in versions) {
63+
versionsToTest(serviceVersions, {}, (serviceVersion) => {
64+
it("it should allow us to specify an API version from a specific set of versions", async function() {
6765
const client = new KeyClient(keyVaultUrl, credential, {
68-
serviceVersion: serviceVersion as ApIVersions,
66+
serviceVersion: serviceVersion,
6967
httpClient: mockHttpClient
7068
});
7169
await client.createKey("keyName", "RSA");
@@ -76,6 +74,6 @@ describe("The Keys client should set the serviceVersion", () => {
7674
lastCall.args[0].url,
7775
`https://keyVaultName.vault.azure.net/keys/keyName/create?api-version=${serviceVersion}`
7876
);
79-
}
77+
});
8078
});
8179
});

sdk/keyvault/keyvault-keys/test/public/CRUD.hsm.spec.ts

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,45 @@ import { KeyClient } from "../../src";
99
import { authenticate } from "../utils/testAuthentication";
1010
import TestClient from "../utils/testClient";
1111
import { CreateOctKeyOptions } from "../../src/keysModels";
12-
13-
describe("Keys client - create, read, update and delete operations for managed HSM", () => {
14-
const keyPrefix = `CRUD${env.KEY_NAME || "KeyName"}`;
15-
let keySuffix: string;
16-
let hsmClient: KeyClient;
17-
let testClient: TestClient;
18-
let recorder: Recorder;
19-
20-
beforeEach(async function(this: Context) {
21-
const authentication = await authenticate(this);
22-
recorder = authentication.recorder;
23-
24-
if (!authentication.hsmClient) {
25-
// Managed HSM is not deployed for this run due to service resource restrictions so we skip these tests.
26-
// This is only necessary while Managed HSM is in preview.
27-
this.skip();
28-
}
29-
30-
hsmClient = authentication.hsmClient;
31-
keySuffix = authentication.keySuffix;
32-
testClient = new TestClient(authentication.hsmClient);
33-
});
34-
35-
afterEach(async function() {
36-
await recorder.stop();
37-
});
38-
39-
it("can create an OCT key with options", async function(this: Context) {
40-
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
41-
const options: CreateOctKeyOptions = {
42-
hsm: true
43-
};
44-
const result = await hsmClient.createOctKey(keyName, options);
45-
assert.equal(result.name, keyName, "Unexpected key name in result from createKey().");
46-
assert.equal(result.keyType, "oct-HSM");
47-
await testClient.flushKey(keyName);
48-
});
49-
});
12+
import { getServiceVersion, onVersions } from "../utils/utils.common";
13+
14+
onVersions({ minVer: "7.2" }).describe(
15+
"Keys client - create, read, update and delete operations for managed HSM",
16+
() => {
17+
const keyPrefix = `CRUD${env.KEY_NAME || "KeyName"}`;
18+
let keySuffix: string;
19+
let hsmClient: KeyClient;
20+
let testClient: TestClient;
21+
let recorder: Recorder;
22+
23+
beforeEach(async function(this: Context) {
24+
const authentication = await authenticate(this, getServiceVersion());
25+
recorder = authentication.recorder;
26+
27+
if (!authentication.hsmClient) {
28+
// Managed HSM is not deployed for this run due to service resource restrictions so we skip these tests.
29+
// This is only necessary while Managed HSM is in preview.
30+
this.skip();
31+
}
32+
33+
hsmClient = authentication.hsmClient;
34+
keySuffix = authentication.keySuffix;
35+
testClient = new TestClient(authentication.hsmClient);
36+
});
37+
38+
afterEach(async function() {
39+
await recorder.stop();
40+
});
41+
42+
it("can create an OCT key with options", async function(this: Context) {
43+
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`);
44+
const options: CreateOctKeyOptions = {
45+
hsm: true
46+
};
47+
const result = await hsmClient.createOctKey(keyName, options);
48+
assert.equal(result.name, keyName, "Unexpected key name in result from createKey().");
49+
assert.equal(result.keyType, "oct-HSM");
50+
await testClient.flushKey(keyName);
51+
});
52+
}
53+
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
UpdateKeyPropertiesOptions,
1414
GetKeyOptions
1515
} from "../../src";
16-
import { assertThrowsAbortError } from "../utils/utils.common";
16+
import { assertThrowsAbortError, getServiceVersion } from "../utils/utils.common";
1717
import { testPollerProperties } from "../utils/recorderUtils";
1818
import { authenticate } from "../utils/testAuthentication";
1919
import TestClient from "../utils/testClient";
@@ -26,7 +26,7 @@ describe("Keys client - create, read, update and delete operations", () => {
2626
let recorder: Recorder;
2727

2828
beforeEach(async function(this: Context) {
29-
const authentication = await authenticate(this);
29+
const authentication = await authenticate(this, getServiceVersion());
3030
keySuffix = authentication.keySuffix;
3131
client = authentication.client;
3232
testClient = authentication.testClient;

0 commit comments

Comments
 (0)