Skip to content

Commit 6c13fcc

Browse files
Merge pull request #856 from ecordell/adming-ag-test
test(olm): test role aggregation for aggregate apiservices
2 parents 02c6d31 + cd7ebd2 commit 6c13fcc

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

test/e2e/operator_groups_e2e_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package e2e
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"strings"
67
"testing"
@@ -521,10 +522,82 @@ func TestOperatorGroupRoleAggregation(t *testing.T) {
521522
_, err = fetchCSV(t, crc, csvA.GetName(), nsA, csvSucceededChecker)
522523
require.NoError(t, err)
523524

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+
524596
// Ensure clusterroles created and aggregated for access provided APIs
525597
padmin, cleanupPadmin := createProjectAdmin(t, c, nsA)
526598
defer cleanupPadmin()
527599

600+
// Check CRD access aggregated
528601
err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
529602
res, err := c.KubernetesInterface().AuthorizationV1().SubjectAccessReviews().Create(&authorizationv1.SubjectAccessReview{
530603
Spec: authorizationv1.SubjectAccessReviewSpec{
@@ -548,6 +621,31 @@ func TestOperatorGroupRoleAggregation(t *testing.T) {
548621
return res.Status.Allowed, nil
549622
})
550623
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)
551649
}
552650

553651
func TestOperatorGroupInstallModeSupport(t *testing.T) {

0 commit comments

Comments
 (0)