Skip to content

Commit a941850

Browse files
author
OpenShift Bot
authored
Merge pull request #11222 from jim-minter/issue10804
Merged by openshift-bot
2 parents f6bd74b + 3838d18 commit a941850

File tree

6 files changed

+51
-11
lines changed

6 files changed

+51
-11
lines changed

hack/util.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ function create_gitconfig() {
415415
function create_valid_file() {
416416
BASETMPDIR="${BASETMPDIR:-"/tmp"}"
417417
FILE_DIR=$(mktemp -d ${BASETMPDIR}/test-file.XXXX)
418-
touch ${FILE_DIR}/${1}
418+
echo test_data >${FILE_DIR}/${1}
419419
echo ${FILE_DIR}/${1}
420420
}
421421

pkg/cmd/cli/secrets/basicauth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (o *CreateBasicAuthSecretOptions) CreateBasicAuthSecret() error {
124124
func (o *CreateBasicAuthSecretOptions) NewBasicAuthSecret() (*api.Secret, error) {
125125
secret := &api.Secret{}
126126
secret.Name = o.SecretName
127-
secret.Type = api.SecretTypeOpaque
127+
secret.Type = api.SecretTypeBasicAuth
128128
secret.Data = map[string][]byte{}
129129

130130
if len(o.Username) != 0 {

pkg/cmd/cli/secrets/basicauth_test.go

+23-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package secrets
22

33
import (
44
"testing"
5+
6+
"k8s.io/kubernetes/pkg/api"
57
)
68

79
func TestValidateBasicAuth(t *testing.T) {
@@ -69,10 +71,28 @@ func TestValidateBasicAuth(t *testing.T) {
6971

7072
for _, test := range tests {
7173
options := test.params
72-
options.Complete(nil, test.args)
73-
err := options.Validate()
74-
if err != nil && !test.expErr {
74+
err := options.Complete(nil, test.args)
75+
if err == nil {
76+
err = options.Validate()
77+
}
78+
79+
if test.expErr {
80+
if err == nil {
81+
t.Errorf("%s: unexpected error: %v", test.testName, err)
82+
}
83+
continue
84+
}
85+
86+
if err != nil {
7587
t.Errorf("%s: unexpected error: %v", test.testName, err)
7688
}
89+
90+
secret, err := options.NewBasicAuthSecret()
91+
if err != nil {
92+
t.Errorf("%s: unexpected error: %v", test.testName, err)
93+
}
94+
if secret.Type != api.SecretTypeBasicAuth {
95+
t.Errorf("%s: unexpected secret.Type: %v", test.testName, secret.Type)
96+
}
7797
}
7898
}

pkg/cmd/cli/secrets/sshauth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (o *CreateSSHAuthSecretOptions) CreateSSHAuthSecret() error {
117117
func (o *CreateSSHAuthSecretOptions) NewSSHAuthSecret() (*api.Secret, error) {
118118
secret := &api.Secret{}
119119
secret.Name = o.SecretName
120-
secret.Type = api.SecretTypeOpaque
120+
secret.Type = api.SecretTypeSSHAuth
121121
secret.Data = map[string][]byte{}
122122

123123
if len(o.PrivateKeyPath) != 0 {

pkg/cmd/cli/secrets/sshauth_test.go

+23-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package secrets
22

33
import (
44
"testing"
5+
6+
"k8s.io/kubernetes/pkg/api"
57
)
68

79
func TestValidateSSHAuth(t *testing.T) {
@@ -47,10 +49,28 @@ func TestValidateSSHAuth(t *testing.T) {
4749

4850
for _, test := range tests {
4951
options := test.params
50-
options.Complete(nil, test.args)
51-
err := options.Validate()
52-
if err != nil && !test.expErr {
52+
err := options.Complete(nil, test.args)
53+
if err == nil {
54+
err = options.Validate()
55+
}
56+
57+
if test.expErr {
58+
if err == nil {
59+
t.Errorf("%s: unexpected error: %v", test.testName, err)
60+
}
61+
continue
62+
}
63+
64+
if err != nil {
5365
t.Errorf("%s: unexpected error: %v", test.testName, err)
5466
}
67+
68+
secret, err := options.NewSSHAuthSecret()
69+
if err != nil {
70+
t.Errorf("%s: unexpected error: %v", test.testName, err)
71+
}
72+
if secret.Type != api.SecretTypeSSHAuth {
73+
t.Errorf("%s: unexpected secret.Type: %v", test.testName, secret.Type)
74+
}
5575
}
5676
}

test/cmd/secrets.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ GIT_CONFIG_PATH=$(create_gitconfig)
5353
CA_CERT_PATH=$(create_valid_file ca.pem)
5454
PRIVATE_KEY_PATH=$(create_valid_file id_rsa)
5555

56-
os::cmd::expect_success 'oc secrets new-basicauth basicauth --username=sample-user --password=sample-password --gitconfig=$GIT_CONFIG_PATH --ca-cert=$PRIVATE_KEY_PATH'
56+
os::cmd::expect_success 'oc secrets new-basicauth basicauth --username=sample-user --password=sample-password --gitconfig=$GIT_CONFIG_PATH --ca-cert=$CA_CERT_PATH'
5757
# check to make sure two mutual exclusive flags return error as expected
5858
os::cmd::expect_failure_and_text 'oc secrets new-basicauth bad-file --password=sample-password --prompt' 'error: must provide either --prompt or --password flag'
5959
# check to make sure incorrect .gitconfig path fail as expected
6060
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'
6161

62-
os::cmd::expect_success 'oc secrets new-sshauth sshauth --ssh-privatekey=$PRIVATE_KEY_PATH --ca-cert=$PRIVATE_KEY_PATH'
62+
os::cmd::expect_success 'oc secrets new-sshauth sshauth --ssh-privatekey=$PRIVATE_KEY_PATH --ca-cert=$CA_CERT_PATH'
6363
# check to make sure incorrect SSH private-key path fail as expected
6464
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'
6565

0 commit comments

Comments
 (0)