|
1 | 1 | import {
|
2 | 2 | generateOAuthErrorDescription,
|
3 | 3 | parseOAuthCallbackParams,
|
| 4 | + oauthAuthServerMetadataUrl, |
4 | 5 | } from "@/utils/oauthUtils.ts";
|
5 | 6 |
|
6 | 7 | describe("parseOAuthCallbackParams", () => {
|
@@ -76,3 +77,37 @@ describe("generateOAuthErrorDescription", () => {
|
76 | 77 | );
|
77 | 78 | });
|
78 | 79 | });
|
| 80 | + |
| 81 | +describe("oauthAuthServerMetadataUrl", () => { |
| 82 | + it("Returns metadata URL for simple auth server URL", () => { |
| 83 | + const input = new URL("https://auth.example.com"); |
| 84 | + const result = oauthAuthServerMetadataUrl(input); |
| 85 | + expect(result.href).toBe( |
| 86 | + "https://auth.example.com/.well-known/oauth-authorization-server", |
| 87 | + ); |
| 88 | + }); |
| 89 | + |
| 90 | + it("Returns metadata URL for auth server with path", () => { |
| 91 | + const input = new URL("https://auth.example.com/oauth/tenant/xyz"); |
| 92 | + const result = oauthAuthServerMetadataUrl(input); |
| 93 | + expect(result.href).toBe( |
| 94 | + "https://auth.example.com/.well-known/oauth-authorization-server/oauth/tenant/xyz", |
| 95 | + ); |
| 96 | + }); |
| 97 | + |
| 98 | + it("Strips trailing slash from path as per spec", () => { |
| 99 | + const input = new URL("https://auth.example.com/oauth/"); |
| 100 | + const result = oauthAuthServerMetadataUrl(input); |
| 101 | + expect(result.href).toBe( |
| 102 | + "https://auth.example.com/.well-known/oauth-authorization-server/oauth", |
| 103 | + ); |
| 104 | + }); |
| 105 | + |
| 106 | + it("Handles auth server URL with port", () => { |
| 107 | + const input = new URL("https://auth.example.com:8080"); |
| 108 | + const result = oauthAuthServerMetadataUrl(input); |
| 109 | + expect(result.href).toBe( |
| 110 | + "https://auth.example.com:8080/.well-known/oauth-authorization-server", |
| 111 | + ); |
| 112 | + }); |
| 113 | +}); |
0 commit comments