11package e2e
22
33import (
4+ "encoding/json"
45 "fmt"
56 "strings"
67 "testing"
@@ -496,10 +497,82 @@ func TestOperatorGroupRoleAggregation(t *testing.T) {
496497 _ , err = fetchCSV (t , crc , csvA .GetName (), nsA , csvSucceededChecker )
497498 require .NoError (t , err )
498499
500+ // Create a csv for an apiserver
501+ depName := genName ("hat-server" )
502+ mockGroup := fmt .Sprintf ("hats.%s.redhat.com" , genName ("" ))
503+ version := "v1alpha1"
504+ mockGroupVersion := strings .Join ([]string {mockGroup , version }, "/" )
505+ mockKinds := []string {"fez" , "fedora" }
506+ mockNames := []string {"fezs" , "fedoras" }
507+ depSpec := newMockExtServerDeployment (depName , mockGroupVersion , mockKinds )
508+ strategy := install.StrategyDetailsDeployment {
509+ DeploymentSpecs : []install.StrategyDeploymentSpec {
510+ {
511+ Name : depName ,
512+ Spec : depSpec ,
513+ },
514+ },
515+ }
516+ strategyRaw , err := json .Marshal (strategy )
517+ owned := make ([]v1alpha1.APIServiceDescription , len (mockKinds ))
518+ for i , kind := range mockKinds {
519+ owned [i ] = v1alpha1.APIServiceDescription {
520+ Name : mockNames [i ],
521+ Group : mockGroup ,
522+ Version : version ,
523+ Kind : kind ,
524+ DeploymentName : depName ,
525+ ContainerPort : int32 (5443 ),
526+ DisplayName : kind ,
527+ Description : fmt .Sprintf ("A %s" , kind ),
528+ }
529+ }
530+
531+ csvB := v1alpha1.ClusterServiceVersion {
532+ Spec : v1alpha1.ClusterServiceVersionSpec {
533+ MinKubeVersion : "0.0.0" ,
534+ InstallModes : []v1alpha1.InstallMode {
535+ {
536+ Type : v1alpha1 .InstallModeTypeOwnNamespace ,
537+ Supported : true ,
538+ },
539+ {
540+ Type : v1alpha1 .InstallModeTypeSingleNamespace ,
541+ Supported : true ,
542+ },
543+ {
544+ Type : v1alpha1 .InstallModeTypeMultiNamespace ,
545+ Supported : true ,
546+ },
547+ {
548+ Type : v1alpha1 .InstallModeTypeAllNamespaces ,
549+ Supported : true ,
550+ },
551+ },
552+ InstallStrategy : v1alpha1.NamedInstallStrategy {
553+ StrategyName : install .InstallStrategyNameDeployment ,
554+ StrategySpecRaw : strategyRaw ,
555+ },
556+ APIServiceDefinitions : v1alpha1.APIServiceDefinitions {
557+ Owned : owned ,
558+ },
559+ },
560+ }
561+ csvB .SetName (depName )
562+
563+ // Create the APIService CSV
564+ cleanupCSV , err := createCSV (t , c , crc , csvB , nsA , false , true )
565+ require .NoError (t , err )
566+ defer cleanupCSV ()
567+
568+ _ , err = fetchCSV (t , crc , csvB .GetName (), nsA , csvSucceededChecker )
569+ require .NoError (t , err )
570+
499571 // Ensure clusterroles created and aggregated for access provided APIs
500572 padmin , cleanupPadmin := createProjectAdmin (t , c , nsA )
501573 defer cleanupPadmin ()
502574
575+ // Check CRD access aggregated
503576 err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
504577 res , err := c .KubernetesInterface ().AuthorizationV1 ().SubjectAccessReviews ().Create (& authorizationv1.SubjectAccessReview {
505578 Spec : authorizationv1.SubjectAccessReviewSpec {
@@ -523,6 +596,31 @@ func TestOperatorGroupRoleAggregation(t *testing.T) {
523596 return res .Status .Allowed , nil
524597 })
525598 require .NoError (t , err )
599+
600+ // Check apiserver access aggregated
601+ err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
602+ res , err := c .KubernetesInterface ().AuthorizationV1 ().SubjectAccessReviews ().Create (& authorizationv1.SubjectAccessReview {
603+ Spec : authorizationv1.SubjectAccessReviewSpec {
604+ User : padmin ,
605+ ResourceAttributes : & authorizationv1.ResourceAttributes {
606+ Namespace : nsA ,
607+ Group : mockGroup ,
608+ Version : version ,
609+ Resource : mockNames [1 ],
610+ Verb : "create" ,
611+ },
612+ },
613+ })
614+ if err != nil {
615+ return false , err
616+ }
617+ if res == nil {
618+ return false , nil
619+ }
620+ t .Logf ("checking padmin for permission: %#v" , res )
621+ return res .Status .Allowed , nil
622+ })
623+ require .NoError (t , err )
526624}
527625
528626func TestOperatorGroupInstallModeSupport (t * testing.T ) {
0 commit comments