File tree 6 files changed +51
-11
lines changed
6 files changed +51
-11
lines changed Original file line number Diff line number Diff line change @@ -415,7 +415,7 @@ function create_gitconfig() {
415
415
function create_valid_file() {
416
416
BASETMPDIR=" ${BASETMPDIR:- " /tmp" } "
417
417
FILE_DIR=$( mktemp -d ${BASETMPDIR} /test-file.XXXX)
418
- touch ${FILE_DIR} /${1}
418
+ echo test_data > ${FILE_DIR} /${1}
419
419
echo ${FILE_DIR} /${1}
420
420
}
421
421
Original file line number Diff line number Diff line change @@ -124,7 +124,7 @@ func (o *CreateBasicAuthSecretOptions) CreateBasicAuthSecret() error {
124
124
func (o * CreateBasicAuthSecretOptions ) NewBasicAuthSecret () (* api.Secret , error ) {
125
125
secret := & api.Secret {}
126
126
secret .Name = o .SecretName
127
- secret .Type = api .SecretTypeOpaque
127
+ secret .Type = api .SecretTypeBasicAuth
128
128
secret .Data = map [string ][]byte {}
129
129
130
130
if len (o .Username ) != 0 {
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package secrets
2
2
3
3
import (
4
4
"testing"
5
+
6
+ "k8s.io/kubernetes/pkg/api"
5
7
)
6
8
7
9
func TestValidateBasicAuth (t * testing.T ) {
@@ -69,10 +71,28 @@ func TestValidateBasicAuth(t *testing.T) {
69
71
70
72
for _ , test := range tests {
71
73
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 {
75
87
t .Errorf ("%s: unexpected error: %v" , test .testName , err )
76
88
}
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
+ }
77
97
}
78
98
}
Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ func (o *CreateSSHAuthSecretOptions) CreateSSHAuthSecret() error {
117
117
func (o * CreateSSHAuthSecretOptions ) NewSSHAuthSecret () (* api.Secret , error ) {
118
118
secret := & api.Secret {}
119
119
secret .Name = o .SecretName
120
- secret .Type = api .SecretTypeOpaque
120
+ secret .Type = api .SecretTypeSSHAuth
121
121
secret .Data = map [string ][]byte {}
122
122
123
123
if len (o .PrivateKeyPath ) != 0 {
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package secrets
2
2
3
3
import (
4
4
"testing"
5
+
6
+ "k8s.io/kubernetes/pkg/api"
5
7
)
6
8
7
9
func TestValidateSSHAuth (t * testing.T ) {
@@ -47,10 +49,28 @@ func TestValidateSSHAuth(t *testing.T) {
47
49
48
50
for _ , test := range tests {
49
51
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 {
53
65
t .Errorf ("%s: unexpected error: %v" , test .testName , err )
54
66
}
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
+ }
55
75
}
56
76
}
Original file line number Diff line number Diff line change @@ -53,13 +53,13 @@ GIT_CONFIG_PATH=$(create_gitconfig)
53
53
CA_CERT_PATH=$( create_valid_file ca.pem)
54
54
PRIVATE_KEY_PATH=$( create_valid_file id_rsa)
55
55
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 '
57
57
# check to make sure two mutual exclusive flags return error as expected
58
58
os::cmd::expect_failure_and_text ' oc secrets new-basicauth bad-file --password=sample-password --prompt' ' error: must provide either --prompt or --password flag'
59
59
# check to make sure incorrect .gitconfig path fail as expected
60
60
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'
61
61
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 '
63
63
# check to make sure incorrect SSH private-key path fail as expected
64
64
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'
65
65
You can’t perform that action at this time.
0 commit comments