diff --git a/lib/msal-node/src/client/ManagedIdentityApplication.ts b/lib/msal-node/src/client/ManagedIdentityApplication.ts index 6208dfb002..f120d6286d 100644 --- a/lib/msal-node/src/client/ManagedIdentityApplication.ts +++ b/lib/msal-node/src/client/ManagedIdentityApplication.ts @@ -31,7 +31,10 @@ import { ClientCredentialClient } from "./ClientCredentialClient"; import { ManagedIdentityClient } from "./ManagedIdentityClient"; import { ManagedIdentityRequestParams } from "../request/ManagedIdentityRequestParams"; import { NodeStorage } from "../cache/NodeStorage"; -import { DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY } from "../utils/Constants"; +import { + AzureIdentitySdkManagedIdentitySourceNames, + DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY, +} from "../utils/Constants"; /** * Class to initialize a managed identity and identify the service @@ -183,4 +186,8 @@ export class ManagedIdentityApplication { ); } } + + public getManagedIdentitySource(): AzureIdentitySdkManagedIdentitySourceNames { + return this.managedIdentityClient.getManagedIdentitySource(); + } } diff --git a/lib/msal-node/src/client/ManagedIdentityClient.ts b/lib/msal-node/src/client/ManagedIdentityClient.ts index c2a74db1c5..d6bc1e7d00 100644 --- a/lib/msal-node/src/client/ManagedIdentityClient.ts +++ b/lib/msal-node/src/client/ManagedIdentityClient.ts @@ -23,6 +23,7 @@ import { ManagedIdentityRequest } from "../request/ManagedIdentityRequest"; import { ManagedIdentityId } from "../config/ManagedIdentityId"; import { NodeStorage } from "../cache/NodeStorage"; import { BaseManagedIdentitySource } from "./ManagedIdentitySources/BaseManagedIdentitySource"; +import { AzureIdentitySdkManagedIdentitySourceNames } from "../utils/Constants"; /* * Class to initialize a managed identity and identify the service. @@ -73,6 +74,40 @@ export class ManagedIdentityClient { ); } + private allEnvironmentVariablesAreDefined( + environmentVariables: Array + ): boolean { + return Object.values(environmentVariables).every( + (environmentVariable) => { + return environmentVariable !== undefined; + } + ); + } + + /** + * Determine the Managed Identity Source based on available environment variables. This API is consumed by Azure Identity SDK. + * @returns AzureIdentitySdkManagedIdentitySourceNames - Azure Identity SDK defined identifiers for the Managed Identity Sources + */ + public getManagedIdentitySource(): AzureIdentitySdkManagedIdentitySourceNames { + return this.allEnvironmentVariablesAreDefined( + ServiceFabric.getEnvironmentVariables() + ) + ? AzureIdentitySdkManagedIdentitySourceNames.SERVICE_FABRIC + : this.allEnvironmentVariablesAreDefined( + AppService.getEnvironmentVariables() + ) + ? AzureIdentitySdkManagedIdentitySourceNames.APP_SERVICE + : this.allEnvironmentVariablesAreDefined( + CloudShell.getEnvironmentVariables() + ) + ? AzureIdentitySdkManagedIdentitySourceNames.CLOUD_SHELL + : this.allEnvironmentVariablesAreDefined( + AzureArc.getEnvironmentVariables() + ) + ? AzureIdentitySdkManagedIdentitySourceNames.AZURE_ARC + : AzureIdentitySdkManagedIdentitySourceNames.IMDS; + } + /** * Tries to create a managed identity source for all sources * @returns the managed identity Source diff --git a/lib/msal-node/src/client/ManagedIdentitySources/AppService.ts b/lib/msal-node/src/client/ManagedIdentitySources/AppService.ts index 2300a2979e..8f4ac9ca4e 100644 --- a/lib/msal-node/src/client/ManagedIdentitySources/AppService.ts +++ b/lib/msal-node/src/client/ManagedIdentitySources/AppService.ts @@ -43,12 +43,7 @@ export class AppService extends BaseManagedIdentitySource { this.identityHeader = identityHeader; } - public static tryCreate( - logger: Logger, - nodeStorage: NodeStorage, - networkClient: INetworkModule, - cryptoProvider: CryptoProvider - ): AppService | null { + public static getEnvironmentVariables(): Array { const identityEndpoint: string | undefined = process.env[ ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT @@ -58,6 +53,18 @@ export class AppService extends BaseManagedIdentitySource { ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER ]; + return [identityEndpoint, identityHeader]; + } + + public static tryCreate( + logger: Logger, + nodeStorage: NodeStorage, + networkClient: INetworkModule, + cryptoProvider: CryptoProvider + ): AppService | null { + const [identityEndpoint, identityHeader] = + AppService.getEnvironmentVariables(); + // if either of the identity endpoint or identity header variables are undefined, this MSI provider is unavailable. if (!identityEndpoint || !identityHeader) { logger.info( diff --git a/lib/msal-node/src/client/ManagedIdentitySources/AzureArc.ts b/lib/msal-node/src/client/ManagedIdentitySources/AzureArc.ts index f0ae556004..779b958ea3 100644 --- a/lib/msal-node/src/client/ManagedIdentitySources/AzureArc.ts +++ b/lib/msal-node/src/client/ManagedIdentitySources/AzureArc.ts @@ -56,6 +56,17 @@ export class AzureArc extends BaseManagedIdentitySource { this.identityEndpoint = identityEndpoint; } + public static getEnvironmentVariables(): Array { + const identityEndpoint: string | undefined = + process.env[ + ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT + ]; + const imdsEndpoint: string | undefined = + process.env[ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT]; + + return [identityEndpoint, imdsEndpoint]; + } + public static tryCreate( logger: Logger, nodeStorage: NodeStorage, @@ -63,12 +74,8 @@ export class AzureArc extends BaseManagedIdentitySource { cryptoProvider: CryptoProvider, managedIdentityId: ManagedIdentityId ): AzureArc | null { - const identityEndpoint: string | undefined = - process.env[ - ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT - ]; - const imdsEndpoint: string | undefined = - process.env[ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT]; + const [identityEndpoint, imdsEndpoint] = + AzureArc.getEnvironmentVariables(); // if either of the identity or imds endpoints are undefined, this MSI provider is unavailable. if (!identityEndpoint || !imdsEndpoint) { diff --git a/lib/msal-node/src/client/ManagedIdentitySources/CloudShell.ts b/lib/msal-node/src/client/ManagedIdentitySources/CloudShell.ts index a62781d009..030823af32 100644 --- a/lib/msal-node/src/client/ManagedIdentitySources/CloudShell.ts +++ b/lib/msal-node/src/client/ManagedIdentitySources/CloudShell.ts @@ -40,6 +40,13 @@ export class CloudShell extends BaseManagedIdentitySource { this.msiEndpoint = msiEndpoint; } + public static getEnvironmentVariables(): Array { + const msiEndpoint: string | undefined = + process.env[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT]; + + return [msiEndpoint]; + } + public static tryCreate( logger: Logger, nodeStorage: NodeStorage, @@ -47,8 +54,7 @@ export class CloudShell extends BaseManagedIdentitySource { cryptoProvider: CryptoProvider, managedIdentityId: ManagedIdentityId ): CloudShell | null { - const msiEndpoint: string | undefined = - process.env[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT]; + const [msiEndpoint] = CloudShell.getEnvironmentVariables(); // if the msi endpoint environment variable is undefined, this MSI provider is unavailable. if (!msiEndpoint) { diff --git a/lib/msal-node/src/client/ManagedIdentitySources/ServiceFabric.ts b/lib/msal-node/src/client/ManagedIdentitySources/ServiceFabric.ts index 553d4259e7..c1c157e545 100644 --- a/lib/msal-node/src/client/ManagedIdentitySources/ServiceFabric.ts +++ b/lib/msal-node/src/client/ManagedIdentitySources/ServiceFabric.ts @@ -43,13 +43,7 @@ export class ServiceFabric extends BaseManagedIdentitySource { this.identityHeader = identityHeader; } - public static tryCreate( - logger: Logger, - nodeStorage: NodeStorage, - networkClient: INetworkModule, - cryptoProvider: CryptoProvider, - managedIdentityId: ManagedIdentityId - ): ServiceFabric | null { + public static getEnvironmentVariables(): Array { const identityEndpoint: string | undefined = process.env[ ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT @@ -64,6 +58,19 @@ export class ServiceFabric extends BaseManagedIdentitySource { .IDENTITY_SERVER_THUMBPRINT ]; + return [identityEndpoint, identityHeader, identityServerThumbprint]; + } + + public static tryCreate( + logger: Logger, + nodeStorage: NodeStorage, + networkClient: INetworkModule, + cryptoProvider: CryptoProvider, + managedIdentityId: ManagedIdentityId + ): ServiceFabric | null { + const [identityEndpoint, identityHeader, identityServerThumbprint] = + ServiceFabric.getEnvironmentVariables(); + /* * if either of the identity endpoint, identity header, or identity server thumbprint * environment variables are undefined, this MSI provider is unavailable. diff --git a/lib/msal-node/src/utils/Constants.ts b/lib/msal-node/src/utils/Constants.ts index ebb9328c77..946fc17f2b 100644 --- a/lib/msal-node/src/utils/Constants.ts +++ b/lib/msal-node/src/utils/Constants.ts @@ -43,6 +43,19 @@ export const ManagedIdentitySourceNames = { export type ManagedIdentitySourceNames = (typeof ManagedIdentitySourceNames)[keyof typeof ManagedIdentitySourceNames]; +/** + * Azure Identity SDK defined identifiers for the Managed Identity Sources + */ +export const AzureIdentitySdkManagedIdentitySourceNames = { + APP_SERVICE: "APP_SERVICE", + AZURE_ARC: "ARC", + CLOUD_SHELL: "CLOUD_SHELL", + IMDS: "DEFAULT_TO_VM", + SERVICE_FABRIC: "SERVICE_FABRIC", +} as const; +export type AzureIdentitySdkManagedIdentitySourceNames = + (typeof AzureIdentitySdkManagedIdentitySourceNames)[keyof typeof AzureIdentitySdkManagedIdentitySourceNames]; + /** * Managed Identity Ids */ diff --git a/lib/msal-node/test/client/ManagedIdentitySources/AppService.spec.ts b/lib/msal-node/test/client/ManagedIdentitySources/AppService.spec.ts index 773a796c03..d75dc28a77 100644 --- a/lib/msal-node/test/client/ManagedIdentitySources/AppService.spec.ts +++ b/lib/msal-node/test/client/ManagedIdentitySources/AppService.spec.ts @@ -18,7 +18,10 @@ import { } from "../../test_kit/ManagedIdentityTestUtils"; import { AuthenticationResult } from "@azure/msal-common"; import { ManagedIdentityClient } from "../../../src/client/ManagedIdentityClient"; -import { ManagedIdentityEnvironmentVariableNames } from "../../../src/utils/Constants"; +import { + AzureIdentitySdkManagedIdentitySourceNames, + ManagedIdentityEnvironmentVariableNames, +} from "../../../src/utils/Constants"; describe("Acquires a token successfully via an App Service Managed Identity", () => { beforeAll(() => { @@ -48,6 +51,9 @@ describe("Acquires a token successfully via an App Service Managed Identity", () const managedIdentityApplication: ManagedIdentityApplication = new ManagedIdentityApplication(userAssignedClientIdConfig); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.APP_SERVICE + ); const networkManagedIdentityResult: AuthenticationResult = await managedIdentityApplication.acquireToken( @@ -65,6 +71,9 @@ describe("Acquires a token successfully via an App Service Managed Identity", () managedIdentityApplication = new ManagedIdentityApplication( systemAssignedConfig ); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.APP_SERVICE + ); }); test("acquires a token", async () => { diff --git a/lib/msal-node/test/client/ManagedIdentitySources/AzureArc.spec.ts b/lib/msal-node/test/client/ManagedIdentitySources/AzureArc.spec.ts index 6fcc448fae..6aa48b4af4 100644 --- a/lib/msal-node/test/client/ManagedIdentitySources/AzureArc.spec.ts +++ b/lib/msal-node/test/client/ManagedIdentitySources/AzureArc.spec.ts @@ -30,7 +30,10 @@ import { } from "../../../src/error/ManagedIdentityError"; import { ARC_API_VERSION } from "../../../src/client/ManagedIdentitySources/AzureArc"; import * as fs from "fs"; -import { ManagedIdentityEnvironmentVariableNames } from "../../../src/utils/Constants"; +import { + AzureIdentitySdkManagedIdentitySourceNames, + ManagedIdentityEnvironmentVariableNames, +} from "../../../src/utils/Constants"; jest.mock("fs"); @@ -64,6 +67,9 @@ describe("Acquires a token successfully via an Azure Arc Managed Identity", () = managedIdentityApplication = new ManagedIdentityApplication( systemAssignedConfig ); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.AZURE_ARC + ); }); test("acquires a token", async () => { @@ -116,6 +122,9 @@ describe("Acquires a token successfully via an Azure Arc Managed Identity", () = // managedIdentityIdParams will be omitted for system assigned }, }); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.AZURE_ARC + ); const networkErrorClient: ManagedIdentityNetworkErrorClient = new ManagedIdentityNetworkErrorClient(); @@ -174,6 +183,9 @@ describe("Acquires a token successfully via an Azure Arc Managed Identity", () = const managedIdentityApplication: ManagedIdentityApplication = new ManagedIdentityApplication(userAssignedClientIdConfig); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.AZURE_ARC + ); await expect( managedIdentityApplication.acquireToken( @@ -199,6 +211,9 @@ describe("Acquires a token successfully via an Azure Arc Managed Identity", () = // managedIdentityIdParams will be omitted for system assigned }, }); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.AZURE_ARC + ); await expect( managedIdentityApplication.acquireToken( @@ -223,6 +238,9 @@ describe("Acquires a token successfully via an Azure Arc Managed Identity", () = // managedIdentityIdParams will be omitted for system assigned }, }); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.AZURE_ARC + ); await expect( managedIdentityApplication.acquireToken( @@ -247,6 +265,9 @@ describe("Acquires a token successfully via an Azure Arc Managed Identity", () = // managedIdentityIdParams will be omitted for system assigned }, }); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.AZURE_ARC + ); jest.spyOn(fs, "readFileSync").mockImplementationOnce(() => { throw new Error(); diff --git a/lib/msal-node/test/client/ManagedIdentitySources/CloudShell.spec.ts b/lib/msal-node/test/client/ManagedIdentitySources/CloudShell.spec.ts index b589aa6a50..d318114dea 100644 --- a/lib/msal-node/test/client/ManagedIdentitySources/CloudShell.spec.ts +++ b/lib/msal-node/test/client/ManagedIdentitySources/CloudShell.spec.ts @@ -17,7 +17,10 @@ import { } from "../../test_kit/ManagedIdentityTestUtils"; import { AuthenticationResult } from "@azure/msal-common"; import { ManagedIdentityClient } from "../../../src/client/ManagedIdentityClient"; -import { ManagedIdentityEnvironmentVariableNames } from "../../../src/utils/Constants"; +import { + AzureIdentitySdkManagedIdentitySourceNames, + ManagedIdentityEnvironmentVariableNames, +} from "../../../src/utils/Constants"; import { ManagedIdentityErrorCodes, createManagedIdentityError, @@ -47,6 +50,9 @@ describe("Acquires a token successfully via an App Service Managed Identity", () managedIdentityApplication = new ManagedIdentityApplication( systemAssignedConfig ); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.CLOUD_SHELL + ); }); test("acquires a token", async () => { @@ -93,6 +99,9 @@ describe("Acquires a token successfully via an App Service Managed Identity", () const managedIdentityApplication: ManagedIdentityApplication = new ManagedIdentityApplication(userAssignedClientIdConfig); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.CLOUD_SHELL + ); await expect( managedIdentityApplication.acquireToken( diff --git a/lib/msal-node/test/client/ManagedIdentitySources/Imds.spec.ts b/lib/msal-node/test/client/ManagedIdentitySources/Imds.spec.ts index e05a62a5ec..08ce7079d3 100644 --- a/lib/msal-node/test/client/ManagedIdentitySources/Imds.spec.ts +++ b/lib/msal-node/test/client/ManagedIdentitySources/Imds.spec.ts @@ -26,7 +26,10 @@ import { managedIdentityRequestParams, systemAssignedConfig, } from "../../test_kit/ManagedIdentityTestUtils"; -import { DEFAULT_MANAGED_IDENTITY_ID } from "../../../src/utils/Constants"; +import { + AzureIdentitySdkManagedIdentitySourceNames, + DEFAULT_MANAGED_IDENTITY_ID, +} from "../../../src/utils/Constants"; import { AccessTokenEntity, AuthenticationResult, @@ -87,6 +90,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { const managedIdentityApplication: ManagedIdentityApplication = new ManagedIdentityApplication(userAssignedClientIdConfig); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.IMDS + ); const networkManagedIdentityResult: AuthenticationResult = await managedIdentityApplication.acquireToken( @@ -103,6 +109,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { const managedIdentityApplication: ManagedIdentityApplication = new ManagedIdentityApplication(userAssignedObjectIdConfig); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.IMDS + ); const networkManagedIdentityResult: AuthenticationResult = await managedIdentityApplication.acquireToken( @@ -119,6 +128,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { const managedIdentityApplication: ManagedIdentityApplication = new ManagedIdentityApplication(userAssignedResourceIdConfig); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.IMDS + ); const networkManagedIdentityResult: AuthenticationResult = await managedIdentityApplication.acquireToken( @@ -137,6 +149,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { managedIdentityApplication = new ManagedIdentityApplication( systemAssignedConfig ); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.IMDS + ); }); test("acquires a token", async () => { @@ -184,6 +199,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { managedIdentityApplication = new ManagedIdentityApplication( userAssignedClientIdConfig ); + expect( + managedIdentityApplication.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); }); test("returns a 500 error response from the network request, just the first time", async () => { @@ -245,6 +263,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { managedIdentityApplication = new ManagedIdentityApplication( systemAssignedConfig ); + expect( + managedIdentityApplication.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); }); test("returns a 500 error response from the network request, just the first time, with no retry-after header", async () => { @@ -464,6 +485,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { disableInternalRetries: true, }, }); + expect( + managedIdentityApplicationNoRetry.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); const sendGetRequestAsyncSpy: jest.SpyInstance = jest .spyOn(networkClient, "sendGetRequestAsync") @@ -496,6 +520,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { beforeEach(() => { systemAssignedManagedIdentityApplication = new ManagedIdentityApplication(systemAssignedConfig); + expect( + systemAssignedManagedIdentityApplication.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); }); test("acquires a token from the network and then the same token from the cache, then acquires a different token for another scope", async () => { @@ -659,6 +686,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { userAssignedClientId: MANAGED_IDENTITY_RESOURCE_ID, }, }); + expect( + userAssignedClientIdManagedIdentityApplicationResource1.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); const userAssignedObjectIdManagedIdentityApplicationResource2: ManagedIdentityApplication = new ManagedIdentityApplication({ @@ -671,6 +701,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { userAssignedObjectId: MANAGED_IDENTITY_RESOURCE_ID_2, }, }); + expect( + userAssignedObjectIdManagedIdentityApplicationResource2.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); // ********** begin: return access tokens from a network request ********** // resource R1 for system assigned - returned from a network request @@ -707,6 +740,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { // resource R1 for system assigned - new application (to prove static cache persists), but same request as before, returned from the cache this time const systemAssignedManagedIdentityApplicationClone: ManagedIdentityApplication = new ManagedIdentityApplication(systemAssignedConfig); + expect( + systemAssignedManagedIdentityApplicationClone.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); let cachedManagedIdentityResult: AuthenticationResult = await systemAssignedManagedIdentityApplicationClone.acquireToken( { @@ -725,6 +761,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { userAssignedClientId: MANAGED_IDENTITY_RESOURCE_ID, }, }); + expect( + userAssignedClientIdManagedIdentityApplicationResource1Clone.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); cachedManagedIdentityResult = await userAssignedClientIdManagedIdentityApplicationResource1Clone.acquireToken( { @@ -745,6 +784,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { userAssignedObjectId: MANAGED_IDENTITY_RESOURCE_ID_2, }, }); + expect( + userAssignedObjectIdManagedIdentityApplicationResource2Clone.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); cachedManagedIdentityResult = await userAssignedObjectIdManagedIdentityApplicationResource2Clone.acquireToken( { @@ -784,6 +826,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { const systemAssignedManagedIdentityApplication: ManagedIdentityApplication = new ManagedIdentityApplication(systemAssignedConfig); + expect( + systemAssignedManagedIdentityApplication.getManagedIdentitySource() + ).toBe(AzureIdentitySdkManagedIdentitySourceNames.IMDS); await expect( systemAssignedManagedIdentityApplication.acquireToken({ @@ -829,6 +874,9 @@ describe("Acquires a token successfully via an IMDS Managed Identity", () => { // managedIdentityIdParams will be omitted for system assigned }, }); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.IMDS + ); let serverError: ServerError = new ServerError(); try { diff --git a/lib/msal-node/test/client/ManagedIdentitySources/ServiceFabric.spec.ts b/lib/msal-node/test/client/ManagedIdentitySources/ServiceFabric.spec.ts index 0be67d8848..82c170cd35 100644 --- a/lib/msal-node/test/client/ManagedIdentitySources/ServiceFabric.spec.ts +++ b/lib/msal-node/test/client/ManagedIdentitySources/ServiceFabric.spec.ts @@ -18,7 +18,10 @@ import { } from "../../test_kit/ManagedIdentityTestUtils"; import { AuthenticationResult } from "@azure/msal-common"; import { ManagedIdentityClient } from "../../../src/client/ManagedIdentityClient"; -import { ManagedIdentityEnvironmentVariableNames } from "../../../src/utils/Constants"; +import { + AzureIdentitySdkManagedIdentitySourceNames, + ManagedIdentityEnvironmentVariableNames, +} from "../../../src/utils/Constants"; describe("Acquires a token successfully via an App Service Managed Identity", () => { beforeAll(() => { @@ -54,6 +57,9 @@ describe("Acquires a token successfully via an App Service Managed Identity", () const managedIdentityApplication: ManagedIdentityApplication = new ManagedIdentityApplication(userAssignedClientIdConfig); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.SERVICE_FABRIC + ); const networkManagedIdentityResult: AuthenticationResult = await managedIdentityApplication.acquireToken( @@ -71,6 +77,9 @@ describe("Acquires a token successfully via an App Service Managed Identity", () managedIdentityApplication = new ManagedIdentityApplication( systemAssignedConfig ); + expect(managedIdentityApplication.getManagedIdentitySource()).toBe( + AzureIdentitySdkManagedIdentitySourceNames.SERVICE_FABRIC + ); }); test("acquires a token", async () => {