Skip to content

Commit

Permalink
Merge pull request #11222 from jim-minter/issue10804
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Oct 18, 2016
2 parents f6bd74b + 3838d18 commit a941850
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion hack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ function create_gitconfig() {
function create_valid_file() {
BASETMPDIR="${BASETMPDIR:-"/tmp"}"
FILE_DIR=$(mktemp -d ${BASETMPDIR}/test-file.XXXX)
touch ${FILE_DIR}/${1}
echo test_data >${FILE_DIR}/${1}
echo ${FILE_DIR}/${1}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/secrets/basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (o *CreateBasicAuthSecretOptions) CreateBasicAuthSecret() error {
func (o *CreateBasicAuthSecretOptions) NewBasicAuthSecret() (*api.Secret, error) {
secret := &api.Secret{}
secret.Name = o.SecretName
secret.Type = api.SecretTypeOpaque
secret.Type = api.SecretTypeBasicAuth
secret.Data = map[string][]byte{}

if len(o.Username) != 0 {
Expand Down
26 changes: 23 additions & 3 deletions pkg/cmd/cli/secrets/basicauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package secrets

import (
"testing"

"k8s.io/kubernetes/pkg/api"
)

func TestValidateBasicAuth(t *testing.T) {
Expand Down Expand Up @@ -69,10 +71,28 @@ func TestValidateBasicAuth(t *testing.T) {

for _, test := range tests {
options := test.params
options.Complete(nil, test.args)
err := options.Validate()
if err != nil && !test.expErr {
err := options.Complete(nil, test.args)
if err == nil {
err = options.Validate()
}

if test.expErr {
if err == nil {
t.Errorf("%s: unexpected error: %v", test.testName, err)
}
continue
}

if err != nil {
t.Errorf("%s: unexpected error: %v", test.testName, err)
}

secret, err := options.NewBasicAuthSecret()
if err != nil {
t.Errorf("%s: unexpected error: %v", test.testName, err)
}
if secret.Type != api.SecretTypeBasicAuth {
t.Errorf("%s: unexpected secret.Type: %v", test.testName, secret.Type)
}
}
}
2 changes: 1 addition & 1 deletion pkg/cmd/cli/secrets/sshauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (o *CreateSSHAuthSecretOptions) CreateSSHAuthSecret() error {
func (o *CreateSSHAuthSecretOptions) NewSSHAuthSecret() (*api.Secret, error) {
secret := &api.Secret{}
secret.Name = o.SecretName
secret.Type = api.SecretTypeOpaque
secret.Type = api.SecretTypeSSHAuth
secret.Data = map[string][]byte{}

if len(o.PrivateKeyPath) != 0 {
Expand Down
26 changes: 23 additions & 3 deletions pkg/cmd/cli/secrets/sshauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package secrets

import (
"testing"

"k8s.io/kubernetes/pkg/api"
)

func TestValidateSSHAuth(t *testing.T) {
Expand Down Expand Up @@ -47,10 +49,28 @@ func TestValidateSSHAuth(t *testing.T) {

for _, test := range tests {
options := test.params
options.Complete(nil, test.args)
err := options.Validate()
if err != nil && !test.expErr {
err := options.Complete(nil, test.args)
if err == nil {
err = options.Validate()
}

if test.expErr {
if err == nil {
t.Errorf("%s: unexpected error: %v", test.testName, err)
}
continue
}

if err != nil {
t.Errorf("%s: unexpected error: %v", test.testName, err)
}

secret, err := options.NewSSHAuthSecret()
if err != nil {
t.Errorf("%s: unexpected error: %v", test.testName, err)
}
if secret.Type != api.SecretTypeSSHAuth {
t.Errorf("%s: unexpected secret.Type: %v", test.testName, secret.Type)
}
}
}
4 changes: 2 additions & 2 deletions test/cmd/secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ GIT_CONFIG_PATH=$(create_gitconfig)
CA_CERT_PATH=$(create_valid_file ca.pem)
PRIVATE_KEY_PATH=$(create_valid_file id_rsa)

os::cmd::expect_success 'oc secrets new-basicauth basicauth --username=sample-user --password=sample-password --gitconfig=$GIT_CONFIG_PATH --ca-cert=$PRIVATE_KEY_PATH'
os::cmd::expect_success 'oc secrets new-basicauth basicauth --username=sample-user --password=sample-password --gitconfig=$GIT_CONFIG_PATH --ca-cert=$CA_CERT_PATH'
# check to make sure two mutual exclusive flags return error as expected
os::cmd::expect_failure_and_text 'oc secrets new-basicauth bad-file --password=sample-password --prompt' 'error: must provide either --prompt or --password flag'
# check to make sure incorrect .gitconfig path fail as expected
os::cmd::expect_failure_and_text 'oc secrets new-basicauth bad-file --username=user --gitconfig=/bad/path' 'error: open /bad/path: no such file or directory'

os::cmd::expect_success 'oc secrets new-sshauth sshauth --ssh-privatekey=$PRIVATE_KEY_PATH --ca-cert=$PRIVATE_KEY_PATH'
os::cmd::expect_success 'oc secrets new-sshauth sshauth --ssh-privatekey=$PRIVATE_KEY_PATH --ca-cert=$CA_CERT_PATH'
# check to make sure incorrect SSH private-key path fail as expected
os::cmd::expect_failure_and_text 'oc secrets new-sshauth bad-file --ssh-privatekey=/bad/path' 'error: open /bad/path: no such file or directory'

Expand Down

0 comments on commit a941850

Please sign in to comment.