@@ -62,7 +62,6 @@ func TestNewAuthHandler(t *testing.T) {
6262 require .NotNil (t , handler )
6363
6464 assert .Equal (t , tc .expectedAuthServer , handler .cfg .AuthorizationServer )
65- assert .NotNil (t , handler .protectedResourceTemplate )
6665 })
6766 }
6867}
@@ -444,8 +443,10 @@ func TestHandleProtectedResource(t *testing.T) {
444443 validateResponse func (t * testing.T , body map [string ]any )
445444 }{
446445 {
447- name : "GET request returns protected resource metadata" ,
448- cfg : & Config {},
446+ name : "GET request returns protected resource metadata" ,
447+ cfg : & Config {
448+ BaseURL : "https://api.example.com" ,
449+ },
449450 path : OAuthProtectedResourcePrefix ,
450451 host : "api.example.com" ,
451452 method : http .MethodGet ,
@@ -454,7 +455,7 @@ func TestHandleProtectedResource(t *testing.T) {
454455 validateResponse : func (t * testing.T , body map [string ]any ) {
455456 t .Helper ()
456457 assert .Equal (t , "GitHub MCP Server" , body ["resource_name" ])
457- assert .Contains (t , body [ "resource" ], " api.example.com" )
458+ assert .Equal (t , "https:// api.example.com", body [ "resource" ] )
458459
459460 authServers , ok := body ["authorization_servers" ].([]any )
460461 require .True (t , ok )
@@ -463,40 +464,47 @@ func TestHandleProtectedResource(t *testing.T) {
463464 },
464465 },
465466 {
466- name : "OPTIONS request for CORS" ,
467- cfg : & Config {},
467+ name : "OPTIONS request for CORS preflight" ,
468+ cfg : & Config {
469+ BaseURL : "https://api.example.com" ,
470+ },
468471 path : OAuthProtectedResourcePrefix ,
469472 host : "api.example.com" ,
470473 method : http .MethodOptions ,
471- expectedStatusCode : http .StatusOK ,
474+ expectedStatusCode : http .StatusNoContent ,
472475 },
473476 {
474- name : "path with /mcp suffix" ,
475- cfg : & Config {},
477+ name : "path with /mcp suffix" ,
478+ cfg : & Config {
479+ BaseURL : "https://api.example.com" ,
480+ },
476481 path : OAuthProtectedResourcePrefix + "/mcp" ,
477482 host : "api.example.com" ,
478483 method : http .MethodGet ,
479484 expectedStatusCode : http .StatusOK ,
480485 validateResponse : func (t * testing.T , body map [string ]any ) {
481486 t .Helper ()
482- assert .Contains (t , body [ "resource" ], "/mcp" )
487+ assert .Equal (t , "https://api.example.com/mcp" , body [ "resource" ] )
483488 },
484489 },
485490 {
486- name : "path with /readonly suffix" ,
487- cfg : & Config {},
491+ name : "path with /readonly suffix" ,
492+ cfg : & Config {
493+ BaseURL : "https://api.example.com" ,
494+ },
488495 path : OAuthProtectedResourcePrefix + "/readonly" ,
489496 host : "api.example.com" ,
490497 method : http .MethodGet ,
491498 expectedStatusCode : http .StatusOK ,
492499 validateResponse : func (t * testing.T , body map [string ]any ) {
493500 t .Helper ()
494- assert .Contains (t , body [ "resource" ], "/readonly" )
501+ assert .Equal (t , "https://api.example.com/readonly" , body [ "resource" ] )
495502 },
496503 },
497504 {
498505 name : "custom authorization server in response" ,
499506 cfg : & Config {
507+ BaseURL : "https://api.example.com" ,
500508 AuthorizationServer : "https://custom.auth.example.com/oauth" ,
501509 },
502510 path : OAuthProtectedResourcePrefix ,
@@ -559,7 +567,9 @@ func TestHandleProtectedResource(t *testing.T) {
559567func TestRegisterRoutes (t * testing.T ) {
560568 t .Parallel ()
561569
562- handler , err := NewAuthHandler (& Config {})
570+ handler , err := NewAuthHandler (& Config {
571+ BaseURL : "https://api.example.com" ,
572+ })
563573 require .NoError (t , err )
564574
565575 router := chi .NewRouter ()
@@ -588,12 +598,12 @@ func TestRegisterRoutes(t *testing.T) {
588598 router .ServeHTTP (rec , req )
589599 assert .Equal (t , http .StatusOK , rec .Code , "GET %s should return 200" , route )
590600
591- // Test OPTIONS (CORS)
601+ // Test OPTIONS (CORS preflight )
592602 req = httptest .NewRequest (http .MethodOptions , route , nil )
593603 req .Host = "api.example.com"
594604 rec = httptest .NewRecorder ()
595605 router .ServeHTTP (rec , req )
596- assert .Equal (t , http .StatusOK , rec .Code , "OPTIONS %s should return 200 " , route )
606+ assert .Equal (t , http .StatusNoContent , rec .Code , "OPTIONS %s should return 204 " , route )
597607 })
598608 }
599609}
@@ -623,7 +633,9 @@ func TestSupportedScopes(t *testing.T) {
623633func TestProtectedResourceResponseFormat (t * testing.T ) {
624634 t .Parallel ()
625635
626- handler , err := NewAuthHandler (& Config {})
636+ handler , err := NewAuthHandler (& Config {
637+ BaseURL : "https://api.example.com" ,
638+ })
627639 require .NoError (t , err )
628640
629641 router := chi .NewRouter ()
0 commit comments