|
56 | 56 | case "$*" in |
57 | 57 | *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
58 | 58 | *" get kamajicontrolplane kubernetes-demo "*) |
59 | | - printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 59 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml --requestheader-uid-headers=X-Remote-Uid]' |
60 | 60 | ;; |
61 | 61 | *" get secret kubernetes-demo-oidc-authn-config "*) |
62 | 62 | printf 'url: https://keycloak.example.test/realms/cozy\naudiences:\n- tenant-test-kubernetes-demo\n' | base64 | tr -d '\n' |
|
76 | 76 | cozy_assert_oidc_system demo |
77 | 77 | } |
78 | 78 |
|
| 79 | +@test "System OIDC assertion fails when the aggregation-layer UID header is missing" { |
| 80 | + # Same mock as the passing case, minus --requestheader-uid-headers, so that |
| 81 | + # flag is the only thing left to fail on. Drop the grep for it from the helper |
| 82 | + # and this case goes red, which is what stops it passing for the wrong reason. |
| 83 | + . hack/e2e-chainsaw/_lib/run-kubernetes.sh |
| 84 | + kubectl() { |
| 85 | + case "$*" in |
| 86 | + *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
| 87 | + *" get kamajicontrolplane kubernetes-demo "*) |
| 88 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 89 | + ;; |
| 90 | + *" get secret kubernetes-demo-oidc-authn-config "*) |
| 91 | + printf 'url: https://keycloak.example.test/realms/cozy\naudiences:\n- tenant-test-kubernetes-demo\n' | base64 | tr -d '\n' |
| 92 | + ;; |
| 93 | + *" get keycloakclient.v1.edp.epam.com tenant-test-kubernetes-demo "*) printf 'true' ;; |
| 94 | + *" get keycloakclientscope.v1.edp.epam.com tenant-test-kubernetes-demo-audience "*) printf 'oidc-audience-mapper' ;; |
| 95 | + *" get secret kubernetes-demo-oidc-kubeconfig "*) |
| 96 | + printf 'args:\n- oidc-login\n- --oidc-client-id=tenant-test-kubernetes-demo\n' | base64 | tr -d '\n' |
| 97 | + ;; |
| 98 | + *) echo "unexpected kubectl call: $*" >&2; return 1 ;; |
| 99 | + esac |
| 100 | + } |
| 101 | + cozy_oidc_bindings() { |
| 102 | + |
| 103 | + } |
| 104 | + |
| 105 | + # The subshell restores `set -e`, which the chainsaw step runs the helper |
| 106 | + # under: without it a failing `grep -q` mid-function does not end the |
| 107 | + # function, and the exit status comes from the last assertion instead. |
| 108 | + # |
| 109 | + # It has to stand as its own command, not as an `if` condition. Shells |
| 110 | + # suppress errexit for a command whose status is being tested, and that |
| 111 | + # suppression reaches inside the subshell too, which is why the plain |
| 112 | + # `if ( set -e; ... )` spelling reports success here. |
| 113 | + local rc=0 |
| 114 | + set +e |
| 115 | + ( set -e; cozy_assert_oidc_system demo ) |
| 116 | + rc=$? |
| 117 | + set -e |
| 118 | + if [ "${rc}" -eq 0 ]; then |
| 119 | + echo "the System assertion passed without --requestheader-uid-headers" >&2 |
| 120 | + return 1 |
| 121 | + fi |
| 122 | +} |
| 123 | + |
79 | 124 | @test "CustomConfig transition fails when it cannot ask whether System leftovers are gone" { |
80 | 125 | # The teardown probes used `if kubectl get ... >/dev/null 2>&1`, which reads |
81 | 126 | # every non-zero exit as "the object is gone" -- including an RBAC denial, a |
|
101 | 146 | *" patch kuberneteses.apps.cozystack.io demo "*) : ;; |
102 | 147 | *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
103 | 148 | *" get kamajicontrolplane kubernetes-demo "*) |
104 | | - printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 149 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml --requestheader-uid-headers=X-Remote-Uid]' |
105 | 150 | ;; |
106 | 151 | *" get secret kubernetes-demo-oidc-authn-config "*) |
107 | 152 | printf 'url: https://idp.byo.example.test\naudiences:\n- cozystack-byo-demo\n' | base64 | tr -d '\n' |
|
123 | 168 | done |
124 | 169 | } |
125 | 170 |
|
| 171 | +@test "CustomConfig transition fails when the aggregation-layer UID header is missing" { |
| 172 | + # The System helper's twin. Same mock as the passing transition below, minus |
| 173 | + # --requestheader-uid-headers, so that flag is the only thing left to fail on. |
| 174 | + . hack/e2e-chainsaw/_lib/run-kubernetes.sh |
| 175 | + kubectl() { |
| 176 | + case "$*" in |
| 177 | + *" get helmrelease kubernetes-demo "*) printf '7' ;; |
| 178 | + *" patch kuberneteses.apps.cozystack.io demo "*) : ;; |
| 179 | + *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
| 180 | + *" get kamajicontrolplane kubernetes-demo "*) |
| 181 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 182 | + ;; |
| 183 | + *" get secret kubernetes-demo-oidc-authn-config "*) |
| 184 | + printf 'url: https://idp.byo.example.test\naudiences:\n- cozystack-byo-demo\n' | base64 | tr -d '\n' |
| 185 | + ;; |
| 186 | + *--ignore-not-found*) : ;; |
| 187 | + *) echo "unexpected kubectl call: $*" >&2; return 1 ;; |
| 188 | + esac |
| 189 | + } |
| 190 | + cozy_wait_helmrelease_upgrade() { :; } |
| 191 | + cozy_oidc_bindings() { printf '[email protected]\tcluster-admin\n'; } |
| 192 | + |
| 193 | + # Standalone subshell, not an `if` condition: errexit is suppressed for a |
| 194 | + # command whose status is tested, and that reaches inside the subshell. |
| 195 | + local rc=0 |
| 196 | + set +e |
| 197 | + ( set -e; cozy_switch_and_assert_oidc_custom_config demo ) |
| 198 | + rc=$? |
| 199 | + set -e |
| 200 | + if [ "${rc}" -eq 0 ]; then |
| 201 | + echo "the transition passed without --requestheader-uid-headers" >&2 |
| 202 | + return 1 |
| 203 | + fi |
| 204 | +} |
| 205 | + |
126 | 206 | @test "CustomConfig transition patches the live cluster waits for the new generation and rejects System leftovers" { |
127 | 207 | . hack/e2e-chainsaw/_lib/run-kubernetes.sh |
128 | 208 | calls=$(mktemp) |
|
144 | 224 | ;; |
145 | 225 | *" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;; |
146 | 226 | *" get kamajicontrolplane kubernetes-demo "*) |
147 | | - printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]' |
| 227 | + printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml --requestheader-uid-headers=X-Remote-Uid]' |
148 | 228 | ;; |
149 | 229 | *" get secret kubernetes-demo-oidc-authn-config "*) |
150 | 230 | printf 'url: https://idp.byo.example.test\naudiences:\n- cozystack-byo-demo\n' | base64 | tr -d '\n' |
|
0 commit comments