1
1
package e2e
2
2
3
3
import (
4
+ "encoding/json"
4
5
"fmt"
5
6
"strings"
6
7
"testing"
@@ -521,10 +522,82 @@ func TestOperatorGroupRoleAggregation(t *testing.T) {
521
522
_ , err = fetchCSV (t , crc , csvA .GetName (), nsA , csvSucceededChecker )
522
523
require .NoError (t , err )
523
524
525
+ // Create a csv for an apiserver
526
+ depName := genName ("hat-server" )
527
+ mockGroup := fmt .Sprintf ("hats.%s.redhat.com" , genName ("" ))
528
+ version := "v1alpha1"
529
+ mockGroupVersion := strings .Join ([]string {mockGroup , version }, "/" )
530
+ mockKinds := []string {"fez" , "fedora" }
531
+ mockNames := []string {"fezs" , "fedoras" }
532
+ depSpec := newMockExtServerDeployment (depName , mockGroupVersion , mockKinds )
533
+ strategy := install.StrategyDetailsDeployment {
534
+ DeploymentSpecs : []install.StrategyDeploymentSpec {
535
+ {
536
+ Name : depName ,
537
+ Spec : depSpec ,
538
+ },
539
+ },
540
+ }
541
+ strategyRaw , err := json .Marshal (strategy )
542
+ owned := make ([]v1alpha1.APIServiceDescription , len (mockKinds ))
543
+ for i , kind := range mockKinds {
544
+ owned [i ] = v1alpha1.APIServiceDescription {
545
+ Name : mockNames [i ],
546
+ Group : mockGroup ,
547
+ Version : version ,
548
+ Kind : kind ,
549
+ DeploymentName : depName ,
550
+ ContainerPort : int32 (5443 ),
551
+ DisplayName : kind ,
552
+ Description : fmt .Sprintf ("A %s" , kind ),
553
+ }
554
+ }
555
+
556
+ csvB := v1alpha1.ClusterServiceVersion {
557
+ Spec : v1alpha1.ClusterServiceVersionSpec {
558
+ MinKubeVersion : "0.0.0" ,
559
+ InstallModes : []v1alpha1.InstallMode {
560
+ {
561
+ Type : v1alpha1 .InstallModeTypeOwnNamespace ,
562
+ Supported : true ,
563
+ },
564
+ {
565
+ Type : v1alpha1 .InstallModeTypeSingleNamespace ,
566
+ Supported : true ,
567
+ },
568
+ {
569
+ Type : v1alpha1 .InstallModeTypeMultiNamespace ,
570
+ Supported : true ,
571
+ },
572
+ {
573
+ Type : v1alpha1 .InstallModeTypeAllNamespaces ,
574
+ Supported : true ,
575
+ },
576
+ },
577
+ InstallStrategy : v1alpha1.NamedInstallStrategy {
578
+ StrategyName : install .InstallStrategyNameDeployment ,
579
+ StrategySpecRaw : strategyRaw ,
580
+ },
581
+ APIServiceDefinitions : v1alpha1.APIServiceDefinitions {
582
+ Owned : owned ,
583
+ },
584
+ },
585
+ }
586
+ csvB .SetName (depName )
587
+
588
+ // Create the APIService CSV
589
+ cleanupCSV , err := createCSV (t , c , crc , csvB , nsA , false , true )
590
+ require .NoError (t , err )
591
+ defer cleanupCSV ()
592
+
593
+ _ , err = fetchCSV (t , crc , csvB .GetName (), nsA , csvSucceededChecker )
594
+ require .NoError (t , err )
595
+
524
596
// Ensure clusterroles created and aggregated for access provided APIs
525
597
padmin , cleanupPadmin := createProjectAdmin (t , c , nsA )
526
598
defer cleanupPadmin ()
527
599
600
+ // Check CRD access aggregated
528
601
err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
529
602
res , err := c .KubernetesInterface ().AuthorizationV1 ().SubjectAccessReviews ().Create (& authorizationv1.SubjectAccessReview {
530
603
Spec : authorizationv1.SubjectAccessReviewSpec {
@@ -548,6 +621,31 @@ func TestOperatorGroupRoleAggregation(t *testing.T) {
548
621
return res .Status .Allowed , nil
549
622
})
550
623
require .NoError (t , err )
624
+
625
+ // Check apiserver access aggregated
626
+ err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
627
+ res , err := c .KubernetesInterface ().AuthorizationV1 ().SubjectAccessReviews ().Create (& authorizationv1.SubjectAccessReview {
628
+ Spec : authorizationv1.SubjectAccessReviewSpec {
629
+ User : padmin ,
630
+ ResourceAttributes : & authorizationv1.ResourceAttributes {
631
+ Namespace : nsA ,
632
+ Group : mockGroup ,
633
+ Version : version ,
634
+ Resource : mockNames [1 ],
635
+ Verb : "create" ,
636
+ },
637
+ },
638
+ })
639
+ if err != nil {
640
+ return false , err
641
+ }
642
+ if res == nil {
643
+ return false , nil
644
+ }
645
+ t .Logf ("checking padmin for permission: %#v" , res )
646
+ return res .Status .Allowed , nil
647
+ })
648
+ require .NoError (t , err )
551
649
}
552
650
553
651
func TestOperatorGroupInstallModeSupport (t * testing.T ) {
0 commit comments