Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
register/unregister runtime without tenant header (#2179)
Browse files Browse the repository at this point in the history
* register/unregister runtime without tenant header

* bump components versions

* fix util
  • Loading branch information
PetarTodorovv authored Jan 18, 2022
1 parent 59f1d94 commit d8f638e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 40 deletions.
2 changes: 1 addition & 1 deletion chart/compass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ global:
version: "PR-52"
e2e_tests:
dir:
version: "PR-2166"
version: "PR-2179"
isLocalEnv: false
oauth2:
host: oauth2
Expand Down
44 changes: 13 additions & 31 deletions tests/director/tests/runtime_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,67 +456,51 @@ func TestRuntimeRegisterUpdateAndUnregisterWithCertificate(t *testing.T) {
t.Run("Test runtime operations(CUD) with externally issued certificate", func(t *testing.T) {
// GIVEN
ctx := context.Background()
subscriptionProviderSubaccountID := tenant.TestTenants.GetIDByName(t, tenant.TestProviderSubaccount)

// Build graphql director client configured with certificate
clientKey, rawCertChain := certs.ClientCertPair(t, conf.ExternalCA.Certificate, conf.ExternalCA.Key)
directorCertSecuredClient := gql.NewCertAuthorizedGraphQLClientWithCustomURL(conf.DirectorExternalCertSecuredURL, clientKey, rawCertChain, conf.SkipSSLValidation)

protectedConsumerSubaccountIdsLabel := "consumer_subaccount_ids"

runtimeInput := graphql.RuntimeInput{
runtimeInput := &graphql.RuntimeInput{
Name: "register-runtime-with-protected-labels",
Description: ptr.String("register-runtime-with-protected-labels-description"),
Labels: graphql.Labels{protectedConsumerSubaccountIdsLabel: []string{"subaccountID-1", "subaccountID-2"}},
}
actualRtm := graphql.RuntimeExt{}

t.Log("Successfully register runtime using certificate with protected labels and validate that they are excluded")
// GIVEN
runtimeInGQL, err := testctx.Tc.Graphqlizer.RuntimeInputToGQL(runtimeInput)
require.NoError(t, err)

// WHEN
registerReq := fixtures.FixRegisterRuntimeRequest(runtimeInGQL)
err = testctx.Tc.RunOperationWithoutTenant(ctx, directorCertSecuredClient, registerReq, &actualRtm)
defer fixtures.CleanupRuntime(t, ctx, directorCertSecuredClient, subscriptionProviderSubaccountID, &actualRtm)
actualRtm := fixtures.RegisterRuntimeFromInputWithoutTenant(t, ctx, directorCertSecuredClient, runtimeInput)
defer fixtures.CleanupRuntimeWithoutTenant(t, ctx, directorCertSecuredClient, &actualRtm)

//THEN
require.NoError(t, err)
require.NotEmpty(t, actualRtm.ID)
require.Equal(t, runtimeInput.Name, actualRtm.Name)
require.Equal(t, runtimeInput.Description, actualRtm.Description)
require.Empty(t, actualRtm.Labels[protectedConsumerSubaccountIdsLabel])

t.Log("Successfully register runtime with certificate")
// GIVEN
runtimeInput = graphql.RuntimeInput{
runtimeInput = &graphql.RuntimeInput{
Name: "runtime-create-update-delete",
Description: ptr.String("runtime-create-update-delete-description"),
Labels: graphql.Labels{conf.SelfRegisterDistinguishLabelKey: []interface{}{"distinguish-label-value"}, tenantfetcher.RegionKey: tenantfetcher.RegionPathParamValue},
Labels: graphql.Labels{conf.SelfRegisterDistinguishLabelKey: []interface{}{"id-value!t12345"}, tenantfetcher.RegionKey: tenantfetcher.RegionPathParamValue},
}
actualRuntime := graphql.RuntimeExt{}

runtimeInGQL, err = testctx.Tc.Graphqlizer.RuntimeInputToGQL(runtimeInput)
require.NoError(t, err)

// WHEN
registerReq = fixtures.FixRegisterRuntimeRequest(runtimeInGQL)
err = testctx.Tc.RunOperationWithoutTenant(ctx, directorCertSecuredClient, registerReq, &actualRuntime)
defer fixtures.CleanupRuntime(t, ctx, directorCertSecuredClient, subscriptionProviderSubaccountID, &actualRuntime)
actualRuntime := fixtures.RegisterRuntimeFromInputWithoutTenant(t, ctx, directorCertSecuredClient, runtimeInput)
defer fixtures.CleanupRuntimeWithoutTenant(t, ctx, directorCertSecuredClient, &actualRuntime)

//THEN
require.NoError(t, err)
require.NotEmpty(t, actualRuntime.ID)
assertions.AssertRuntime(t, runtimeInput, actualRuntime, conf.DefaultScenarioEnabled, true)
assertions.AssertRuntime(t, *runtimeInput, actualRuntime, conf.DefaultScenarioEnabled, true)

t.Log("Successfully set regular runtime label using certificate")
// GIVEN
actualLabel := graphql.Label{}

// WHEN
addLabelReq := fixtures.FixSetRuntimeLabelRequest(actualRuntime.ID, "regular_label", []string{"labelValue"})
err = testctx.Tc.RunOperationWithoutTenant(ctx, directorCertSecuredClient, addLabelReq, &actualLabel)
err := testctx.Tc.RunOperationWithoutTenant(ctx, directorCertSecuredClient, addLabelReq, &actualLabel)

//THEN
require.NoError(t, err)
Expand Down Expand Up @@ -549,12 +533,12 @@ func TestRuntimeRegisterUpdateAndUnregisterWithCertificate(t *testing.T) {
runtimeInput.Name = "updated-runtime"
runtimeInput.Description = ptr.String("updated-runtime-description")
runtimeInput.Labels = graphql.Labels{
conf.SelfRegisterDistinguishLabelKey: []interface{}{"distinguish-label-value"}, tenantfetcher.RegionKey: tenantfetcher.RegionPathParamValue, protectedConsumerSubaccountIdsLabel: []interface{}{"subaccountID-1", "subaccountID-2"},
conf.SelfRegisterDistinguishLabelKey: []interface{}{"id-value!t12345"}, tenantfetcher.RegionKey: tenantfetcher.RegionPathParamValue, protectedConsumerSubaccountIdsLabel: []interface{}{"subaccountID-1", "subaccountID-2"},
}
runtimeStatusCond := graphql.RuntimeStatusConditionConnected
runtimeInput.StatusCondition = &runtimeStatusCond

runtimeInGQL, err = testctx.Tc.Graphqlizer.RuntimeInputToGQL(runtimeInput)
runtimeInGQL, err := testctx.Tc.Graphqlizer.RuntimeInputToGQL(*runtimeInput)
require.NoError(t, err)
updateRuntimeReq := fixtures.FixUpdateRuntimeRequest(actualRuntime.ID, runtimeInGQL)

Expand Down Expand Up @@ -586,7 +570,6 @@ func TestQueryRuntimesWithCertificate(t *testing.T) {
t.Run("Query runtime with externally issued certificate", func(t *testing.T) {
// GIVEN
ctx := context.Background()
subscriptionProviderSubaccountID := tenant.TestTenants.GetIDByName(t, tenant.TestProviderSubaccount)

// Build graphql director client configured with certificate
clientKey, rawCertChain := certs.ClientCertPair(t, conf.ExternalCA.Certificate, conf.ExternalCA.Key)
Expand All @@ -596,7 +579,7 @@ func TestQueryRuntimesWithCertificate(t *testing.T) {
defer func() {
for _, id := range idsToRemove {
if id != "" {
fixtures.UnregisterRuntime(t, ctx, directorCertSecuredClient, subscriptionProviderSubaccountID, id)
fixtures.UnregisterRuntimeWithoutTenant(t, ctx, directorCertSecuredClient, id)
}
}
}()
Expand Down Expand Up @@ -652,7 +635,6 @@ func TestQuerySpecificRuntimeWithCertificate(t *testing.T) {
t.Run("Query specific runtime with externally issued certificate", func(t *testing.T) {
// GIVEN
ctx := context.Background()
subscriptionProviderSubaccountID := tenant.TestTenants.GetIDByName(t, tenant.TestProviderSubaccount)

// Build graphql director client configured with certificate
clientKey, rawCertChain := certs.ClientCertPair(t, conf.ExternalCA.Certificate, conf.ExternalCA.Key)
Expand All @@ -666,7 +648,7 @@ func TestQuerySpecificRuntimeWithCertificate(t *testing.T) {
registerReq := fixtures.FixRegisterRuntimeRequest(runtimeInGQL)
createdRuntime := graphql.RuntimeExt{}
err = testctx.Tc.RunOperationWithoutTenant(ctx, directorCertSecuredClient, registerReq, &createdRuntime)
defer fixtures.CleanupRuntime(t, ctx, directorCertSecuredClient, subscriptionProviderSubaccountID, &createdRuntime)
defer fixtures.CleanupRuntimeWithoutTenant(t, ctx, directorCertSecuredClient, &createdRuntime)

require.NoError(t, err)
require.NotEmpty(t, createdRuntime.ID)
Expand Down
13 changes: 5 additions & 8 deletions tests/ord-service/tests/subscription_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func TestSelfRegisterFlow(stdT *testing.T) {

// defaultTenantId is the parent of the subaccountID
defaultTenantId := tenant.TestTenants.GetDefaultTenantID()
subaccountID := tenant.TestTenants.GetIDByName(t, tenant.TestProviderSubaccount)

// Build graphql director client configured with certificate
clientKey, rawCertChain := certs.ClientCertPair(t, testConfig.ExternalCA.Certificate, testConfig.ExternalCA.Key)
Expand Down Expand Up @@ -76,9 +75,8 @@ func TestSelfRegisterFlow(stdT *testing.T) {
Description: ptr.String("selfRegisterRuntime-description"),
Labels: graphql.Labels{testConfig.SelfRegisterDistinguishLabelKey: distinguishLblValue},
}
runtime, err := fixtures.RegisterRuntimeFromInputWithinTenant(t, ctx, directorCertSecuredClient, subaccountID, &runtimeInput)
defer fixtures.CleanupRuntime(t, ctx, directorCertSecuredClient, subaccountID, &runtime)
require.NoError(t, err)
runtime := fixtures.RegisterRuntimeFromInputWithoutTenant(t, ctx, directorCertSecuredClient, &runtimeInput)
defer fixtures.CleanupRuntimeWithoutTenant(t, ctx, directorCertSecuredClient, &runtime)
require.NotEmpty(t, runtime.ID)
strLbl, ok := runtime.Labels[testConfig.SelfRegisterLabelKey].(string)
require.True(t, ok)
Expand All @@ -87,7 +85,7 @@ func TestSelfRegisterFlow(stdT *testing.T) {
// Verify that the label returned cannot be modified
setLabelRequest := fixtures.FixSetRuntimeLabelRequest(runtime.ID, testConfig.SelfRegisterLabelKey, "value")
label := graphql.Label{}
err = testctx.Tc.RunOperationWithCustomTenant(ctx, directorCertSecuredClient, subaccountID, setLabelRequest, &label)
err = testctx.Tc.RunOperationWithoutTenant(ctx, directorCertSecuredClient, setLabelRequest, &label)
require.Error(t, err)
require.Contains(t, err.Error(), fmt.Sprintf("could not set unmodifiable label with key %s", testConfig.SelfRegisterLabelKey))

Expand Down Expand Up @@ -124,9 +122,8 @@ func TestConsumerProviderFlow(stdT *testing.T) {
}

// Register provider runtime with the necessary label
runtime, err := fixtures.RegisterRuntimeFromInputWithinTenant(t, ctx, directorCertSecuredClient, subscriptionProviderSubaccountID, &runtimeInput)
defer fixtures.CleanupRuntime(t, ctx, directorCertSecuredClient, subscriptionProviderSubaccountID, &runtime)
require.NoError(t, err)
runtime := fixtures.RegisterRuntimeFromInputWithoutTenant(t, ctx, directorCertSecuredClient, &runtimeInput)
defer fixtures.CleanupRuntimeWithoutTenant(t, ctx, directorCertSecuredClient, &runtime)
require.NotEmpty(t, runtime.ID)

// Register application
Expand Down
32 changes: 32 additions & 0 deletions tests/pkg/fixtures/runtime_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ func RegisterRuntimeFromInputWithinTenant(t require.TestingT, ctx context.Contex
return runtime, err
}

func RegisterRuntimeFromInputWithoutTenant(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, input *graphql.RuntimeInput) graphql.RuntimeExt {
inputGQL, err := testctx.Tc.Graphqlizer.RuntimeInputToGQL(*input)
require.NoError(t, err)

registerRuntimeRequest := FixRegisterRuntimeRequest(inputGQL)
var runtime graphql.RuntimeExt

err = testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, registerRuntimeRequest, &runtime)
require.NoError(t, err)
return runtime
}

func RequestClientCredentialsForRuntime(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, tenant, id string) graphql.RuntimeSystemAuth {
req := FixRequestClientCredentialsForRuntime(id)
systemAuth := graphql.RuntimeSystemAuth{}
Expand All @@ -41,6 +53,16 @@ func UnregisterRuntime(t require.TestingT, ctx context.Context, gqlClient *gcli.
require.NoError(t, err)
}

func UnregisterRuntimeWithoutTenant(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, id string) {
if id == "" {
return
}
delReq := FixUnregisterRuntimeRequest(id)

err := testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, delReq, nil)
require.NoError(t, err)
}

func CleanupRuntime(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, tenant string, rtm *graphql.RuntimeExt) {
if rtm == nil || rtm.ID == "" {
return
Expand All @@ -51,6 +73,16 @@ func CleanupRuntime(t require.TestingT, ctx context.Context, gqlClient *gcli.Cli
assertions.AssertNoErrorForOtherThanNotFound(t, err)
}

func CleanupRuntimeWithoutTenant(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, rtm *graphql.RuntimeExt) {
if rtm == nil || rtm.ID == "" {
return
}
delReq := FixUnregisterRuntimeRequest(rtm.ID)

err := testctx.Tc.RunOperationWithoutTenant(ctx, gqlClient, delReq, nil)
assertions.AssertNoErrorForOtherThanNotFound(t, err)
}

func GetRuntime(t require.TestingT, ctx context.Context, gqlClient *gcli.Client, tenant, id string) graphql.RuntimeExt {
req := FixGetRuntimeRequest(id)
runtime := graphql.RuntimeExt{}
Expand Down

0 comments on commit d8f638e

Please sign in to comment.