From b44a4b4e40401d730bfc35c979ae12b22556ba28 Mon Sep 17 00:00:00 2001 From: Syed Nihal Date: Wed, 28 Feb 2024 18:57:12 +0530 Subject: [PATCH] added tests for the change https://github.com/kiwigrid/k8s-sidecar/issues/318 Signed-off-by: Syed Nihal --- .github/workflows/build_and_test.yaml | 12 +++++- test/resources/sidecar.yaml | 54 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index d37a175c..8ba54912 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -90,6 +90,7 @@ jobs: kubectl get pods wait_for_pod_ready "sidecar" + wait_for_pod_ready "sidecar-basicauth-args" wait_for_pod_ready "sidecar-5xx" wait_for_pod_ready "sidecar-pythonscript" wait_for_pod_ready "sidecar-pythonscript-logfile" @@ -106,7 +107,7 @@ jobs: sleep 20 echo "Installing resources..." kubectl apply -f "test/resources/resources.yaml" - pods=("sidecar" "sidecar-5xx" "sidecar-pythonscript" "sidecar-pythonscript-logfile") + pods=("sidecar" "sidecar-basicauth-args" "sidecar-5xx" "sidecar-pythonscript" "sidecar-pythonscript-logfile") resources=("sample-configmap" "sample-secret-binary" "absolute-configmap" "relative-configmap" "change-dir-configmap" "similar-configmap-secret" "url-configmap-500" "url-configmap-basic-auth" "sample-configmap") for p in ${pods[*]}; do for r in ${resources[*]}; do @@ -119,6 +120,7 @@ jobs: run: | mkdir /tmp/logs kubectl logs sidecar > /tmp/logs/sidecar.log + kubectl logs sidecar-basicauth-args > /tmp/logs/sidecar-basicauth-args.log kubectl logs sidecar-5xx > /tmp/logs/sidecar-5xx.log kubectl logs sidecar-pythonscript > /tmp/logs/sidecar-pythonscript.log kubectl logs sidecar-pythonscript-logfile > /tmp/logs/sidecar-pythonscript-logfile.log @@ -147,7 +149,10 @@ jobs: kubectl cp sidecar:/tmp/secured.txt /tmp/sidecar/secured.txt kubectl cp sidecar:/tmp/similar-configmap.txt /tmp/sidecar/similar-configmap.txt kubectl cp sidecar:/tmp/similar-secret.txt /tmp/sidecar/similar-secret.txt - + + echo "Downloading resource files from sidecar-basicauth-args pod" + kubectl cp sidecar-basicauth-args:/tmp/secured.txt /tmp/sidecar-basicauth-args/secured.txt + echo "Downloading resource files from sidecar-5xx..." kubectl cp sidecar-5xx:/tmp-5xx/hello.world /tmp/sidecar-5xx/hello.world kubectl cp sidecar-5xx:/tmp-5xx/cm-kubelogo.png /tmp/sidecar-5xx/cm-kubelogo.png @@ -203,6 +208,9 @@ jobs: echo -n "allowed" | diff - /tmp/sidecar/secured.txt && [ ! -f /tmp/sidecar/500.txt ] && echo "No 5xx file created" && ls /tmp/sidecar/script_result + - name: Verify sidecar-basicauth-args pod file after initial sync + run: | + echo -n "allowed" | diff - /tmp/sidecar-basicauth-args/secured.txt - name: Verify sidecar-5xx files after initial sync run: | echo -n '{"detail":"Not authenticated"}' | diff - /tmp/sidecar-5xx/secured.txt && diff --git a/test/resources/sidecar.yaml b/test/resources/sidecar.yaml index 0d76c161..d1f68e0f 100644 --- a/test/resources/sidecar.yaml +++ b/test/resources/sidecar.yaml @@ -335,3 +335,57 @@ spec: - port: 80 targetPort: 80 name: http +--- +apiVersion: v1 +kind: Pod +metadata: + name: sidecar-basicauth-args + namespace: default +spec: + serviceAccountName: sample-acc + containers: + - name: sidecar + image: k8s-sidecar:testing + command: [ "python" , "-u" , "sidecar.py" , "--req-username-file=/opt/creds/username" , "--req-password-file=/opt/creds/password"] + imagePullPolicy: IfNotPresent + volumeMounts: + - name: auth-creds + mountPath: /opt/creds/ + - name: shared-volume + mountPath: /tmp/ + - name: script-volume + mountPath: /opt/script.sh + subPath: script.sh + env: + - name: LABEL + value: "findme" + - name: FOLDER + value: /tmp/ + - name: RESOURCE + value: both + - name: SCRIPT + value: "/opt/script.sh" + - name: REQ_BASIC_AUTH_ENCODING + # the python server we're using for the tests expects ascii encoding of basic auth credentials, hence we can't use non-ascii characters in the password or username + value: "ascii" + - name: LOG_LEVEL + value: "DEBUG" + volumes: + - name: auth-creds + secret: + secretName: dummyyserver-credentials + - name: shared-volume + emptyDir: {} + - name: script-volume + configMap: + name: script-configmap + defaultMode: 0777 +--- +apiVersion: v1 +kind: Secret +metadata: + name: dummyyserver-credentials +type: Opaque +stringData: + username: "user1" + password: "abcdefghijklmnopqrstuvwxyz" \ No newline at end of file