Skip to content

Commit 19d0468

Browse files
authored
[Identity] Fixing certificate test inconsistencies, including min-max live tests. (Azure#19810)
* skipping if the certificacte file cant be found * error details * what if we use a fake http client to prevent requests to resolve too fast * ok also skipping if the file isnt found * lint fix
1 parent 78f849d commit 19d0468

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

sdk/identity/identity/test/public/node/clientCertificateCredential.spec.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
55

66
import * as path from "path";
7+
import fs from "fs";
78
import { assert } from "chai";
89
import { AbortController } from "@azure/abort-controller";
910
import { env, isPlaybackMode, delay, isLiveMode } from "@azure-tools/test-recorder";
1011
import { MsalTestCleanup, msalNodeTestSetup, testTracing } from "../../msalTestUtils";
1112
import { ClientCertificateCredential } from "../../../src";
1213
import { Context } from "mocha";
1314
import { readFileSync } from "fs";
15+
import { PipelineRequest, PipelineResponse } from "@azure/core-rest-pipeline";
1416

1517
const ASSET_PATH = "assets";
1618

@@ -82,10 +84,27 @@ describe("ClientCertificateCredential", function () {
8284
assert.ok(token?.expiresOnTimestamp! > Date.now());
8385
});
8486

85-
it("allows cancelling the authentication", async function () {
86-
const credential = new ClientCertificateCredential(env.AZURE_TENANT_ID, env.AZURE_CLIENT_ID, {
87-
certificatePath,
88-
});
87+
it("allows cancelling the authentication", async function (this: Context) {
88+
if (!fs.existsSync(certificatePath)) {
89+
// In min-max tests, the certificate file can't be found.
90+
console.log("Failed to locate the certificate file. Skipping.");
91+
this.skip();
92+
}
93+
const credential = new ClientCertificateCredential(
94+
env.AZURE_TENANT_ID,
95+
env.AZURE_CLIENT_ID,
96+
{
97+
certificatePath,
98+
},
99+
{
100+
httpClient: {
101+
async sendRequest(_request: PipelineRequest): Promise<PipelineResponse> {
102+
await delay(100);
103+
throw new Error("Fake HTTP client.");
104+
},
105+
},
106+
}
107+
);
89108

90109
const controller = new AbortController();
91110
const getTokenPromise = credential.getToken(scope, {

0 commit comments

Comments
 (0)