@@ -497,3 +497,131 @@ func TestOIDCAuthValidation(t *testing.T) {
497497})
498498}
499499}
500+
501+ func TestOIDCProviderConfigUniqueIssuerURIValidation (t * testing.T ) {
502+ tests := []struct {
503+ name string
504+ mongoVersion string
505+ configs []OIDCProviderConfig
506+ expectedResult v1.ValidationResult
507+ }{
508+ {
509+ name : "MongoDB 6.0 with duplicate issuer URIs - error" ,
510+ mongoVersion : "6.0.0" ,
511+ configs : []OIDCProviderConfig {
512+ {
513+ ConfigurationName : "config1" ,
514+ IssuerURI : "https://provider.com" ,
515+ Audience : "audience1" ,
516+ },
517+ {
518+ ConfigurationName : "config2" ,
519+ IssuerURI : "https://provider.com" ,
520+ Audience : "audience2" ,
521+ },
522+ },
523+ expectedResult : v1 .ValidationError ("OIDC provider configs %q and %q have duplicate IssuerURI: %s" ,
524+ "config1" , "config2" , "https://provider.com" ),
525+ },
526+ {
527+ name : "MongoDB 7.0 with unique issuer+audience combinations" ,
528+ mongoVersion : "7.0.0" ,
529+ configs : []OIDCProviderConfig {
530+ {
531+ ConfigurationName : "config1" ,
532+ IssuerURI : "https://provider.com" ,
533+ Audience : "audience1" ,
534+ },
535+ {
536+ ConfigurationName : "config2" ,
537+ IssuerURI : "https://provider.com" ,
538+ Audience : "audience2" ,
539+ },
540+ },
541+ expectedResult : v1 .ValidationSuccess (),
542+ },
543+ {
544+ name : "MongoDB 7.0 with duplicate issuer+audience combinations - warning" ,
545+ mongoVersion : "7.0.0" ,
546+ configs : []OIDCProviderConfig {
547+ {
548+ ConfigurationName : "config1" ,
549+ IssuerURI : "https://provider.com" ,
550+ Audience : "audience1" ,
551+ },
552+ {
553+ ConfigurationName : "config2" ,
554+ IssuerURI : "https://provider.com" ,
555+ Audience : "audience1" ,
556+ },
557+ },
558+ expectedResult : v1 .ValidationWarning ("OIDC provider configs %q and %q have duplicate IssuerURI and Audience combination" ,
559+ "config1" , "config2" ),
560+ },
561+ {
562+ name : "MongoDB 7.3 with unique issuer+audience combinations" ,
563+ mongoVersion : "7.3.0" ,
564+ configs : []OIDCProviderConfig {
565+ {
566+ ConfigurationName : "config1" ,
567+ IssuerURI : "https://provider.com" ,
568+ Audience : "audience1" ,
569+ },
570+ {
571+ ConfigurationName : "config2" ,
572+ IssuerURI : "https://provider.com" ,
573+ Audience : "audience2" ,
574+ },
575+ },
576+ expectedResult : v1 .ValidationSuccess (),
577+ },
578+ {
579+ name : "MongoDB 8.0 with unique issuer+audience combinations" ,
580+ mongoVersion : "8.0.0" ,
581+ configs : []OIDCProviderConfig {
582+ {
583+ ConfigurationName : "config1" ,
584+ IssuerURI : "https://provider.com" ,
585+ Audience : "audience1" ,
586+ },
587+ {
588+ ConfigurationName : "config2" ,
589+ IssuerURI : "https://provider.com" ,
590+ Audience : "audience2" ,
591+ },
592+ },
593+ expectedResult : v1 .ValidationSuccess (),
594+ },
595+ {
596+ name : "MongoDB enterprise version with -ent suffix" ,
597+ mongoVersion : "7.0.0-ent" ,
598+ configs : []OIDCProviderConfig {
599+ {
600+ ConfigurationName : "config1" ,
601+ IssuerURI : "https://provider.com" ,
602+ Audience : "audience1" ,
603+ },
604+ {
605+ ConfigurationName : "config2" ,
606+ IssuerURI : "https://provider.com" ,
607+ Audience : "audience2" ,
608+ },
609+ },
610+ expectedResult : v1 .ValidationSuccess (),
611+ },
612+ }
613+
614+ for _ , tt := range tests {
615+ t .Run (tt .name , func (t * testing.T ) {
616+ validationFunc := oidcProviderConfigUniqueIssuerURIValidation (tt .configs )
617+
618+ dbSpec := DbCommonSpec {
619+ Version : tt .mongoVersion ,
620+ }
621+
622+ result := validationFunc (dbSpec )
623+
624+ assert .Equal (t , tt .expectedResult , result )
625+ })
626+ }
627+ }
0 commit comments