-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow API to manage AD Users and Reader AD Users (#677)
* Allow API to manage AD Users and Reader AD Users * Update swagger * Add test for Getting application, ad users is set * Update operator * Update types to imply AdUsers is always set * update operator
- Loading branch information
Showing
8 changed files
with
120 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ import ( | |
"github.com/equinor/radix-operator/pkg/apis/radixvalidators" | ||
commontest "github.com/equinor/radix-operator/pkg/apis/test" | ||
builders "github.com/equinor/radix-operator/pkg/apis/utils" | ||
"github.com/equinor/radix-operator/pkg/client/clientset/versioned/fake" | ||
radixfake "github.com/equinor/radix-operator/pkg/client/clientset/versioned/fake" | ||
"github.com/google/uuid" | ||
kedafake "github.com/kedacore/keda/v2/pkg/generated/clientset/versioned/fake" | ||
prometheusfake "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned/fake" | ||
"github.com/stretchr/testify/assert" | ||
|
@@ -49,7 +50,7 @@ const ( | |
subscriptionId = "12347718-c8f8-4995-bfbb-02655ff1f89c" | ||
) | ||
|
||
func setupTest(t *testing.T, requireAppConfigurationItem, requireAppADGroups bool) (*commontest.Utils, *controllertest.Utils, *kubefake.Clientset, *fake.Clientset, *kedafake.Clientset, *prometheusfake.Clientset, *secretproviderfake.Clientset, *certfake.Clientset) { | ||
func setupTest(t *testing.T, requireAppConfigurationItem, requireAppADGroups bool) (*commontest.Utils, *controllertest.Utils, *kubefake.Clientset, *radixfake.Clientset, *kedafake.Clientset, *prometheusfake.Clientset, *secretproviderfake.Clientset, *certfake.Clientset) { | ||
return setupTestWithFactory(t, newTestApplicationHandlerFactory( | ||
ApplicationHandlerConfig{RequireAppConfigurationItem: requireAppConfigurationItem, RequireAppADGroups: requireAppADGroups}, | ||
func(ctx context.Context, kubeClient kubernetes.Interface, namespace string, configMapName string) (bool, error) { | ||
|
@@ -58,10 +59,10 @@ func setupTest(t *testing.T, requireAppConfigurationItem, requireAppADGroups boo | |
)) | ||
} | ||
|
||
func setupTestWithFactory(t *testing.T, handlerFactory ApplicationHandlerFactory) (*commontest.Utils, *controllertest.Utils, *kubefake.Clientset, *fake.Clientset, *kedafake.Clientset, *prometheusfake.Clientset, *secretproviderfake.Clientset, *certfake.Clientset) { | ||
func setupTestWithFactory(t *testing.T, handlerFactory ApplicationHandlerFactory) (*commontest.Utils, *controllertest.Utils, *kubefake.Clientset, *radixfake.Clientset, *kedafake.Clientset, *prometheusfake.Clientset, *secretproviderfake.Clientset, *certfake.Clientset) { | ||
// Setup | ||
kubeclient := kubefake.NewSimpleClientset() | ||
radixclient := fake.NewSimpleClientset() | ||
radixclient := radixfake.NewSimpleClientset() | ||
kedaClient := kedafake.NewSimpleClientset() | ||
prometheusclient := prometheusfake.NewSimpleClientset() | ||
secretproviderclient := secretproviderfake.NewSimpleClientset() | ||
|
@@ -809,12 +810,17 @@ func TestGetApplication_AllFieldsAreSet(t *testing.T) { | |
// Setup | ||
_, controllerTestUtils, _, _, _, _, _, _ := setupTest(t, true, true) | ||
|
||
adGroups, adUsers := []string{uuid.New().String()}, []string{uuid.New().String()} | ||
readerAdGroups, readerAdUsers := []string{uuid.New().String()}, []string{uuid.New().String()} | ||
parameters := buildApplicationRegistrationRequest( | ||
anApplicationRegistration(). | ||
WithName("any-name"). | ||
WithRepository("https://github.com/Equinor/any-repo"). | ||
WithSharedSecret("Any secret"). | ||
WithAdGroups([]string{"a6a3b81b-34gd-sfsf-saf2-7986371ea35f"}). | ||
WithAdGroups(adGroups). | ||
WithAdUsers(adUsers). | ||
WithReaderAdGroups(readerAdGroups). | ||
WithReaderAdUsers(readerAdUsers). | ||
WithConfigBranch("abranch"). | ||
WithRadixConfigFullName("a/custom-radixconfig.yaml"). | ||
WithConfigurationItem("ci"). | ||
|
@@ -835,7 +841,10 @@ func TestGetApplication_AllFieldsAreSet(t *testing.T) { | |
|
||
assert.Equal(t, "https://github.com/Equinor/any-repo", application.Registration.Repository) | ||
assert.Equal(t, "Any secret", application.Registration.SharedSecret) | ||
assert.Equal(t, []string{"a6a3b81b-34gd-sfsf-saf2-7986371ea35f"}, application.Registration.AdGroups) | ||
assert.Equal(t, adGroups, application.Registration.AdGroups) | ||
assert.Equal(t, adUsers, application.Registration.AdUsers) | ||
assert.Equal(t, readerAdGroups, application.Registration.ReaderAdGroups) | ||
assert.Equal(t, readerAdUsers, application.Registration.ReaderAdUsers) | ||
assert.Equal(t, "[email protected]", application.Registration.Creator) | ||
assert.Equal(t, "abranch", application.Registration.ConfigBranch) | ||
assert.Equal(t, "a/custom-radixconfig.yaml", application.Registration.RadixConfigFullName) | ||
|
@@ -1157,8 +1166,10 @@ func TestModifyApplication_AbleToSetField(t *testing.T) { | |
WithName("any-name"). | ||
WithRepository("https://github.com/Equinor/a-repo"). | ||
WithSharedSecret(""). | ||
WithAdGroups([]string{"a5dfa635-dc00-4a28-9ad9-9e7f1e56919d"}). | ||
WithReaderAdGroups([]string{"d5df55c1-78b7-4330-9d2c-f1b1aa5584ca"}). | ||
WithAdGroups([]string{uuid.New().String()}). | ||
WithAdUsers([]string{uuid.New().String()}). | ||
WithReaderAdGroups([]string{uuid.New().String()}). | ||
WithReaderAdUsers([]string{uuid.New().String()}). | ||
WithOwner("[email protected]"). | ||
WithWBS("T.O123A.AZ.45678"). | ||
WithConfigBranch("main1"). | ||
|
@@ -1167,10 +1178,12 @@ func TestModifyApplication_AbleToSetField(t *testing.T) { | |
<-responseChannel | ||
|
||
// Test | ||
anyNewAdGroup := []string{"98765432-dc00-4a28-9ad9-9e7f1e56919d"} | ||
anyNewAdGroup := []string{uuid.New().String()} | ||
anyNewAdUser := []string{uuid.New().String()} | ||
patchRequest := applicationModels.ApplicationRegistrationPatchRequest{ | ||
ApplicationRegistrationPatch: &applicationModels.ApplicationRegistrationPatch{ | ||
AdGroups: &anyNewAdGroup, | ||
AdUsers: &anyNewAdUser, | ||
}, | ||
} | ||
|
||
|
@@ -1185,16 +1198,19 @@ func TestModifyApplication_AbleToSetField(t *testing.T) { | |
err := controllertest.GetResponseBody(response, &application) | ||
require.NoError(t, err) | ||
assert.Equal(t, anyNewAdGroup, application.Registration.AdGroups) | ||
assert.Equal(t, anyNewAdUser, application.Registration.AdUsers) | ||
assert.Equal(t, "[email protected]", application.Registration.Owner) | ||
assert.Equal(t, "T.O123A.AZ.45678", application.Registration.WBS) | ||
assert.Equal(t, "main1", application.Registration.ConfigBranch) | ||
assert.Equal(t, "ci-initial", application.Registration.ConfigurationItem) | ||
|
||
// Test | ||
anyNewReaderAdGroup := []string{"44643b96-0f6d-4bdc-af2c-a4f596d821eb"} | ||
anyNewReaderAdGroup := []string{uuid.New().String()} | ||
anyNewReaderAdUser := []string{uuid.New().String()} | ||
patchRequest = applicationModels.ApplicationRegistrationPatchRequest{ | ||
ApplicationRegistrationPatch: &applicationModels.ApplicationRegistrationPatch{ | ||
ReaderAdGroups: &anyNewReaderAdGroup, | ||
ReaderAdUsers: &anyNewReaderAdUser, | ||
}, | ||
} | ||
|
||
|
@@ -1209,6 +1225,7 @@ func TestModifyApplication_AbleToSetField(t *testing.T) { | |
err = controllertest.GetResponseBody(response, &application) | ||
require.NoError(t, err) | ||
assert.Equal(t, anyNewReaderAdGroup, application.Registration.ReaderAdGroups) | ||
assert.Equal(t, anyNewReaderAdUser, application.Registration.ReaderAdUsers) | ||
|
||
// Test | ||
anyNewOwner := "[email protected]" | ||
|
@@ -1924,7 +1941,7 @@ func createRadixJob(commonTestUtils *commontest.Utils, appName, jobName string, | |
return err | ||
} | ||
|
||
func getJobsInNamespace(radixclient *fake.Clientset, appNamespace string) ([]v1.RadixJob, error) { | ||
func getJobsInNamespace(radixclient *radixfake.Clientset, appNamespace string) ([]v1.RadixJob, error) { | ||
jobs, err := radixclient.RadixV1().RadixJobs(appNamespace).List(context.Background(), metav1.ListOptions{}) | ||
if err != nil { | ||
return nil, err | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters