@@ -17,6 +17,7 @@ import (
1717 configv1 "github.com/openshift/api/config/v1"
1818 "github.com/openshift/api/features"
1919 operatorv1 "github.com/openshift/api/operator/v1"
20+ routev1 "github.com/openshift/api/route/v1"
2021 configclient "github.com/openshift/client-go/config/clientset/versioned"
2122 oauthclient "github.com/openshift/client-go/oauth/clientset/versioned"
2223 operatorversionedclient "github.com/openshift/client-go/operator/clientset/versioned"
@@ -727,6 +728,7 @@ func (tc *testClient) validateOAuthState(t *testing.T, ctx context.Context, requ
727728 validationErrs = append (validationErrs , validateOAuthResources (ctx , dynamicClient , requireMissing )... )
728729 validationErrs = append (validationErrs , validateOAuthRoutes (ctx , tc .routeClient , tc .configClient , requireMissing )... )
729730 validationErrs = append (validationErrs , validateOAuthControllerConditions (tc .operatorClient , requireMissing )... )
731+ validationErrs = append (validationErrs , validateOAuthRelatedObjects (requireMissing )... )
730732 return len (validationErrs ) == 0 , nil
731733 })
732734
@@ -872,6 +874,42 @@ func validateOAuthControllerConditions(operatorClient v1helpers.OperatorClient,
872874 return nil
873875}
874876
877+ func validateOAuthRelatedObjects (ctx context.Context , configClient * configclient.Clientset , requireMissing bool ) []error {
878+ co , err := configClient .ConfigV1 ().ClusterOperators ().Get (ctx , "authentication" , metav1.GetOptions {})
879+ if err != nil {
880+ return []error {err }
881+ }
882+
883+ oauthRelatedObjects := []configv1.ObjectReference {
884+ {Group : routev1 .GroupName , Resource : "routes" , Name : "oauth-openshift" , Namespace : "openshift-authentication" },
885+ {Resource : "services" , Name : "oauth-openshift" , Namespace : "openshift-authentication" },
886+ }
887+
888+ errs := make ([]error , 0 )
889+ for _ , oauthObj := range oauthRelatedObjects {
890+ found := false
891+ for _ , existingObj := range co .Status .RelatedObjects {
892+ if oauthObj .Group == existingObj .Group &&
893+ oauthObj .Resource == existingObj .Resource &&
894+ oauthObj .Name == existingObj .Name &&
895+ oauthObj .Namespace == existingObj .Namespace {
896+ found = true
897+ break
898+ }
899+ }
900+
901+ if requireMissing && found {
902+ errs = append (errs , fmt .Errorf ("oauth related object %s/%s %s/%s should be missing but was found in RelatedObjects" ,
903+ oauthObj .Group , oauthObj .Resource , oauthObj .Namespace , oauthObj .Name ))
904+ } else if ! requireMissing && ! found {
905+ errs = append (errs , fmt .Errorf ("oauth related object %s/%s %s/%s should be present but was not found in RelatedObjects" ,
906+ oauthObj .Group , oauthObj .Resource , oauthObj .Namespace , oauthObj .Name ))
907+ }
908+ }
909+
910+ return errs
911+ }
912+
875913func (tc * testClient ) testOIDCAuthentication (t * testing.T , ctx context.Context , kcClient * test.KeycloakClient , usernameClaim , usernamePrefix string , expectAuthSuccess bool ) {
876914 // re-authenticate to ensure we always have a fresh token
877915 var err error
0 commit comments