@@ -286,6 +286,36 @@ func TestHealthCheck(t *testing.T) {
286286 })
287287}
288288
289+ func TestWellKnownOAuthAuthorizationServer (t * testing.T ) {
290+ // Simple http server to mock the authorization server
291+ testServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
292+ if r .URL .Path != "/.well-known/oauth-authorization-server" {
293+ http .NotFound (w , r )
294+ return
295+ }
296+ w .Header ().Set ("Content-Type" , "application/json" )
297+ _ , _ = w .Write ([]byte (`{"issuer": "https://example.com"}` ))
298+ }))
299+ t .Cleanup (testServer .Close )
300+ testCaseWithContext (t , & httpContext {StaticConfig : & config.StaticConfig {AuthorizationURL : testServer .URL , RequireOAuth : true }}, func (ctx * httpContext ) {
301+ resp , err := http .Get (fmt .Sprintf ("http://%s/.well-known/oauth-authorization-server" , ctx .HttpAddress ))
302+ t .Cleanup (func () { _ = resp .Body .Close () })
303+ t .Run ("Exposes .well-known/oauth-authorization-server endpoint" , func (t * testing.T ) {
304+ if err != nil {
305+ t .Fatalf ("Failed to get .well-known/oauth-authorization-server endpoint: %v" , err )
306+ }
307+ if resp .StatusCode != http .StatusOK {
308+ t .Errorf ("Expected HTTP 200 OK, got %d" , resp .StatusCode )
309+ }
310+ })
311+ t .Run (".well-known/oauth-authorization-server returns application/json content type" , func (t * testing.T ) {
312+ if resp .Header .Get ("Content-Type" ) != "application/json" {
313+ t .Errorf ("Expected Content-Type application/json, got %s" , resp .Header .Get ("Content-Type" ))
314+ }
315+ })
316+ })
317+ }
318+
289319func TestWellKnownOAuthProtectedResource (t * testing.T ) {
290320 testCase (t , func (ctx * httpContext ) {
291321 resp , err := http .Get (fmt .Sprintf ("http://%s/.well-known/oauth-protected-resource" , ctx .HttpAddress ))
0 commit comments