|
4 | 4 | /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ |
5 | 5 |
|
6 | 6 | import * as path from "path"; |
| 7 | +import fs from "fs"; |
7 | 8 | import { assert } from "chai"; |
8 | 9 | import { AbortController } from "@azure/abort-controller"; |
9 | 10 | import { env, isPlaybackMode, delay, isLiveMode } from "@azure-tools/test-recorder"; |
10 | 11 | import { MsalTestCleanup, msalNodeTestSetup, testTracing } from "../../msalTestUtils"; |
11 | 12 | import { ClientCertificateCredential } from "../../../src"; |
12 | 13 | import { Context } from "mocha"; |
13 | 14 | import { readFileSync } from "fs"; |
| 15 | +import { PipelineRequest, PipelineResponse } from "@azure/core-rest-pipeline"; |
14 | 16 |
|
15 | 17 | const ASSET_PATH = "assets"; |
16 | 18 |
|
@@ -82,10 +84,27 @@ describe("ClientCertificateCredential", function () { |
82 | 84 | assert.ok(token?.expiresOnTimestamp! > Date.now()); |
83 | 85 | }); |
84 | 86 |
|
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 | + ); |
89 | 108 |
|
90 | 109 | const controller = new AbortController(); |
91 | 110 | const getTokenPromise = credential.getToken(scope, { |
|
0 commit comments