|
50 | 50 | } |
51 | 51 | } |
52 | 52 |
|
| 53 | +@test "OIDC binding query fails when kubectl cannot list the bindings" { |
| 54 | + # Piped straight into sort, the query took its status from sort, and a |
| 55 | + # failed kubectl read as an empty binding list. The status has to hold |
| 56 | + # without errexit too, because callers capture it in a substitution. |
| 57 | + . hack/e2e-chainsaw/_lib/run-kubernetes.sh |
| 58 | + kubectl() { echo "the server is currently unable to handle the request" >&2; return 1; } |
| 59 | + |
| 60 | + if cozy_oidc_bindings demo >/dev/null 2>&1; then |
| 61 | + echo "a failed binding query was reported as success" >&2 |
| 62 | + return 1 |
| 63 | + fi |
| 64 | +} |
| 65 | + |
53 | 66 | @test "System OIDC assertion proves rendered objects bootstrap kubeconfig and tenant RBAC" { |
54 | 67 | . hack/e2e-chainsaw/_lib/run-kubernetes.sh |
55 | 68 | kubectl() { |
56 | 69 | case "$*" in |
57 | 70 | *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
58 | 71 | *" get kamajicontrolplane kubernetes-demo "*) |
59 | | - printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 72 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml --requestheader-uid-headers=X-Remote-Uid]' |
60 | 73 | ;; |
61 | 74 | *" get secret kubernetes-demo-oidc-authn-config "*) |
62 | 75 | printf 'url: https://keycloak.example.test/realms/cozy\naudiences:\n- tenant-test-kubernetes-demo\n' | base64 | tr -d '\n' |
|
76 | 89 | cozy_assert_oidc_system demo |
77 | 90 | } |
78 | 91 |
|
| 92 | +@test "System OIDC assertion fails when the aggregation-layer UID header is missing" { |
| 93 | + # Same mock as the passing case, minus --requestheader-uid-headers, so that |
| 94 | + # flag is the only thing left to fail on. Drop the grep for it from the helper |
| 95 | + # and this case goes red, which is what stops it passing for the wrong reason. |
| 96 | + . hack/e2e-chainsaw/_lib/run-kubernetes.sh |
| 97 | + kubectl() { |
| 98 | + case "$*" in |
| 99 | + *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
| 100 | + *" get kamajicontrolplane kubernetes-demo "*) |
| 101 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 102 | + ;; |
| 103 | + *" get secret kubernetes-demo-oidc-authn-config "*) |
| 104 | + printf 'url: https://keycloak.example.test/realms/cozy\naudiences:\n- tenant-test-kubernetes-demo\n' | base64 | tr -d '\n' |
| 105 | + ;; |
| 106 | + *" get keycloakclient.v1.edp.epam.com tenant-test-kubernetes-demo "*) printf 'true' ;; |
| 107 | + *" get keycloakclientscope.v1.edp.epam.com tenant-test-kubernetes-demo-audience "*) printf 'oidc-audience-mapper' ;; |
| 108 | + *" get secret kubernetes-demo-oidc-kubeconfig "*) |
| 109 | + printf 'args:\n- oidc-login\n- --oidc-client-id=tenant-test-kubernetes-demo\n' | base64 | tr -d '\n' |
| 110 | + ;; |
| 111 | + *) echo "unexpected kubectl call: $*" >&2; return 1 ;; |
| 112 | + esac |
| 113 | + } |
| 114 | + cozy_oidc_bindings() { |
| 115 | + |
| 116 | + } |
| 117 | + |
| 118 | + # The subshell restores `set -e`, which the chainsaw step runs the helper |
| 119 | + # under: without it a failing `grep -q` mid-function does not end the |
| 120 | + # function, and the exit status comes from the last assertion instead. |
| 121 | + # |
| 122 | + # It has to stand as its own command, not as an `if` condition. Shells |
| 123 | + # suppress errexit for a command whose status is being tested, and that |
| 124 | + # suppression reaches inside the subshell too, which is why the plain |
| 125 | + # `if ( set -e; ... )` spelling reports success here. |
| 126 | + local rc=0 |
| 127 | + set +e |
| 128 | + ( set -e; cozy_assert_oidc_system demo ) |
| 129 | + rc=$? |
| 130 | + set -e |
| 131 | + if [ "${rc}" -eq 0 ]; then |
| 132 | + echo "the System assertion passed without --requestheader-uid-headers" >&2 |
| 133 | + return 1 |
| 134 | + fi |
| 135 | +} |
| 136 | + |
79 | 137 | @test "CustomConfig transition fails when it cannot ask whether System leftovers are gone" { |
80 | 138 | # The teardown probes used `if kubectl get ... >/dev/null 2>&1`, which reads |
81 | 139 | # every non-zero exit as "the object is gone" -- including an RBAC denial, a |
|
101 | 159 | *" patch kuberneteses.apps.cozystack.io demo "*) : ;; |
102 | 160 | *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
103 | 161 | *" get kamajicontrolplane kubernetes-demo "*) |
104 | | - printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 162 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml --requestheader-uid-headers=X-Remote-Uid]' |
105 | 163 | ;; |
106 | 164 | *" get secret kubernetes-demo-oidc-authn-config "*) |
107 | 165 | printf 'url: https://idp.byo.example.test\naudiences:\n- cozystack-byo-demo\n' | base64 | tr -d '\n' |
|
123 | 181 | done |
124 | 182 | } |
125 | 183 |
|
| 184 | +@test "CustomConfig transition fails when the aggregation-layer UID header is missing" { |
| 185 | + # The System helper's twin. Same mock as the passing transition below, minus |
| 186 | + # --requestheader-uid-headers, so that flag is the only thing left to fail on. |
| 187 | + . hack/e2e-chainsaw/_lib/run-kubernetes.sh |
| 188 | + kubectl() { |
| 189 | + case "$*" in |
| 190 | + *" get helmrelease kubernetes-demo "*) printf '7' ;; |
| 191 | + *" patch kuberneteses.apps.cozystack.io demo "*) : ;; |
| 192 | + *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
| 193 | + *" get kamajicontrolplane kubernetes-demo "*) |
| 194 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 195 | + ;; |
| 196 | + *" get secret kubernetes-demo-oidc-authn-config "*) |
| 197 | + printf 'url: https://idp.byo.example.test\naudiences:\n- cozystack-byo-demo\n' | base64 | tr -d '\n' |
| 198 | + ;; |
| 199 | + *--ignore-not-found*) : ;; |
| 200 | + *) echo "unexpected kubectl call: $*" >&2; return 1 ;; |
| 201 | + esac |
| 202 | + } |
| 203 | + cozy_wait_helmrelease_upgrade() { :; } |
| 204 | + cozy_oidc_bindings() { printf '[email protected]\tcluster-admin\n'; } |
| 205 | + |
| 206 | + # Standalone subshell, not an `if` condition: errexit is suppressed for a |
| 207 | + # command whose status is tested, and that reaches inside the subshell. |
| 208 | + local rc=0 |
| 209 | + set +e |
| 210 | + ( set -e; cozy_switch_and_assert_oidc_custom_config demo ) |
| 211 | + rc=$? |
| 212 | + set -e |
| 213 | + if [ "${rc}" -eq 0 ]; then |
| 214 | + echo "the transition passed without --requestheader-uid-headers" >&2 |
| 215 | + return 1 |
| 216 | + fi |
| 217 | +} |
| 218 | + |
126 | 219 | @test "CustomConfig transition patches the live cluster waits for the new generation and rejects System leftovers" { |
127 | 220 | . hack/e2e-chainsaw/_lib/run-kubernetes.sh |
128 | 221 | calls=$(mktemp) |
|
144 | 237 | ;; |
145 | 238 | *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
146 | 239 | *" get kamajicontrolplane kubernetes-demo "*) |
147 | | - printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 240 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml --requestheader-uid-headers=X-Remote-Uid]' |
148 | 241 | ;; |
149 | 242 | *" get secret kubernetes-demo-oidc-authn-config "*) |
150 | 243 | printf 'url: https://idp.byo.example.test\naudiences:\n- cozystack-byo-demo\n' | base64 | tr -d '\n' |
|
0 commit comments