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

Function TestDynamicRegistration

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

Source from the content-addressed store, hash-verified

566}
567
568func TestDynamicRegistration(t *testing.T) {
569 s := oauthtest.NewFakeAuthorizationServer(oauthtest.Config{
570 RegistrationConfig: &oauthtest.RegistrationConfig{
571 DynamicClientRegistrationEnabled: true,
572 },
573 })
574 s.Start(t)
575 handler, err := NewAuthorizationCodeHandler(&AuthorizationCodeHandlerConfig{
576 DynamicClientRegistrationConfig: &DynamicClientRegistrationConfig{
577 Metadata: &oauthex.ClientRegistrationMetadata{
578 RedirectURIs: []string{"https://example.com/callback"},
579 },
580 },
581 RedirectURL: "https://example.com/callback",
582 AuthorizationCodeFetcher: func(ctx context.Context, args *AuthorizationArgs) (*AuthorizationResult, error) {
583 return nil, nil
584 },
585 })
586 if err != nil {
587 t.Fatalf("NewAuthorizationCodeHandler() error = %v", err)
588 }
589 asm, err := GetAuthServerMetadata(t.Context(), s.URL(), http.DefaultClient)
590 if err != nil {
591 t.Fatalf("GetAuthServerMetadata() unexpected error = %v", err)
592 }
593 got, err := handler.handleRegistration(t.Context(), asm)
594 if err != nil {
595 t.Fatalf("handleRegistration() error = %v, want nil", err)
596 }
597 if got.registrationType != registrationTypeDynamic {
598 t.Errorf("handleRegistration() registrationType = %v, want %v", got.registrationType, registrationTypeDynamic)
599 }
600 if got.clientID == "" {
601 t.Errorf("handleRegistration() clientID = %q, want non-empty", got.clientID)
602 }
603 if got.clientSecret == "" {
604 t.Errorf("handleRegistration() clientSecret = %q, want non-empty", got.clientSecret)
605 }
606 if got.authStyle != oauth2.AuthStyleInHeader {
607 t.Errorf("handleRegistration() authStyle = %v, want %v", got.authStyle, oauth2.AuthStyleInHeader)
608 }
609}
610
611func TestInferApplicationType(t *testing.T) {
612 tests := []struct {

Callers

nothing calls this directly

Calls 6

StartMethod · 0.95
URLMethod · 0.95
handleRegistrationMethod · 0.95
GetAuthServerMetadataFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…