Skip to content

Commit

Permalink
fix a bug in CIAM authority support
Browse files Browse the repository at this point in the history
  • Loading branch information
sameerag committed Apr 22, 2023
1 parent 352f741 commit 5e29132
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/msal-common/src/authority/Authority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ export class Authority {
* @param authority
*/
static transformCIAMAuthority(authority: string): string {
let ciamAuthority = authority;
let ciamAuthority = authority.endsWith(Constants.FORWARD_SLASH) ? authority : `${authority}${Constants.FORWARD_SLASH}`;
const authorityUrl = new UrlString(authority);
const authorityUrlComponents = authorityUrl.getUrlComponents();

Expand Down
9 changes: 9 additions & 0 deletions lib/msal-common/test/authority/AuthorityFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ describe("AuthorityFactory.ts Class Unit Tests", () => {
expect(resolveEndpointsStub).toHaveBeenCalledTimes(1);
});

it("createDiscoveredInstance transforms CIAM authority when trailing slash is missing", async () => {
const resolveEndpointsStub = jest.spyOn(Authority.prototype, "resolveEndpointsAsync").mockResolvedValue();
const authorityInstance = await AuthorityFactory.createDiscoveredInstance("https://test.ciamlogin.com", networkInterface, mockStorage, authorityOptions, logger);
expect(authorityInstance.authorityType).toBe(AuthorityType.Ciam);
expect(authorityInstance.canonicalAuthority).toBe("https://test.ciamlogin.com/test.onmicrosoft.com/");
expect(authorityInstance instanceof Authority);
expect(resolveEndpointsStub).toHaveBeenCalledTimes(1);
});

it("createDiscoveredInstance does not transform when there is a PATH", async () => {
const resolveEndpointsStub = jest.spyOn(Authority.prototype, "resolveEndpointsAsync").mockResolvedValue();
const authorityInstance = await AuthorityFactory.createDiscoveredInstance("https://test.ciamlogin.com/tenant/", networkInterface, mockStorage, authorityOptions, logger);
Expand Down

0 comments on commit 5e29132

Please sign in to comment.