diff --git a/test/e2e/parallel/spacebindingrequest_test.go b/test/e2e/parallel/spacebindingrequest_test.go index 4d02fc893..8c6193cd6 100644 --- a/test/e2e/parallel/spacebindingrequest_test.go +++ b/test/e2e/parallel/spacebindingrequest_test.go @@ -5,6 +5,7 @@ import ( "fmt" "sort" "testing" + "time" toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/gofrs/uuid" @@ -192,10 +193,10 @@ func TestUpdateSpaceBindingRequest(t *testing.T) { require.NoError(t, err) }) - t.Run("update space binding request MasterUserRecord", func(t *testing.T) { + t.Run("update space binding request MasterUserRecord is denied", func(t *testing.T) { // when space, spaceBindingRequest, _ := NewSpaceBindingRequest(t, awaitilities, memberAwait, hostAwait, "admin") - // let's create another MUR that will have access to the space + // let's create another MUR that will be used for the update request username := uuid.Must(uuid.NewV4()).String() _, newmur := NewSignupRequest(awaitilities). Username(username). @@ -205,24 +206,26 @@ func TestUpdateSpaceBindingRequest(t *testing.T) { RequireConditions(ConditionSet(Default(), ApprovedByAdmin())...). NoSpace(). WaitForMUR().Execute(t).Resources() - // and we update the MUR in the SBR - _, err := memberAwait.UpdateSpaceBindingRequest(t, types.NamespacedName{Namespace: spaceBindingRequest.Namespace, Name: spaceBindingRequest.Name}, + // and we try to update the MUR in the SBR + // with lower timeout since it will fail as expected + _, err := memberAwait.WithRetryOptions(TimeoutOption(time.Second*2)).UpdateSpaceBindingRequest(t, types.NamespacedName{Namespace: spaceBindingRequest.Namespace, Name: spaceBindingRequest.Name}, func(s *toolchainv1alpha1.SpaceBindingRequest) { s.Spec.MasterUserRecord = newmur.GetName() // set to the new MUR }, ) - require.NoError(t, err) + require.Error(t, err) // an error from the validating webhook is expected when trying to update the MUR field + require.EqualError(t, err, "admission webhook \"users.spacebindingrequests.webhook.sandbox\" denied the request: SpaceBindingRequest.MasterUserRecord field cannot be updated. Consider deleting and recreating the SpaceBindingRequest resource") //then // wait for both SpaceBindingRequest and SpaceBinding to have same MUR spaceBindingRequest, err = memberAwait.WaitForSpaceBindingRequest(t, types.NamespacedName{Namespace: spaceBindingRequest.GetNamespace(), Name: spaceBindingRequest.GetName()}, UntilSpaceBindingRequestHasConditions(spacebindingrequesttestcommon.Ready()), UntilSpaceBindingRequestHasSpecSpaceRole(spaceBindingRequest.Spec.SpaceRole), - UntilSpaceBindingRequestHasSpecMUR(newmur.GetName()), // new MUR + UntilSpaceBindingRequestHasSpecMUR(spaceBindingRequest.Spec.MasterUserRecord), // MUR should be the same ) require.NoError(t, err) _, err = hostAwait.WaitForSpaceBinding(t, spaceBindingRequest.Spec.MasterUserRecord, space.Name, - UntilSpaceBindingHasMurName(newmur.GetName()), // has new MUR + UntilSpaceBindingHasMurName(spaceBindingRequest.Spec.MasterUserRecord), // MUR should be the same UntilSpaceBindingHasSpaceName(space.Name), UntilSpaceBindingHasSpaceRole(spaceBindingRequest.Spec.SpaceRole), ) diff --git a/testsupport/wait/member.go b/testsupport/wait/member.go index 306d3b95b..3dab3c456 100644 --- a/testsupport/wait/member.go +++ b/testsupport/wait/member.go @@ -1426,7 +1426,7 @@ func (a *MemberAwaitility) UpdateSpaceBindingRequest(t *testing.T, spaceBindingR modifySpaceBindingRequest(freshSpaceBindingRequest) if err := a.Client.Update(context.TODO(), freshSpaceBindingRequest); err != nil { t.Logf("error updating SpaceBindingRequest '%s' in namespace '%s': %s. Will retry again...", spaceBindingRequestNamespacedName.Name, spaceBindingRequestNamespacedName.Name, err.Error()) - return false, nil + return false, err } sr = freshSpaceBindingRequest return true, nil @@ -2303,6 +2303,28 @@ func (a *MemberAwaitility) verifyUsersRolebindingsWebhookConfig(t *testing.T, ca assert.Equal(t, []string{"checlusters"}, checlusterRule.Resources) assert.Equal(t, admv1.NamespacedScope, *checlusterRule.Scope) + spacebindingrequestWebhook := actualValWbhConf.Webhooks[2] + assert.Equal(t, "users.spacebindingrequests.webhook.sandbox", spacebindingrequestWebhook.Name) + assert.Equal(t, []string{"v1"}, spacebindingrequestWebhook.AdmissionReviewVersions) + assert.Equal(t, admv1.SideEffectClassNone, *spacebindingrequestWebhook.SideEffects) + assert.Equal(t, int32(5), *spacebindingrequestWebhook.TimeoutSeconds) + assert.Equal(t, admv1.Ignore, *spacebindingrequestWebhook.FailurePolicy) + assert.Equal(t, admv1.Equivalent, *spacebindingrequestWebhook.MatchPolicy) + assert.Equal(t, codereadyToolchainProviderLabel, spacebindingrequestWebhook.NamespaceSelector.MatchLabels) + assert.Equal(t, ca, spacebindingrequestWebhook.ClientConfig.CABundle) + assert.Equal(t, "member-operator-webhook", spacebindingrequestWebhook.ClientConfig.Service.Name) + assert.Equal(t, a.Namespace, spacebindingrequestWebhook.ClientConfig.Service.Namespace) + assert.Equal(t, "/validate-spacebindingrequests", *spacebindingrequestWebhook.ClientConfig.Service.Path) + assert.Equal(t, int32(443), *spacebindingrequestWebhook.ClientConfig.Service.Port) + require.Len(t, spacebindingrequestWebhook.Rules, 1) + + spacebindingrequestRule := spacebindingrequestWebhook.Rules[0] + assert.Equal(t, []admv1.OperationType{admv1.Create, admv1.Update}, spacebindingrequestRule.Operations) + assert.Equal(t, []string{"toolchain.dev.openshift.com"}, spacebindingrequestRule.APIGroups) + assert.Equal(t, []string{"v1alpha1"}, spacebindingrequestRule.APIVersions) + assert.Equal(t, []string{"spacebindingrequests"}, spacebindingrequestRule.Resources) + assert.Equal(t, admv1.NamespacedScope, *spacebindingrequestRule.Scope) + } func (a *MemberAwaitility) WaitForAutoscalingBufferApp(t *testing.T) {