From 6262f5f150877f5f43ed544819de3758015cf6b7 Mon Sep 17 00:00:00 2001 From: Sarath Chandra Oruganti <39090092+SarathChandra24@users.noreply.github.com> Date: Mon, 19 Feb 2024 13:49:19 -0500 Subject: [PATCH 1/3] chart: incrementals-publisher unit tests for secrets --- charts/incrementals-publisher/Chart.yaml | 2 +- .../tests/custom_values_test.yaml | 46 ++++++++++++- .../tests/defaults_test.yaml | 68 +++++++++++++++++++ charts/incrementals-publisher/values.yaml | 10 +-- 4 files changed, 118 insertions(+), 8 deletions(-) diff --git a/charts/incrementals-publisher/Chart.yaml b/charts/incrementals-publisher/Chart.yaml index c5dfd34ef..c1b3201cf 100644 --- a/charts/incrementals-publisher/Chart.yaml +++ b/charts/incrementals-publisher/Chart.yaml @@ -1,4 +1,4 @@ apiVersion: v1 description: incrementals-publisher name: incrementals-publisher -version: 0.7.0 +version: 0.8.0 diff --git a/charts/incrementals-publisher/tests/custom_values_test.yaml b/charts/incrementals-publisher/tests/custom_values_test.yaml index 689993132..d7579725e 100644 --- a/charts/incrementals-publisher/tests/custom_values_test.yaml +++ b/charts/incrementals-publisher/tests/custom_values_test.yaml @@ -2,11 +2,17 @@ suite: Custom values templates: - deployment.yaml - secret.yaml # dependency of deployment.yaml -values: - # These values are required by the template "secret.yaml" - - secret-values.yaml set: permissions_url: https://somewhere.jenkins.io/github.json + artifactory: + key: testingArtifactoryKey + github: + token: customSuperSecretToken + appId: customSuperSecretAppId + privateKey: customSuperSecretPrivateKey + jenkins: + auth: customSecretJenkinsUser:customSecretJenkinsPassword + preshared_key: customSuperSecretPreSharedKey tests: - it: should define a deployment with the provided custom settings template: deployment.yaml @@ -33,3 +39,37 @@ tests: name: PERMISSIONS_URL value: https://somewhere.jenkins.io/github.json any: true + - contains: + path: spec.template.spec.containers[0].env + content: + name: JENKINS_AUTH + valueFrom: + secretKeyRef: + key: jenkins_auth + name: RELEASE-NAME-incrementals-publisher + + - it: should define a secret with the provided custom settings + template: secret.yaml + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Secret + - equal: + path: data.artifactory_key + value: dGVzdGluZ0FydGlmYWN0b3J5S2V5 + - equal: + path: data.github_token + value: Y3VzdG9tU3VwZXJTZWNyZXRUb2tlbg== + - equal: + path: data.github_app_id + value: Y3VzdG9tU3VwZXJTZWNyZXRBcHBJZA== + - equal: + path: data.github_app_private_key + value: Y3VzdG9tU3VwZXJTZWNyZXRQcml2YXRlS2V5 + - equal: + path: data.jenkins_auth + value: Y3VzdG9tU2VjcmV0SmVua2luc1VzZXI6Y3VzdG9tU2VjcmV0SmVua2luc1Bhc3N3b3Jk + - equal: + path: data.preshared_key + value: Y3VzdG9tU3VwZXJTZWNyZXRQcmVTaGFyZWRLZXk= \ No newline at end of file diff --git a/charts/incrementals-publisher/tests/defaults_test.yaml b/charts/incrementals-publisher/tests/defaults_test.yaml index 4c94e875f..e73cb8f7c 100644 --- a/charts/incrementals-publisher/tests/defaults_test.yaml +++ b/charts/incrementals-publisher/tests/defaults_test.yaml @@ -30,3 +30,71 @@ tests: content: name: PERMISSIONS_URL any: true + - contains: + path: spec.template.spec.containers[0].env + content: + name: JENKINS_AUTH + valueFrom: + secretKeyRef: + key: jenkins_auth + name: RELEASE-NAME-incrementals-publisher + - contains: + path: spec.template.spec.containers[0].env + content: + name: GITHUB_TOKEN + valueFrom: + secretKeyRef: + key: github_token + name: RELEASE-NAME-incrementals-publisher + - contains: + path: spec.template.spec.containers[0].env + content: + name: GITHUB_APP_ID + valueFrom: + secretKeyRef: + key: github_app_id + name: RELEASE-NAME-incrementals-publisher + any: true + - contains: + path: spec.template.spec.containers[0].env + content: + name: GITHUB_APP_PRIVATE_KEY + valueFrom: + secretKeyRef: + key: github_app_private_key + name: RELEASE-NAME-incrementals-publisher + any: true + - contains: + path: spec.template.spec.containers[0].env + content: + name: ARTIFACTORY_KEY + valueFrom: + secretKeyRef: + key: artifactory_key + name: RELEASE-NAME-incrementals-publisher + any: true + - it: should define a secret with the provided custom settings + template: secret.yaml + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Secret + - equal: + path: data.artifactory_key + value: c3VwZXJTZWNyZXRLZXk= + - equal: + path: data.github_token + value: c3VwZXJTZWNyZXRUb2tlbg== + - equal: + path: data.github_app_id + value: c3VwZXJTZWNyZXRJRA== + - equal: + path: data.github_app_private_key + value: c3VwZXJTZWNyZXRLZXk= + - equal: + path: data.jenkins_auth + value: c2VjcmV0SmVua2luc1VzZXI6c3VwZXJTZWNyZXRKZW5raW5zVXNlclBhc3M= + - equal: + path: data.preshared_key + value: c3VwZXJTZWNyZXRQcmVTaGFyZWRLZXk= diff --git a/charts/incrementals-publisher/values.yaml b/charts/incrementals-publisher/values.yaml index 82aa6d248..81877a16a 100644 --- a/charts/incrementals-publisher/values.yaml +++ b/charts/incrementals-publisher/values.yaml @@ -50,12 +50,14 @@ affinity: {} permissions_url: '' artifactory: # artifactory.key -- key to upload to artifactory - key: '' + key: 'testingArtifactoryKey' github: # github.token -- token to update github checks and look up commits - token: '' + token: 'customSuperSecretToken' + appId: 'customSuperSecretAppId' + privateKey: 'customSuperSecretPrivateKey' jenkins: # jenkins.auth -- username:accesskey to talk to jenkins apis to pull build metadata - auth: '' + auth: 'customSecretJenkinsUser:customSecretJenkinsPassword' # preshared_key -- The token needed to be provided for autherization -preshared_key: '' +preshared_key: 'customSuperSecretPreSharedKey' \ No newline at end of file From f520fd74daf591c3aca0d1b3c3137186e2a09de9 Mon Sep 17 00:00:00 2001 From: Sarath Chandra Oruganti <39090092+SarathChandra24@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:21:11 -0500 Subject: [PATCH 2/3] refactor unit tests --- .../templates/secret.yaml | 12 +-- .../tests/custom_values_test.yaml | 4 +- .../tests/defaults_test.yaml | 79 ++----------------- .../tests/secret-values.yaml | 11 --- charts/incrementals-publisher/values.yaml | 10 +-- 5 files changed, 20 insertions(+), 96 deletions(-) delete mode 100644 charts/incrementals-publisher/tests/secret-values.yaml diff --git a/charts/incrementals-publisher/templates/secret.yaml b/charts/incrementals-publisher/templates/secret.yaml index e323bfb89..cfeb7bd83 100644 --- a/charts/incrementals-publisher/templates/secret.yaml +++ b/charts/incrementals-publisher/templates/secret.yaml @@ -7,9 +7,9 @@ metadata: {{ include "incrementals-publisher.labels" . | indent 4 }} type: Opaque data: - artifactory_key: {{ required "artifactory.key is required" .Values.artifactory.key | toString | b64enc }} - github_token: {{ required "github.token is required" .Values.github.token | toString | b64enc }} - github_app_id: {{ required "github.appId is required" .Values.github.appId | toString | b64enc }} - github_app_private_key: {{ required "github.privateKey is required" .Values.github.privateKey | toString | b64enc }} - jenkins_auth: {{ required "jenkins.auth is required" .Values.jenkins.auth | toString | b64enc }} - preshared_key: {{ required "preshared_key is required" .Values.preshared_key | toString | b64enc }} + artifactory_key: {{ .Values.artifactory.key | toString | b64enc }} + github_token: {{ .Values.github.token | toString | b64enc }} + github_app_id: {{ .Values.github.appId | toString | b64enc }} + github_app_private_key: {{ .Values.github.privateKey | toString | b64enc }} + jenkins_auth: {{ .Values.jenkins.auth | toString | b64enc }} + preshared_key: {{ .Values.preshared_key | toString | b64enc }} diff --git a/charts/incrementals-publisher/tests/custom_values_test.yaml b/charts/incrementals-publisher/tests/custom_values_test.yaml index d7579725e..8c673d68a 100644 --- a/charts/incrementals-publisher/tests/custom_values_test.yaml +++ b/charts/incrementals-publisher/tests/custom_values_test.yaml @@ -48,7 +48,7 @@ tests: key: jenkins_auth name: RELEASE-NAME-incrementals-publisher - - it: should define a secret with the provided custom settings + - it: should create a Secret with the correct value template: secret.yaml asserts: - hasDocuments: @@ -72,4 +72,4 @@ tests: value: Y3VzdG9tU2VjcmV0SmVua2luc1VzZXI6Y3VzdG9tU2VjcmV0SmVua2luc1Bhc3N3b3Jk - equal: path: data.preshared_key - value: Y3VzdG9tU3VwZXJTZWNyZXRQcmVTaGFyZWRLZXk= \ No newline at end of file + value: Y3VzdG9tU3VwZXJTZWNyZXRQcmVTaGFyZWRLZXk= diff --git a/charts/incrementals-publisher/tests/defaults_test.yaml b/charts/incrementals-publisher/tests/defaults_test.yaml index e73cb8f7c..d6896af15 100644 --- a/charts/incrementals-publisher/tests/defaults_test.yaml +++ b/charts/incrementals-publisher/tests/defaults_test.yaml @@ -2,10 +2,15 @@ suite: Default values templates: - deployment.yaml - secret.yaml # dependency of deployment.yaml -values: - # These values are required by the template "secret.yaml" - - secret-values.yaml +# values: +# # These values are required by the template "secret.yaml" +# - secret-values.yaml tests: + - it: should create an secret with default values + template: secret.yaml + asserts: + - hasDocuments: + count: 1 - it: should define a deployment with the default settings template: deployment.yaml asserts: @@ -30,71 +35,3 @@ tests: content: name: PERMISSIONS_URL any: true - - contains: - path: spec.template.spec.containers[0].env - content: - name: JENKINS_AUTH - valueFrom: - secretKeyRef: - key: jenkins_auth - name: RELEASE-NAME-incrementals-publisher - - contains: - path: spec.template.spec.containers[0].env - content: - name: GITHUB_TOKEN - valueFrom: - secretKeyRef: - key: github_token - name: RELEASE-NAME-incrementals-publisher - - contains: - path: spec.template.spec.containers[0].env - content: - name: GITHUB_APP_ID - valueFrom: - secretKeyRef: - key: github_app_id - name: RELEASE-NAME-incrementals-publisher - any: true - - contains: - path: spec.template.spec.containers[0].env - content: - name: GITHUB_APP_PRIVATE_KEY - valueFrom: - secretKeyRef: - key: github_app_private_key - name: RELEASE-NAME-incrementals-publisher - any: true - - contains: - path: spec.template.spec.containers[0].env - content: - name: ARTIFACTORY_KEY - valueFrom: - secretKeyRef: - key: artifactory_key - name: RELEASE-NAME-incrementals-publisher - any: true - - it: should define a secret with the provided custom settings - template: secret.yaml - asserts: - - hasDocuments: - count: 1 - - isKind: - of: Secret - - equal: - path: data.artifactory_key - value: c3VwZXJTZWNyZXRLZXk= - - equal: - path: data.github_token - value: c3VwZXJTZWNyZXRUb2tlbg== - - equal: - path: data.github_app_id - value: c3VwZXJTZWNyZXRJRA== - - equal: - path: data.github_app_private_key - value: c3VwZXJTZWNyZXRLZXk= - - equal: - path: data.jenkins_auth - value: c2VjcmV0SmVua2luc1VzZXI6c3VwZXJTZWNyZXRKZW5raW5zVXNlclBhc3M= - - equal: - path: data.preshared_key - value: c3VwZXJTZWNyZXRQcmVTaGFyZWRLZXk= diff --git a/charts/incrementals-publisher/tests/secret-values.yaml b/charts/incrementals-publisher/tests/secret-values.yaml deleted file mode 100644 index f4f9dc228..000000000 --- a/charts/incrementals-publisher/tests/secret-values.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# These values are required by the template "secret.yaml" -# (their default value is "empty" which fails the chart) -artifactory: - key: superSecretKey -github: - token: superSecretToken - appId: superSecretID - privateKey: superSecretKey -jenkins: - auth: secretJenkinsUser:superSecretJenkinsUserPass -preshared_key: superSecretPreSharedKey diff --git a/charts/incrementals-publisher/values.yaml b/charts/incrementals-publisher/values.yaml index 81877a16a..f3ee46c90 100644 --- a/charts/incrementals-publisher/values.yaml +++ b/charts/incrementals-publisher/values.yaml @@ -50,14 +50,12 @@ affinity: {} permissions_url: '' artifactory: # artifactory.key -- key to upload to artifactory - key: 'testingArtifactoryKey' + key: "" github: # github.token -- token to update github checks and look up commits - token: 'customSuperSecretToken' - appId: 'customSuperSecretAppId' - privateKey: 'customSuperSecretPrivateKey' + token: "" jenkins: # jenkins.auth -- username:accesskey to talk to jenkins apis to pull build metadata - auth: 'customSecretJenkinsUser:customSecretJenkinsPassword' + auth: "" # preshared_key -- The token needed to be provided for autherization -preshared_key: 'customSuperSecretPreSharedKey' \ No newline at end of file +preshared_key: "" From 6fd4437bdf7d03431e867576e68af777c88d925c Mon Sep 17 00:00:00 2001 From: Sarath Chandra Oruganti <39090092+SarathChandra24@users.noreply.github.com> Date: Thu, 22 Feb 2024 12:34:58 -0500 Subject: [PATCH 3/3] chart: incrementals-publisher fix unit test changes --- charts/incrementals-publisher/Chart.yaml | 2 +- charts/incrementals-publisher/tests/defaults_test.yaml | 5 +---- charts/incrementals-publisher/values.yaml | 8 ++++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/charts/incrementals-publisher/Chart.yaml b/charts/incrementals-publisher/Chart.yaml index c1b3201cf..60489ca3d 100644 --- a/charts/incrementals-publisher/Chart.yaml +++ b/charts/incrementals-publisher/Chart.yaml @@ -1,4 +1,4 @@ apiVersion: v1 description: incrementals-publisher name: incrementals-publisher -version: 0.8.0 +version: 0.7.1 diff --git a/charts/incrementals-publisher/tests/defaults_test.yaml b/charts/incrementals-publisher/tests/defaults_test.yaml index d6896af15..bf1b49698 100644 --- a/charts/incrementals-publisher/tests/defaults_test.yaml +++ b/charts/incrementals-publisher/tests/defaults_test.yaml @@ -2,11 +2,8 @@ suite: Default values templates: - deployment.yaml - secret.yaml # dependency of deployment.yaml -# values: -# # These values are required by the template "secret.yaml" -# - secret-values.yaml tests: - - it: should create an secret with default values + - it: should create a secret with default values template: secret.yaml asserts: - hasDocuments: diff --git a/charts/incrementals-publisher/values.yaml b/charts/incrementals-publisher/values.yaml index f3ee46c90..82aa6d248 100644 --- a/charts/incrementals-publisher/values.yaml +++ b/charts/incrementals-publisher/values.yaml @@ -50,12 +50,12 @@ affinity: {} permissions_url: '' artifactory: # artifactory.key -- key to upload to artifactory - key: "" + key: '' github: # github.token -- token to update github checks and look up commits - token: "" + token: '' jenkins: # jenkins.auth -- username:accesskey to talk to jenkins apis to pull build metadata - auth: "" + auth: '' # preshared_key -- The token needed to be provided for autherization -preshared_key: "" +preshared_key: ''