|
...
|
...
|
@@ -6,54 +6,55 @@ set -o pipefail
|
|
6
|
6
|
|
|
7
|
7
|
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
|
8
|
8
|
source "${OS_ROOT}/hack/util.sh"
|
|
|
9
|
+source "${OS_ROOT}/hack/cmd_util.sh"
|
|
9
|
10
|
os::log::install_errexit
|
|
10
|
11
|
|
|
11
|
12
|
# This test validates secret interaction
|
|
12
|
13
|
|
|
13
|
|
-oc secrets new-dockercfg dockercfg --docker-username=sample-user --docker-password=sample-password --docker-email=fake@example.org
|
|
|
14
|
+os::cmd::expect_success 'oc secrets new-dockercfg dockercfg --docker-username=sample-user --docker-password=sample-password --docker-email=fake@example.org'
|
|
14
|
15
|
# can't use a go template here because the output needs to be base64 decoded. base64 isn't installed by default in all distros
|
|
15
|
|
-oc describe secrets/dockercfg | grep "dockercfg:" | awk '{print $2}' > ${HOME}/dockerconfig
|
|
16
|
|
-oc secrets new from-file .dockercfg=${HOME}/dockerconfig
|
|
|
16
|
+os::cmd::expect_success "oc describe secrets/dockercfg | grep 'dockercfg:' | awk '{print \$2}' > ${HOME}/dockerconfig"
|
|
|
17
|
+os::cmd::expect_success 'oc secrets new from-file .dockercfg=${HOME}/dockerconfig'
|
|
17
|
18
|
# check to make sure the type was correctly auto-detected
|
|
18
|
|
-[ "$(oc get secret/from-file --template="{{ .type }}" | grep 'kubernetes.io/dockercfg')" ]
|
|
|
19
|
+os::cmd::expect_success_and_text 'oc get secret/from-file --template="{{ .type }}"' 'kubernetes.io/dockercfg'
|
|
19
|
20
|
# make sure the -o works correctly
|
|
20
|
|
-[ "$(oc secrets new-dockercfg dockercfg --docker-username=sample-user --docker-password=sample-password --docker-email=fake@example.org -o yaml | grep "kubernetes.io/dockercfg")" ]
|
|
21
|
|
-[ "$(oc secrets new from-file .dockercfg=${HOME}/dockerconfig -o yaml | grep "kubernetes.io/dockercfg")" ]
|
|
|
21
|
+os::cmd::expect_success_and_text 'oc secrets new-dockercfg dockercfg --docker-username=sample-user --docker-password=sample-password --docker-email=fake@example.org -o yaml' 'kubernetes.io/dockercfg'
|
|
|
22
|
+os::cmd::expect_success_and_text 'oc secrets new from-file .dockercfg=${HOME}/dockerconfig -o yaml' 'kubernetes.io/dockercfg'
|
|
22
|
23
|
# check to make sure malformed names fail as expected
|
|
23
|
|
-[ "$(oc secrets new bad-name .docker=cfg=${HOME}/dockerconfig 2>&1 | grep "error: Key names or file paths cannot contain '='.")" ]
|
|
|
24
|
+os::cmd::expect_failure_and_text 'oc secrets new bad-name .docker=cfg=${HOME}/dockerconfig' "error: Key names or file paths cannot contain '='."
|
|
24
|
25
|
|
|
25
|
26
|
# attach secrets to service account
|
|
26
|
27
|
# single secret with prefix
|
|
27
|
|
-oc secrets add deployer dockercfg
|
|
|
28
|
+os::cmd::expect_success 'oc secrets add deployer dockercfg'
|
|
28
|
29
|
# don't add the same secret twice
|
|
29
|
|
-oc secrets add serviceaccounts/deployer dockercfg secrets/from-file
|
|
|
30
|
+os::cmd::expect_success 'oc secrets add serviceaccounts/deployer dockercfg secrets/from-file'
|
|
30
|
31
|
# make sure we can add as as pull secret
|
|
31
|
|
-oc secrets add deployer dockercfg from-file --for=pull
|
|
|
32
|
+os::cmd::expect_success 'oc secrets add deployer dockercfg from-file --for=pull'
|
|
32
|
33
|
# make sure we can add as as pull secret and mount secret at once
|
|
33
|
|
-oc secrets add serviceaccounts/deployer secrets/dockercfg secrets/from-file --for=pull,mount
|
|
|
34
|
+os::cmd::expect_success 'oc secrets add serviceaccounts/deployer secrets/dockercfg secrets/from-file --for=pull,mount'
|
|
34
|
35
|
|
|
35
|
36
|
GIT_CONFIG_PATH=$(create_gitconfig)
|
|
36
|
37
|
CA_CERT_PATH=$(create_valid_file ca.pem)
|
|
37
|
38
|
PRIVATE_KEY_PATH=$(create_valid_file id_rsa)
|
|
38
|
39
|
|
|
39
|
|
-oc secrets new-basicauth basicauth --username=sample-user --password=sample-password --gitconfig=$GIT_CONFIG_PATH --ca-cert=$PRIVATE_KEY_PATH
|
|
|
40
|
+os::cmd::expect_success 'oc secrets new-basicauth basicauth --username=sample-user --password=sample-password --gitconfig=$GIT_CONFIG_PATH --ca-cert=$PRIVATE_KEY_PATH'
|
|
40
|
41
|
# check to make sure two mutual exclusive flags return error as expected
|
|
41
|
|
-[ "$(oc secrets new-basicauth bad-file --password=sample-password --prompt 2>&1 | grep "error: must provide either --prompt or --password flag")" ]
|
|
|
42
|
+os::cmd::expect_failure_and_text 'oc secrets new-basicauth bad-file --password=sample-password --prompt' 'error: must provide either --prompt or --password flag'
|
|
42
|
43
|
# check to make sure incorrect .gitconfig path fail as expected
|
|
43
|
|
-[ "$(oc secrets new-basicauth bad-file --username=user --gitconfig=/bad/path 2>&1 | grep "error: open /bad/path: no such file or directory")" ]
|
|
|
44
|
+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'
|
|
44
|
45
|
|
|
45
|
|
-oc secrets new-sshauth sshauth --ssh-privatekey=$PRIVATE_KEY_PATH --ca-cert=$PRIVATE_KEY_PATH
|
|
|
46
|
+os::cmd::expect_success 'oc secrets new-sshauth sshauth --ssh-privatekey=$PRIVATE_KEY_PATH --ca-cert=$PRIVATE_KEY_PATH'
|
|
46
|
47
|
# check to make sure incorrect SSH private-key path fail as expected
|
|
47
|
|
-[ "$(oc secrets new-sshauth bad-file --ssh-privatekey=/bad/path 2>&1 | grep "error: open /bad/path: no such file or directory")" ]
|
|
|
48
|
+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'
|
|
48
|
49
|
|
|
49
|
50
|
# attach secrets to service account
|
|
50
|
51
|
# single secret with prefix
|
|
51
|
|
-oc secrets add serviceaccounts/deployer secrets/basicauth
|
|
|
52
|
+os::cmd::expect_success 'oc secrets add serviceaccounts/deployer secrets/basicauth'
|
|
52
|
53
|
# don't add the same secret twice
|
|
53
|
|
-oc secrets add serviceaccounts/deployer secrets/basicauth secrets/sshauth
|
|
|
54
|
+os::cmd::expect_success 'oc secrets add serviceaccounts/deployer secrets/basicauth secrets/sshauth'
|
|
54
|
55
|
# make sure we can add as as pull secret
|
|
55
|
|
-oc secrets add serviceaccounts/deployer secrets/basicauth secrets/sshauth --for=pull
|
|
|
56
|
+os::cmd::expect_success 'oc secrets add serviceaccounts/deployer secrets/basicauth secrets/sshauth --for=pull'
|
|
56
|
57
|
# make sure we can add as as pull secret and mount secret at once
|
|
57
|
|
-oc secrets add serviceaccounts/deployer secrets/basicauth secrets/sshauth --for=pull,mount
|
|
|
58
|
+os::cmd::expect_success 'oc secrets add serviceaccounts/deployer secrets/basicauth secrets/sshauth --for=pull,mount'
|
|
58
|
59
|
|
|
59
|
60
|
echo "secrets: ok"
|