@@ -8,7 +8,6 @@ import * as sinon from 'sinon';
88import {
99 getClaimsFromJWT ,
1010 getDefaultMetadataForUrl ,
11- getResourceServerBaseUrlFromDiscoveryUrl ,
1211 isAuthorizationAuthorizeResponse ,
1312 isAuthorizationDeviceResponse ,
1413 isAuthorizationErrorResponse ,
@@ -625,106 +624,6 @@ suite('OAuth', () => {
625624 } ) ;
626625 } ) ;
627626
628- suite ( 'getResourceServerBaseUrlFromDiscoveryUrl' , ( ) => {
629- test ( 'should extract base URL from discovery URL at root' , ( ) => {
630- const discoveryUrl = 'https://mcp.example.com/.well-known/oauth-protected-resource' ;
631- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
632- assert . strictEqual ( result , 'https://mcp.example.com/' ) ;
633- } ) ;
634-
635- test ( 'should extract base URL from discovery URL with subpath' , ( ) => {
636- const discoveryUrl = 'https://mcp.example.com/.well-known/oauth-protected-resource/mcp' ;
637- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
638- assert . strictEqual ( result , 'https://mcp.example.com/mcp' ) ;
639- } ) ;
640-
641- test ( 'should extract base URL from discovery URL with nested subpath' , ( ) => {
642- const discoveryUrl = 'https://api.example.com/.well-known/oauth-protected-resource/v1/services/mcp' ;
643- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
644- assert . strictEqual ( result , 'https://api.example.com/v1/services/mcp' ) ;
645- } ) ;
646-
647- test ( 'should handle discovery URL with port number' , ( ) => {
648- const discoveryUrl = 'https://localhost:8443/.well-known/oauth-protected-resource/api' ;
649- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
650- assert . strictEqual ( result , 'https://localhost:8443/api' ) ;
651- } ) ;
652-
653- test ( 'should handle discovery URL with query parameters' , ( ) => {
654- const discoveryUrl = 'https://example.com/.well-known/oauth-protected-resource/api?version=1' ;
655- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
656- assert . strictEqual ( result , 'https://example.com/api' ) ;
657- } ) ;
658-
659- test ( 'should handle discovery URL with fragment' , ( ) => {
660- const discoveryUrl = 'https://example.com/.well-known/oauth-protected-resource/api#section' ;
661- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
662- assert . strictEqual ( result , 'https://example.com/api' ) ;
663- } ) ;
664-
665- test ( 'should handle discovery URL ending with trailing slash' , ( ) => {
666- const discoveryUrl = 'https://example.com/.well-known/oauth-protected-resource/api/' ;
667- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
668- assert . strictEqual ( result , 'https://example.com/api/' ) ;
669- } ) ;
670-
671- test ( 'should handle HTTP URLs' , ( ) => {
672- const discoveryUrl = 'http://localhost:3000/.well-known/oauth-protected-resource/dev' ;
673- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
674- assert . strictEqual ( result , 'http://localhost:3000/dev' ) ;
675- } ) ;
676-
677- test ( 'should throw error for URL without discovery path' , ( ) => {
678- const discoveryUrl = 'https://example.com/some/other/path' ;
679- assert . throws (
680- ( ) => getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ,
681- / I n v a l i d d i s c o v e r y U R L : e x p e c t e d p a t h t o s t a r t w i t h \/ \. w e l l - k n o w n \/ o a u t h - p r o t e c t e d - r e s o u r c e /
682- ) ;
683- } ) ;
684-
685- test ( 'should throw error for URL with partial discovery path' , ( ) => {
686- const discoveryUrl = 'https://example.com/.well-known/oauth' ;
687- assert . throws (
688- ( ) => getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ,
689- / I n v a l i d d i s c o v e r y U R L : e x p e c t e d p a t h t o s t a r t w i t h \/ \. w e l l - k n o w n \/ o a u t h - p r o t e c t e d - r e s o u r c e /
690- ) ;
691- } ) ;
692-
693- test ( 'should throw error for URL with discovery path not at beginning' , ( ) => {
694- const discoveryUrl = 'https://example.com/api/.well-known/oauth-protected-resource' ;
695- assert . throws (
696- ( ) => getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ,
697- / I n v a l i d d i s c o v e r y U R L : e x p e c t e d p a t h t o s t a r t w i t h \/ \. w e l l - k n o w n \/ o a u t h - p r o t e c t e d - r e s o u r c e /
698- ) ;
699- } ) ;
700-
701- test ( 'should throw error for invalid URL format' , ( ) => {
702- const discoveryUrl = 'not-a-valid-url' ;
703- assert . throws (
704- ( ) => getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ,
705- TypeError
706- ) ;
707- } ) ;
708-
709- test ( 'should handle empty path after discovery path' , ( ) => {
710- const discoveryUrl = 'https://example.com/.well-known/oauth-protected-resource' ;
711- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
712- assert . strictEqual ( result , 'https://example.com/' ) ;
713- } ) ;
714-
715- test ( 'should preserve URL encoding in subpath' , ( ) => {
716- const discoveryUrl = 'https://example.com/.well-known/oauth-protected-resource/api%20v1' ;
717- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
718- assert . strictEqual ( result , 'https://example.com/api%20v1' ) ;
719- } ) ;
720-
721- test ( 'should normalize hostname case consistently' , ( ) => {
722- const discoveryUrl = 'https://MCP.EXAMPLE.COM/.well-known/oauth-protected-resource' ;
723- const result = getResourceServerBaseUrlFromDiscoveryUrl ( discoveryUrl ) ;
724- assert . strictEqual ( result , 'https://mcp.example.com/' ) ;
725- } ) ;
726- } ) ;
727-
728627 suite ( 'Client ID Fallback Scenarios' , ( ) => {
729628 let sandbox : sinon . SinonSandbox ;
730629 let fetchStub : sinon . SinonStub ;
0 commit comments