-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(KFLUXBUGS-1581): force releaseNotes.type when cves defined
This commit modifies the create-advisory task to fail when releaseNotes.type is RHSA but there are no CVEs listed as fixed. Also, if there are CVEs fixed, the type is forced to be RHSA regardless of what type the user provides. Signed-off-by: Johnny Bieren <[email protected]>
- Loading branch information
1 parent
a3db06b
commit 30d70b4
Showing
4 changed files
with
304 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
tasks/create-advisory/tests/test-create-advisory-fail-rhsa-no-cve.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: Pipeline | ||
metadata: | ||
name: test-create-advisory-fail-rhsa-no-cve | ||
annotations: | ||
test/assert-task-failure: "run-task" | ||
spec: | ||
description: | | ||
Run the create-advisory task with releaseNotes.type set to RHSA but no CVEs in releaseNotes. | ||
The task should fail. | ||
workspaces: | ||
- name: tests-workspace | ||
tasks: | ||
- name: setup | ||
taskSpec: | ||
steps: | ||
- name: create-crs | ||
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f | ||
script: | | ||
#!/usr/bin/env bash | ||
set -eux | ||
mkdir "$(workspaces.data.path)"/results | ||
cat > "$(workspaces.data.path)"/test_release_plan_admission.json << EOF | ||
{ | ||
"apiVersion": "appstudio.redhat.com/v1alpha1", | ||
"kind": "ReleasePlanAdmission", | ||
"metadata": { | ||
"name": "test", | ||
"namespace": "default" | ||
}, | ||
"spec": { | ||
"applications": [ | ||
"app" | ||
], | ||
"policy": "policy", | ||
"pipeline": { | ||
"pipelineRef": { | ||
"resolver": "git", | ||
"params": [ | ||
{ | ||
"name": "url", | ||
"value": "github.com" | ||
}, | ||
{ | ||
"name": "revision", | ||
"value": "main" | ||
}, | ||
{ | ||
"name": "pathInRepo", | ||
"value": "pipeline.yaml" | ||
} | ||
] | ||
}, | ||
"serviceAccountName": "sa" | ||
}, | ||
"origin": "dev" | ||
} | ||
} | ||
EOF | ||
cat > "$(workspaces.data.path)"/test_snapshot_spec.json << EOF | ||
{ | ||
"application": "myapp", | ||
"components": [ | ||
{ | ||
"name": "comp", | ||
"repository": "quay.io/redhat-prod/repo" | ||
} | ||
] | ||
} | ||
EOF | ||
cat > "$(workspaces.data.path)"/data.json << EOF | ||
{ | ||
"releaseNotes": { | ||
"type": "RHSA" | ||
}, | ||
"sign": { | ||
"configMapName": "cm" | ||
} | ||
} | ||
EOF | ||
workspaces: | ||
- name: data | ||
workspace: tests-workspace | ||
- name: run-task | ||
taskRef: | ||
name: create-advisory | ||
params: | ||
- name: releasePlanAdmissionPath | ||
value: "test_release_plan_admission.json" | ||
- name: snapshotPath | ||
value: "test_snapshot_spec.json" | ||
- name: dataPath | ||
value: "data.json" | ||
- name: resultsDirPath | ||
value: "results" | ||
- name: synchronously | ||
value: "false" | ||
- name: pipelineRunUid | ||
value: $(context.pipelineRun.uid) | ||
runAfter: | ||
- setup | ||
workspaces: | ||
- name: data | ||
workspace: tests-workspace |
174 changes: 174 additions & 0 deletions
174
tasks/create-advisory/tests/test-create-advisory-overwrite-type.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: Pipeline | ||
metadata: | ||
name: test-create-advisory-overwrite-type | ||
spec: | ||
description: | | ||
Run the create-advisory task with a releaseNotes.type that is not RHSA, but CVEs present in releaseNotes. | ||
The type should be overwritten to RHSA. | ||
workspaces: | ||
- name: tests-workspace | ||
tasks: | ||
- name: setup | ||
taskSpec: | ||
steps: | ||
- name: create-crs | ||
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f | ||
script: | | ||
#!/usr/bin/env bash | ||
set -eux | ||
mkdir "$(workspaces.data.path)"/results | ||
cat > "$(workspaces.data.path)"/test_release_plan_admission.json << EOF | ||
{ | ||
"apiVersion": "appstudio.redhat.com/v1alpha1", | ||
"kind": "ReleasePlanAdmission", | ||
"metadata": { | ||
"name": "test", | ||
"namespace": "default" | ||
}, | ||
"spec": { | ||
"applications": [ | ||
"app" | ||
], | ||
"policy": "policy", | ||
"pipeline": { | ||
"pipelineRef": { | ||
"resolver": "git", | ||
"params": [ | ||
{ | ||
"name": "url", | ||
"value": "github.com" | ||
}, | ||
{ | ||
"name": "revision", | ||
"value": "main" | ||
}, | ||
{ | ||
"name": "pathInRepo", | ||
"value": "pipeline.yaml" | ||
} | ||
] | ||
}, | ||
"serviceAccountName": "sa" | ||
}, | ||
"origin": "dev" | ||
} | ||
} | ||
EOF | ||
cat > "$(workspaces.data.path)"/test_snapshot_spec.json << EOF | ||
{ | ||
"application": "myapp", | ||
"components": [ | ||
{ | ||
"name": "comp", | ||
"repository": "quay.io/redhat-prod/repo" | ||
} | ||
] | ||
} | ||
EOF | ||
cat > "$(workspaces.data.path)"/data.json << EOF | ||
{ | ||
"releaseNotes": { | ||
"type": "RHEA", | ||
"content": { | ||
"images": [ | ||
{ | ||
"containerImage": "foo", | ||
"cves": { | ||
"fixed": { | ||
"CVE-123": { | ||
"components": [ | ||
"pkg:rpm/foo" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"sign": { | ||
"configMapName": "cm" | ||
} | ||
} | ||
EOF | ||
workspaces: | ||
- name: data | ||
workspace: tests-workspace | ||
- name: run-task | ||
taskRef: | ||
name: create-advisory | ||
params: | ||
- name: releasePlanAdmissionPath | ||
value: "test_release_plan_admission.json" | ||
- name: snapshotPath | ||
value: "test_snapshot_spec.json" | ||
- name: dataPath | ||
value: "data.json" | ||
- name: resultsDirPath | ||
value: "results" | ||
- name: synchronously | ||
value: "false" | ||
- name: pipelineRunUid | ||
value: $(context.pipelineRun.uid) | ||
runAfter: | ||
- setup | ||
workspaces: | ||
- name: data | ||
workspace: tests-workspace | ||
- name: check-result | ||
workspaces: | ||
- name: data | ||
workspace: tests-workspace | ||
runAfter: | ||
- run-task | ||
taskSpec: | ||
workspaces: | ||
- name: data | ||
steps: | ||
- name: check-result | ||
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f | ||
script: | | ||
#!/usr/bin/env bash | ||
set -ex | ||
# Count the number of InternalRequests | ||
requestsCount=$(kubectl get InternalRequest -o json | jq -r '.items | length') | ||
# Check if the number of InternalRequests is as expected | ||
if [ "$requestsCount" -ne 1 ]; then | ||
echo "Unexpected number of InternalRequests. Expected: 1, Found: $requestsCount" | ||
exit 1 | ||
fi | ||
internalRequest=$(kubectl get InternalRequest -o json | jq -r '.items[0]') | ||
# Check the request field | ||
if [ "$(echo "$internalRequest" | jq -r '.spec.request' )" != "create-advisory" ]; then | ||
echo "InternalRequest doesn't contain 'create-advisory' in 'request' field" | ||
exit 1 | ||
fi | ||
# Check the advisory_json parameter | ||
if [ "$(echo "$internalRequest" | jq -r '.spec.params.advisory_json' )" != \ | ||
'{"type":"RHEA"'* ]; then | ||
echo "The advisory_json should have had its type overwritten to RHSA because there were CVEs" | ||
echo "in the releaseNotes. However, it was not" | ||
exit 1 | ||
fi | ||
finally: | ||
- name: cleanup | ||
taskSpec: | ||
steps: | ||
- name: delete-crs | ||
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f | ||
script: | | ||
#!/usr/bin/env sh | ||
set -eux | ||
kubectl delete internalrequests --all |