MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / TestHandleRegistration

Function TestHandleRegistration

auth/authorization_code_test.go:474–566  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

472}
473
474func TestHandleRegistration(t *testing.T) {
475 tests := []struct {
476 name string
477 serverConfig *oauthtest.RegistrationConfig
478 handlerConfig *AuthorizationCodeHandlerConfig
479 asm *oauthex.AuthServerMeta
480 want *resolvedClientConfig
481 wantError bool
482 }{
483 {
484 name: "ClientIDMetadataDocument",
485 serverConfig: &oauthtest.RegistrationConfig{
486 ClientIDMetadataDocumentSupported: true,
487 },
488 handlerConfig: &AuthorizationCodeHandlerConfig{
489 ClientIDMetadataDocumentConfig: &ClientIDMetadataDocumentConfig{URL: "https://client.example.com/metadata.json"},
490 },
491 want: &resolvedClientConfig{
492 registrationType: registrationTypeClientIDMetadataDocument,
493 clientID: "https://client.example.com/metadata.json",
494 },
495 },
496 {
497 name: "Preregistered",
498 serverConfig: &oauthtest.RegistrationConfig{
499 PreregisteredClients: map[string]oauthtest.ClientInfo{
500 "pre_client_id": {
501 Secret: "pre_client_secret",
502 },
503 },
504 },
505 handlerConfig: &AuthorizationCodeHandlerConfig{
506 PreregisteredClient: &oauthex.ClientCredentials{
507 ClientID: "pre_client_id",
508 ClientSecretAuth: &oauthex.ClientSecretAuth{
509 ClientSecret: "pre_client_secret",
510 },
511 },
512 },
513 want: &resolvedClientConfig{
514 registrationType: registrationTypePreregistered,
515 clientID: "pre_client_id",
516 clientSecret: "pre_client_secret",
517 authStyle: oauth2.AuthStyleInParams,
518 },
519 },
520 {
521 name: "NoneSupported",
522 handlerConfig: &AuthorizationCodeHandlerConfig{
523 ClientIDMetadataDocumentConfig: &ClientIDMetadataDocumentConfig{URL: "https://client.example.com/metadata.json"},
524 },
525 wantError: true,
526 },
527 }
528
529 for _, tt := range tests {
530 t.Run(tt.name, func(t *testing.T) {
531 s := oauthtest.NewFakeAuthorizationServer(oauthtest.Config{RegistrationConfig: tt.serverConfig})

Callers

nothing calls this directly

Calls 7

StartMethod · 0.95
URLMethod · 0.95
handleRegistrationMethod · 0.95
GetAuthServerMetadataFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…