Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions cmd/config/add_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,14 @@ func TestConfigAddProfileCmd_DuplicateProfileName(t *testing.T) {

// Test config add profile command fails when provided an invalid profile name
func TestConfigAddProfileCmd_InvalidProfileName(t *testing.T) {
expectedErrorPattern := `^failed to add profile: invalid profile name: '.*'\. name must be lowercase and contain only alphanumeric characters, underscores, and dashes$`
expectedErrorPattern := `^failed to add profile: invalid profile name: '.*'\. name must contain only alphanumeric characters, underscores, and dashes$`
err := testutils_cobra.ExecutePingcli(t, "config", "add-profile",
"--name", "pname&*^*&^$&@!",
"--description", "test description",
"--set-active=false")
testutils.CheckExpectedError(t, err, &expectedErrorPattern)
}

// Test Root Command fails when provided an invalid value containing uppercase character for profile name
func TestConfigAddProfileCmd_InvalidUpperCaseProfileName(t *testing.T) {
expectedErrorPattern := `^failed to add profile: invalid profile name: '.*'\. name must be lowercase and contain only alphanumeric characters, underscores, and dashes$`
err := testutils_cobra.ExecutePingcli(t, "config", "add-profile",
"--name", "myProfile",
"--description", "test description",
"--set-active=false")
testutils.CheckExpectedError(t, err, &expectedErrorPattern)
}

// Test config add profile command fails when provided an invalid set-active value
func TestConfigAddProfileCmd_InvalidSetActiveValue(t *testing.T) {
expectedErrorPattern := `^invalid argument ".*" for "-s, --set-active" flag: strconv\.ParseBool: parsing ".*": invalid syntax$`
Expand Down
2 changes: 1 addition & 1 deletion cmd/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestConfigCmd_HelpFlag(t *testing.T) {

// // Test Config Command fails when provided an invalid profile name
// func TestConfigCmd_InvalidProfileName(t *testing.T) {
// expectedErrorPattern := `^failed to update profile '.*' name to: .*\. invalid profile name: '.*'\. name must be lowercase and contain only alphanumeric characters, underscores, and dashes$`
// expectedErrorPattern := `^failed to update profile '.*' name to: .*\. invalid profile name: '.*'\. name must contain only alphanumeric characters, underscores, and dashes$`
// err := testutils_cobra.ExecutePingcli(t, "config",
// "--profile", "production",
// "--name", "pname&*^*&^$&@!",
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
pingcli config get --profile myprofile noColor

Read the worker ID used to authenticate to the PingOne service management API.
pingcli config get service.pingone.authentication.worker.environmentID
pingcli config get service.pingOne.authentication.worker.environmentID

Read the unmasked value for the request access token.
pingcli config get --unmask-values request.accessToken`
Expand All @@ -35,7 +35,7 @@ func NewConfigGetCommand() *cobra.Command {
RunE: configGetRunE,
Short: "Read stored configuration settings for the CLI.",
Use: "get [flags] key",
ValidArgs: configuration.ViperKeys(),
ValidArgs: configuration.KoanfKeys(),
}

return cmd
Expand Down
18 changes: 9 additions & 9 deletions cmd/config/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ func TestConfigGetCmd_Execute(t *testing.T) {
// Test Config Get Command fails when provided too many arguments
func TestConfigGetCmd_TooManyArgs(t *testing.T) {
expectedErrorPattern := `^failed to execute 'pingcli config get': command accepts 1 arg\(s\), received 2$`
err := testutils_cobra.ExecutePingcli(t, "config", "get", options.RootColorOption.ViperKey, options.RootOutputFormatOption.ViperKey)
err := testutils_cobra.ExecutePingcli(t, "config", "get", options.RootColorOption.KoanfKey, options.RootOutputFormatOption.KoanfKey)
testutils.CheckExpectedError(t, err, &expectedErrorPattern)
}

// Test Config Get Command Executes when provided a full key
func TestConfigGetCmd_FullKey(t *testing.T) {
err := testutils_cobra.ExecutePingcli(t, "config", "get", options.PingOneAuthenticationWorkerClientIDOption.ViperKey)
err := testutils_cobra.ExecutePingcli(t, "config", "get", options.PingOneAuthenticationWorkerClientIDOption.KoanfKey)
testutils.CheckExpectedError(t, err, nil)
}

// Test Config Get Command Executes when provided a partial key
func TestConfigGetCmd_PartialKey(t *testing.T) {
err := testutils_cobra.ExecutePingcli(t, "config", "get", "service.pingone")
err := testutils_cobra.ExecutePingcli(t, "config", "get", "service.pingOne")
testutils.CheckExpectedError(t, err, nil)
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func TestConfigGetCmd_NoKey(t *testing.T) {
// https://pkg.go.dev/testing#hdr-Examples
func Example_getEmptyMaskedValue() {
t := testing.T{}
_ = testutils_cobra.ExecutePingcli(&t, "config", "get", options.RequestAccessTokenOption.ViperKey)
_ = testutils_cobra.ExecutePingcli(&t, "config", "get", options.RequestAccessTokenOption.KoanfKey)

// Output:
// Configuration values for profile 'default' and key 'request.accessToken':
Expand All @@ -79,17 +79,17 @@ func Example_getEmptyMaskedValue() {
// https://pkg.go.dev/testing#hdr-Examples
func Example_getMaskedValue() {
t := testing.T{}
_ = testutils_cobra.ExecutePingcli(&t, "config", "get", options.PingFederateBasicAuthPasswordOption.ViperKey)
_ = testutils_cobra.ExecutePingcli(&t, "config", "get", options.PingFederateBasicAuthPasswordOption.KoanfKey)

// Output:
// Configuration values for profile 'default' and key 'service.pingfederate.authentication.basicAuth.password':
// service.pingfederate.authentication.basicAuth.password=********
// Configuration values for profile 'default' and key 'service.pingFederate.authentication.basicAuth.password':
// service.pingFederate.authentication.basicAuth.password=********
}

// https://pkg.go.dev/testing#hdr-Examples
func Example_getUnmaskedValue() {
t := testing.T{}
_ = testutils_cobra.ExecutePingcli(&t, "config", "get", options.RootColorOption.ViperKey)
_ = testutils_cobra.ExecutePingcli(&t, "config", "get", options.RootColorOption.KoanfKey)

// Output:
// Configuration values for profile 'default' and key 'noColor':
Expand All @@ -99,7 +99,7 @@ func Example_getUnmaskedValue() {
// https://pkg.go.dev/testing#hdr-Examples
func Example_get_UnmaskValuesFlag() {
t := testing.T{}
_ = testutils_cobra.ExecutePingcli(&t, "config", "get", "--unmask-values", options.RequestAccessTokenOption.ViperKey)
_ = testutils_cobra.ExecutePingcli(&t, "config", "get", "--unmask-values", options.RequestAccessTokenOption.KoanfKey)

// Output:
// Configuration values for profile 'default' and key 'request.accessToken':
Expand Down
40 changes: 20 additions & 20 deletions cmd/config/list_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestConfigListKeysCmd_HelpFlag(t *testing.T) {
// Test Config List Keys Command fails when provided too many arguments
func TestConfigListKeysCmd_TooManyArgs(t *testing.T) {
expectedErrorPattern := `^failed to execute 'pingcli config list-keys': command accepts 0 arg\(s\), received 1$`
err := testutils_cobra.ExecutePingcli(t, "config", "list-keys", options.RootColorOption.ViperKey)
err := testutils_cobra.ExecutePingcli(t, "config", "list-keys", options.RootColorOption.KoanfKey)
testutils.CheckExpectedError(t, err, &expectedErrorPattern)
}

Expand All @@ -54,7 +54,7 @@ func Example_listKeysValue() {
// - export.format
// - export.outputDirectory
// - export.overwrite
// - export.pingone.environmentID
// - export.pingOne.environmentID
// - export.serviceGroup
// - export.services
// - noColor
Expand All @@ -63,22 +63,22 @@ func Example_listKeysValue() {
// - request.accessTokenExpiry
// - request.fail
// - request.service
// - service.pingfederate.adminAPIPath
// - service.pingfederate.authentication.accessTokenAuth.accessToken
// - service.pingfederate.authentication.basicAuth.password
// - service.pingfederate.authentication.basicAuth.username
// - service.pingfederate.authentication.clientCredentialsAuth.clientID
// - service.pingfederate.authentication.clientCredentialsAuth.clientSecret
// - service.pingfederate.authentication.clientCredentialsAuth.scopes
// - service.pingfederate.authentication.clientCredentialsAuth.tokenURL
// - service.pingfederate.authentication.type
// - service.pingfederate.caCertificatePemFiles
// - service.pingfederate.httpsHost
// - service.pingfederate.insecureTrustAllTLS
// - service.pingfederate.xBypassExternalValidationHeader
// - service.pingone.authentication.type
// - service.pingone.authentication.worker.clientID
// - service.pingone.authentication.worker.clientSecret
// - service.pingone.authentication.worker.environmentID
// - service.pingone.regionCode
// - service.pingFederate.adminAPIPath
// - service.pingFederate.authentication.accessTokenAuth.accessToken
// - service.pingFederate.authentication.basicAuth.password
// - service.pingFederate.authentication.basicAuth.username
// - service.pingFederate.authentication.clientCredentialsAuth.clientID
// - service.pingFederate.authentication.clientCredentialsAuth.clientSecret
// - service.pingFederate.authentication.clientCredentialsAuth.scopes
// - service.pingFederate.authentication.clientCredentialsAuth.tokenURL
// - service.pingFederate.authentication.type
// - service.pingFederate.caCertificatePEMFiles
// - service.pingFederate.httpsHost
// - service.pingFederate.insecureTrustAllTLS
// - service.pingFederate.xBypassExternalValidationHeader
// - service.pingOne.authentication.type
// - service.pingOne.authentication.worker.clientID
// - service.pingOne.authentication.worker.clientSecret
// - service.pingOne.authentication.worker.environmentID
// - service.pingOne.regionCode
}
6 changes: 3 additions & 3 deletions cmd/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const (
pingcli config set color=true

Set the PingOne tenant region code setting to 'AP' for the profile named 'myprofile'.
pingcli config set --profile myprofile service.pingone.regionCode=AP
pingcli config set --profile myprofile service.pingOne.regionCode=AP

Set the PingFederate basic authentication password with unmasked output
pingcli config set --profile myprofile --unmask-values service.pingfederate.authentication.basicAuth.password=1234`
pingcli config set --profile myprofile --unmask-values service.pingFederate.authentication.basicAuth.password=1234`
)

func NewConfigSetCommand() *cobra.Command {
Expand All @@ -32,7 +32,7 @@ func NewConfigSetCommand() *cobra.Command {
RunE: configSetRunE,
Short: "Set stored configuration settings for the CLI.",
Use: "set [flags] key=value",
ValidArgs: configuration.ViperKeys(),
ValidArgs: configuration.KoanfKeys(),
}

return cmd
Expand Down
39 changes: 20 additions & 19 deletions cmd/config/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"testing"

"github.com/pingidentity/pingcli/internal/configuration/options"
"github.com/pingidentity/pingcli/internal/customtypes"
"github.com/pingidentity/pingcli/internal/profiles"
"github.com/pingidentity/pingcli/internal/testing/testutils"
"github.com/pingidentity/pingcli/internal/testing/testutils_cobra"
)

// Test Config Set Command Executes without issue
func TestConfigSetCmd_Execute(t *testing.T) {
err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=false", options.RootColorOption.ViperKey))
err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=false", options.RootColorOption.KoanfKey))
testutils.CheckExpectedError(t, err, nil)
}

Expand All @@ -28,7 +29,7 @@ func TestConfigSetCmd_TooFewArgs(t *testing.T) {
// Test Config Set Command Fails when provided too many arguments
func TestConfigSetCmd_TooManyArgs(t *testing.T) {
expectedErrorPattern := `^failed to execute 'pingcli config set': command accepts 1 arg\(s\), received 2$`
err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=false", options.RootColorOption.ViperKey), fmt.Sprintf("%s=true", options.RootColorOption.ViperKey))
err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=false", options.RootColorOption.KoanfKey), fmt.Sprintf("%s=true", options.RootColorOption.KoanfKey))
testutils.CheckExpectedError(t, err, &expectedErrorPattern)
}

Expand All @@ -42,31 +43,31 @@ func TestConfigSetCmd_InvalidKey(t *testing.T) {
// Test Config Set Command Fails when an invalid value type is provided
func TestConfigSetCmd_InvalidValueType(t *testing.T) {
expectedErrorPattern := `^failed to set configuration: value for key '.*' must be a boolean\. Allowed .*: strconv\.ParseBool: parsing ".*": invalid syntax$`
err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=invalid", options.RootColorOption.ViperKey))
err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=invalid", options.RootColorOption.KoanfKey))
testutils.CheckExpectedError(t, err, &expectedErrorPattern)
}

// Test Config Set Command Fails when no value is provided
func TestConfigSetCmd_NoValueProvided(t *testing.T) {
expectedErrorPattern := `^failed to set configuration: value for key '.*' is empty\. Use 'pingcli config unset .*' to unset the key$`
err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=", options.RootColorOption.ViperKey))
err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=", options.RootColorOption.KoanfKey))
testutils.CheckExpectedError(t, err, &expectedErrorPattern)
}

// Test Config Set Command for key 'pingone.worker.clientId' updates viper configuration
func TestConfigSetCmd_CheckViperConfig(t *testing.T) {
viperKey := options.PingOneAuthenticationWorkerClientIDOption.ViperKey
viperNewUUID := "12345678-1234-1234-1234-123456789012"
// Test Config Set Command for key 'pingone.worker.clientId' updates koanf configuration
func TestConfigSetCmd_CheckKoanfConfig(t *testing.T) {
koanfKey := options.PingOneAuthenticationWorkerClientIDOption.KoanfKey
koanfNewUUID := "12345678-1234-1234-1234-123456789012"

err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=%s", viperKey, viperNewUUID))
err := testutils_cobra.ExecutePingcli(t, "config", "set", fmt.Sprintf("%s=%s", koanfKey, koanfNewUUID))
testutils.CheckExpectedError(t, err, nil)

mainViper := profiles.GetMainConfig().ViperInstance()
profileViperKey := "default." + viperKey
koanf := profiles.GetKoanfConfig().KoanfInstance()
profileKoanfKey := "default." + koanfKey

viperNewValue := mainViper.GetString(profileViperKey)
if viperNewValue != viperNewUUID {
t.Errorf("Expected viper configuration value to be updated")
koanfNewValue, ok := koanf.Get(profileKoanfKey).(*customtypes.UUID)
if ok && koanfNewValue.String() != koanfNewUUID {
t.Errorf("Expected koanf configuration value to be updated")
}
}

Expand All @@ -89,27 +90,27 @@ func TestConfigSetCmd_InvalidFlag(t *testing.T) {
// https://pkg.go.dev/testing#hdr-Examples
func Example_setMaskedValue() {
t := testing.T{}
_ = testutils_cobra.ExecutePingcli(&t, "config", "set", fmt.Sprintf("%s=%s", options.PingFederateBasicAuthPasswordOption.ViperKey, "1234"))
_ = testutils_cobra.ExecutePingcli(&t, "config", "set", fmt.Sprintf("%s=%s", options.PingFederateBasicAuthPasswordOption.KoanfKey, "1234"))

// Output:
// SUCCESS: Configuration set successfully:
// service.pingfederate.authentication.basicAuth.password=********
// service.pingFederate.authentication.basicAuth.password=********
}

// https://pkg.go.dev/testing#hdr-Examples
func Example_set_UnmaskedValuesFlag() {
t := testing.T{}
_ = testutils_cobra.ExecutePingcli(&t, "config", "set", "--unmask-values", fmt.Sprintf("%s=%s", options.PingFederateBasicAuthPasswordOption.ViperKey, "1234"))
_ = testutils_cobra.ExecutePingcli(&t, "config", "set", "--unmask-values", fmt.Sprintf("%s=%s", options.PingFederateBasicAuthPasswordOption.KoanfKey, "1234"))

// Output:
// SUCCESS: Configuration set successfully:
// service.pingfederate.authentication.basicAuth.password=1234
// service.pingFederate.authentication.basicAuth.password=1234
}

// https://pkg.go.dev/testing#hdr-Examples
func Example_setUnmaskedValue() {
t := testing.T{}
_ = testutils_cobra.ExecutePingcli(&t, "config", "set", fmt.Sprintf("%s=%s", options.RootColorOption.ViperKey, "true"))
_ = testutils_cobra.ExecutePingcli(&t, "config", "set", fmt.Sprintf("%s=%s", options.RootColorOption.KoanfKey, "true"))

// Output:
// SUCCESS: Configuration set successfully:
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
pingcli config unset color

Unset the PingOne tenant region code setting for the profile named 'myprofile'.
pingcli config unset --profile myprofile service.pingone.regionCode`
pingcli config unset --profile myprofile service.pingOne.regionCode`
)

func NewConfigUnsetCommand() *cobra.Command {
Expand All @@ -29,7 +29,7 @@ func NewConfigUnsetCommand() *cobra.Command {
RunE: configUnsetRunE,
Short: "Unset stored configuration settings for the CLI.",
Use: "unset [flags] key",
ValidArgs: configuration.ViperKeys(),
ValidArgs: configuration.KoanfKeys(),
}

return cmd
Expand Down
Loading