@@ -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"
@@ -728,6 +729,7 @@ func (tc *testClient) validateOAuthState(t *testing.T, ctx context.Context, requ
728729 validationErrs = append (validationErrs , validateOAuthRoutes (ctx , tc .routeClient , tc .configClient , requireMissing )... )
729730 validationErrs = append (validationErrs , validateOAuthControllerConditions (tc .operatorClient , requireMissing )... )
730731 validationErrs = append (validationErrs , validateOperandVersions (ctx , tc .configClient , requireMissing )... )
732+ validationErrs = append (validationErrs , validateOAuthRelatedObjects (ctx , tc .configClient , requireMissing )... )
731733 return len (validationErrs ) == 0 , nil
732734 })
733735
@@ -900,6 +902,42 @@ func validateOperandVersions(ctx context.Context, cfgClient *configclient.Client
900902 return nil
901903}
902904
905+ func validateOAuthRelatedObjects (ctx context.Context , configClient * configclient.Clientset , requireMissing bool ) []error {
906+ co , err := configClient .ConfigV1 ().ClusterOperators ().Get (ctx , "authentication" , metav1.GetOptions {})
907+ if err != nil {
908+ return []error {err }
909+ }
910+
911+ oauthRelatedObjects := []configv1.ObjectReference {
912+ {Group : routev1 .GroupName , Resource : "routes" , Name : "oauth-openshift" , Namespace : "openshift-authentication" },
913+ {Resource : "services" , Name : "oauth-openshift" , Namespace : "openshift-authentication" },
914+ }
915+
916+ errs := make ([]error , 0 )
917+ for _ , oauthObj := range oauthRelatedObjects {
918+ found := false
919+ for _ , existingObj := range co .Status .RelatedObjects {
920+ if oauthObj .Group == existingObj .Group &&
921+ oauthObj .Resource == existingObj .Resource &&
922+ oauthObj .Name == existingObj .Name &&
923+ oauthObj .Namespace == existingObj .Namespace {
924+ found = true
925+ break
926+ }
927+ }
928+
929+ if requireMissing && found {
930+ errs = append (errs , fmt .Errorf ("oauth related object %s/%s %s/%s should be missing but was found in RelatedObjects" ,
931+ oauthObj .Group , oauthObj .Resource , oauthObj .Namespace , oauthObj .Name ))
932+ } else if ! requireMissing && ! found {
933+ errs = append (errs , fmt .Errorf ("oauth related object %s/%s %s/%s should be present but was not found in RelatedObjects" ,
934+ oauthObj .Group , oauthObj .Resource , oauthObj .Namespace , oauthObj .Name ))
935+ }
936+ }
937+
938+ return errs
939+ }
940+
903941func (tc * testClient ) testOIDCAuthentication (t * testing.T , ctx context.Context , kcClient * test.KeycloakClient , usernameClaim , usernamePrefix string , expectAuthSuccess bool ) {
904942 // re-authenticate to ensure we always have a fresh token
905943 var err error
0 commit comments