Skip to content

Commit

Permalink
Fix incorrect context name being created when using new tanzu platfor…
Browse files Browse the repository at this point in the history
…m endpoints (#808)

* Fix incorrect context name being created when using new endpoints

* Fix cosign documentation link as it seems to be migrated to new location
  • Loading branch information
anujc25 authored Sep 12, 2024
1 parent 3191e65 commit 0d8192a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/full/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ from the repository. You can find more details in the

### User experience

CLI verifies [cosign](https://docs.sigstore.dev/signing/quickstart/) signature of
CLI verifies [cosign](https://docs.sigstore.dev/quickstart/quickstart-cosign/) signature of
the plugin inventory image present in the repository. If the signature
verification is successful, it would download the plugin inventory image on the
user's machine and caches the verified plugin inventory image to improve the
Expand Down
2 changes: 1 addition & 1 deletion pkg/command/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func getString(data interface{}) string {
// pre-req orgName and endpoint is non-empty string
func prepareTanzuContextName(orgName, ucpEndpoint string, isStaging bool) string {
var contextName string
idpType := getIDPType(ucpEndpoint)
idpType := getIDPType(endpoint)
if idpType == config.UAAIdpType {
contextName = "tpsm"
} else {
Expand Down
94 changes: 62 additions & 32 deletions pkg/command/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,91 @@ import (

func TestPrepareTanzuContextName(t *testing.T) {
testCases := []struct {
orgName string
endpoint string
isStaging bool
forceCSP bool
expected string
orgName string
ucpEndpoint string
endpoint string
saasEndpoints []string
isStaging bool
forceCSP bool
expected string
}{
// Test case for normal input with no staging environment and default endpoint.
{
orgName: "MyOrg",
endpoint: centralconfig.DefaultTanzuPlatformEndpoint,
isStaging: false,
expected: "MyOrg",
orgName: "MyOrg",
ucpEndpoint: centralconfig.DefaultTanzuPlatformEndpoint,
endpoint: centralconfig.DefaultTanzuPlatformEndpoint,
saasEndpoints: []string{centralconfig.DefaultTanzuPlatformEndpoint},
isStaging: false,
expected: "MyOrg",
},
// Test case for normal input with staging environment and default endpoint.
{
orgName: "MyOrg",
endpoint: centralconfig.DefaultTanzuPlatformEndpoint,
isStaging: true,
expected: "MyOrg-staging",
orgName: "MyOrg",
ucpEndpoint: centralconfig.DefaultTanzuPlatformEndpoint,
endpoint: centralconfig.DefaultTanzuPlatformEndpoint,
saasEndpoints: []string{centralconfig.DefaultTanzuPlatformEndpoint},
isStaging: true,
expected: "MyOrg-staging",
},
// Test case for normal input with no staging environment and custom SaaS endpoint.
// Test case for normal input with no staging environment and custom endpoint with force CSP.
{
orgName: "MyOrg",
endpoint: "https://custom-endpoint.com",
isStaging: false,
expected: "MyOrg-86fd8133",
forceCSP: true,
orgName: "MyOrg",
ucpEndpoint: "https://ucp.custom-endpoint.com",
endpoint: "https://custom-endpoint.com",
saasEndpoints: []string{centralconfig.DefaultTanzuPlatformEndpoint},
isStaging: false,
expected: "MyOrg-70217fc3",
forceCSP: true,
},
// Test case for normal input with staging environment and custom SaaS endpoint.
// Test case for normal input with staging environment and custom endpoint with force CSP.
{
orgName: "MyOrg",
endpoint: "https://custom-endpoint.com",
isStaging: true,
expected: "MyOrg-staging-86fd8133",
forceCSP: true,
orgName: "MyOrg",
ucpEndpoint: "https://ucp.custom-endpoint.com",
endpoint: "https://custom-endpoint.com",
saasEndpoints: []string{centralconfig.DefaultTanzuPlatformEndpoint},
isStaging: true,
expected: "MyOrg-staging-70217fc3",
forceCSP: true,
},
// Test case for normal input with new ucpEndpoint and platform endpoints which are actually SaaS endpoints.
{
orgName: "MyOrg",
ucpEndpoint: "https://ucp.platform-dev.endpoint.com",
endpoint: "https://platform-dev.endpoint.com",
saasEndpoints: []string{"https://(www.)?platform(.)*.endpoint.com"},
expected: "MyOrg-9dfa8f6c",
},
// Test case for normal input with new ucpEndpoint and platform endpoints which are actually SaaS endpoints.
{
orgName: "MyOrg",
isStaging: true,
ucpEndpoint: "https://ucp.platform.endpoint.com",
endpoint: "https://platform.endpoint.com",
saasEndpoints: []string{"https://(www.)?platform(.)*.endpoint.com"},
expected: "MyOrg-staging-042532db",
},
// Test case for normal input custom SM endpoint.
{
// org and staging values are effectively ignored
orgName: "MyOrg",
isStaging: true,
endpoint: "https://custom-endpoint.com",
expected: "tpsm-86fd8133",
orgName: "MyOrg",
isStaging: true,
ucpEndpoint: "https://ucp.custom-endpoint.com",
endpoint: "https://custom-endpoint.com",
saasEndpoints: []string{centralconfig.DefaultTanzuPlatformEndpoint},
expected: "tpsm-70217fc3",
},
}

for _, tc := range testCases {
endpoint = tc.endpoint
forceCSP = tc.forceCSP
fakeDefaultCentralConfigReader := fakes.CentralConfig{}
fakeDefaultCentralConfigReader.GetTanzuPlatformSaaSEndpointListReturns([]string{centralconfig.DefaultTanzuPlatformEndpoint})
fakeDefaultCentralConfigReader.GetTanzuPlatformSaaSEndpointListReturns(tc.saasEndpoints)
centralconfig.DefaultCentralConfigReader = &fakeDefaultCentralConfigReader

actual := prepareTanzuContextName(tc.orgName, tc.endpoint, tc.isStaging)
actual := prepareTanzuContextName(tc.orgName, tc.ucpEndpoint, tc.isStaging)
if actual != tc.expected {
t.Errorf("orgName: %s, endpoint: %s, isStaging: %t - expected: %s, got: %s", tc.orgName, tc.endpoint, tc.isStaging, tc.expected, actual)
t.Errorf("orgName: %s, ucpEndpoint: %s endpoint: %s, isStaging: %t - expected: %s, got: %s", tc.orgName, tc.ucpEndpoint, tc.endpoint, tc.isStaging, tc.expected, actual)
}
}
}
Expand Down

0 comments on commit 0d8192a

Please sign in to comment.