Skip to content

Commit

Permalink
Fixed broken unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbie-Microsoft committed Apr 26, 2024
1 parent f218368 commit 474a6c3
Showing 1 changed file with 14 additions and 40 deletions.
54 changes: 14 additions & 40 deletions lib/msal-node/test/client/PublicClientApplication.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
CacheHelpers,
AuthorityFactory,
ProtocolMode,
createClientConfigurationError,
ClientConfigurationErrorCodes,
} from "@azure/msal-common";
import {
Configuration,
Expand Down Expand Up @@ -868,44 +870,17 @@ describe("PublicClientApplication", () => {
});
});

test("initializeBaseRequest passes a requested claims hash to acquireToken when claimsBasedHashing is enabled", async () => {
const account: AccountInfo = {
homeAccountId: "",
environment: "",
tenantId: "",
username: "",
localAccountId: "",
name: "",
idTokenClaims: ID_TOKEN_CLAIMS,
};
const request: SilentFlowRequest = {
account: account,
scopes: TEST_CONSTANTS.DEFAULT_GRAPH_SCOPE,
claims: TEST_CONSTANTS.CLAIMS,
};

const silentFlowClient = getMsalCommonAutoMock().SilentFlowClient;
jest.spyOn(msalCommon, "SilentFlowClient").mockImplementation(
(config) => new silentFlowClient(config)
);

const acquireTokenSpy = jest.spyOn(
silentFlowClient.prototype,
"acquireToken"
);
const authApp = new PublicClientApplication({
...appConfig,
cache: { claimsBasedCachingEnabled: true },
});
await authApp.acquireTokenSilent(request);
expect(silentFlowClient.prototype.acquireToken).toHaveBeenCalledWith(
expect.objectContaining({ requestedClaimsHash: expect.any(String) })
test("throws an error when claimsBasedCaching is enabled", async () => {
expect(() => {
new PublicClientApplication({
...appConfig,
cache: { claimsBasedCachingEnabled: true },
});
}).toThrow(
createClientConfigurationError(
ClientConfigurationErrorCodes.claimsBasedCachingEnabled
)
);

const submittedRequest = acquireTokenSpy.mock.calls[0][0];
expect(
(submittedRequest as any)?.requestedClaimsHash?.length
).toBeGreaterThan(0);
});

test("initializeBaseRequest doesn't pass a claims hash to acquireToken when claimsBasedHashing is disabled by default", async () => {
Expand Down Expand Up @@ -1136,7 +1111,7 @@ describe("PublicClientApplication", () => {
expect(authApp.getLogger().info("Test logger")).toEqual(undefined);
});

test("should throw an error if state is not provided", async () => {
test("throws an error if state is not provided", async () => {
const cryptoProvider = new CryptoProvider();
const request: AuthorizationCodeRequest = {
scopes: TEST_CONSTANTS.DEFAULT_GRAPH_SCOPE,
Expand Down Expand Up @@ -1169,12 +1144,11 @@ describe("PublicClientApplication", () => {
});

const authApp = new PublicClientApplication(appConfig);
await authApp.acquireTokenByCode(request, authCodePayLoad);

try {
await authApp.acquireTokenByCode(request, authCodePayLoad);
} catch (e) {
expect(mockInfo).toBeCalledWith("acquireTokenByCode called");
expect(mockInfo).toHaveBeenCalledWith("acquireTokenByCode called");
expect(mockInfo).toHaveBeenCalledWith(
"acquireTokenByCode - validating state"
);
Expand Down

0 comments on commit 474a6c3

Please sign in to comment.