@@ -598,3 +598,112 @@ func TestCredentialsProviderSubscribe(t *testing.T) {
598
598
}
599
599
})
600
600
}
601
+
602
+ func TestCredentialsProviderOptions (t * testing.T ) {
603
+ t .Run ("default token manager factory" , func (t * testing.T ) {
604
+ options := CredentialsProviderOptions {}
605
+ factory := options .getTokenManagerFactory ()
606
+ assert .NotNil (t , factory )
607
+ })
608
+
609
+ t .Run ("custom token manager factory" , func (t * testing.T ) {
610
+ m := & mockTokenManager {}
611
+ customFactory := func (shared.IdentityProvider , manager.TokenManagerOptions ) (manager.TokenManager , error ) {
612
+ return m , nil
613
+ }
614
+ options := CredentialsProviderOptions {
615
+ tokenManagerFactory : customFactory ,
616
+ }
617
+ tm , err := options .getTokenManagerFactory ()(nil , manager.TokenManagerOptions {})
618
+ assert .NotNil (t , tm )
619
+ assert .NoError (t , err )
620
+ assert .Equal (t , m , tm )
621
+ })
622
+ }
623
+
624
+ func TestCredentialsProviderErrorScenarios (t * testing.T ) {
625
+ t .Run ("token manager start error" , func (t * testing.T ) {
626
+ // Create a test provider with invalid options
627
+ options := ConfidentialCredentialsProviderOptions {
628
+ CredentialsProviderOptions : CredentialsProviderOptions {
629
+ ClientID : "test-client-id" ,
630
+ TokenManagerOptions : manager.TokenManagerOptions {
631
+ ExpirationRefreshRatio : 0.7 ,
632
+ },
633
+ },
634
+ ConfidentialIdentityProviderOptions : identity.ConfidentialIdentityProviderOptions {
635
+ ClientID : "test-client-id" ,
636
+ CredentialsType : "invalid-type" , // Invalid credentials type
637
+ ClientSecret : "test-secret" ,
638
+ Scopes : []string {identity .RedisScopeDefault },
639
+ Authority : identity.AuthorityConfiguration {},
640
+ },
641
+ }
642
+
643
+ provider , err := NewConfidentialCredentialsProvider (options )
644
+ assert .Error (t , err )
645
+ assert .Nil (t , provider )
646
+ })
647
+
648
+ t .Run ("token manager get token error" , func (t * testing.T ) {
649
+ // Create a test provider with invalid options
650
+ options := ConfidentialCredentialsProviderOptions {
651
+ CredentialsProviderOptions : CredentialsProviderOptions {
652
+ ClientID : "test-client-id" ,
653
+ TokenManagerOptions : manager.TokenManagerOptions {
654
+ ExpirationRefreshRatio : 0.7 ,
655
+ },
656
+ },
657
+ ConfidentialIdentityProviderOptions : identity.ConfidentialIdentityProviderOptions {
658
+ ClientID : "test-client-id" ,
659
+ CredentialsType : identity .ClientSecretCredentialType ,
660
+ ClientSecret : "" , // Empty client secret
661
+ Scopes : []string {identity .RedisScopeDefault },
662
+ Authority : identity.AuthorityConfiguration {},
663
+ },
664
+ }
665
+
666
+ provider , err := NewConfidentialCredentialsProvider (options )
667
+ assert .Error (t , err )
668
+ assert .Nil (t , provider )
669
+ })
670
+
671
+ t .Run ("concurrent error handling" , func (t * testing.T ) {
672
+ // Create a test provider with invalid options
673
+ options := ManagedIdentityCredentialsProviderOptions {
674
+ CredentialsProviderOptions : CredentialsProviderOptions {
675
+ ClientID : "test-client-id" ,
676
+ TokenManagerOptions : manager.TokenManagerOptions {
677
+ ExpirationRefreshRatio : 0.7 ,
678
+ },
679
+ },
680
+ ManagedIdentityProviderOptions : identity.ManagedIdentityProviderOptions {
681
+ ManagedIdentityType : "invalid-type" , // Invalid managed identity type
682
+ Scopes : []string {identity .RedisScopeDefault },
683
+ },
684
+ }
685
+
686
+ provider , err := NewManagedIdentityCredentialsProvider (options )
687
+ assert .Error (t , err )
688
+ assert .Nil (t , provider )
689
+ })
690
+
691
+ t .Run ("concurrent token updates" , func (t * testing.T ) {
692
+ // Create a test provider with invalid options
693
+ options := DefaultAzureCredentialsProviderOptions {
694
+ CredentialsProviderOptions : CredentialsProviderOptions {
695
+ ClientID : "test-client-id" ,
696
+ TokenManagerOptions : manager.TokenManagerOptions {
697
+ ExpirationRefreshRatio : 0.7 ,
698
+ },
699
+ },
700
+ DefaultAzureIdentityProviderOptions : identity.DefaultAzureIdentityProviderOptions {
701
+ Scopes : []string {}, // Empty scopes
702
+ },
703
+ }
704
+
705
+ provider , err := NewDefaultAzureCredentialsProvider (options )
706
+ assert .Error (t , err )
707
+ assert .Nil (t , provider )
708
+ })
709
+ }
0 commit comments