|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -eu |
| 4 | +# shellcheck source=tests/scripts/config.source |
| 5 | +. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source |
| 6 | + |
| 7 | +pulp debug has-plugin --name "core" --specifier ">=3.85.3" || exit 0 |
| 8 | +pulp debug has-plugin --name "rpm" --specifier ">=3.38.0" || exit 0 |
| 9 | + |
| 10 | +KERNEL_URL="https://vault.centos.org/7.0.1406/os/x86_64/Packages/kernel-3.10.0-123.el7.x86_64.rpm" |
| 11 | +OSV_CONFIG_A='[{"name": "AlmaLinux", "releases": ["9"]}]' |
| 12 | +OSV_CONFIG_B='[{"name": "Red Hat", "releases": ["cpe:/o:redhat:enterprise_linux:7::workstation"]}]' |
| 13 | +REPOSITORY=rpm_vulnerability_repo |
| 14 | +REPOSITORY_NO_CONFIG=rpm_vulnerability_repo_no_config |
| 15 | + |
| 16 | +cleanup () { |
| 17 | + pulp rpm repository destroy --name ${REPOSITORY} || true |
| 18 | + pulp rpm repository destroy --name ${REPOSITORY_NO_CONFIG} || true |
| 19 | +} |
| 20 | +trap cleanup EXIT |
| 21 | + |
| 22 | + |
| 23 | +get_osv_config(){ |
| 24 | + pulp rpm repository show --name "${1}" | jq '.osv_config' |
| 25 | +} |
| 26 | + |
| 27 | +# osv_config can be created |
| 28 | +expect_succ pulp rpm repository create --name ${REPOSITORY} --osv-config "${OSV_CONFIG_A}" |
| 29 | +test "$(get_osv_config $REPOSITORY)" != "null" |
| 30 | + |
| 31 | +# osv_config can be cleared |
| 32 | +expect_succ pulp rpm repository update --name ${REPOSITORY} --osv-config "" |
| 33 | +test "$(get_osv_config $REPOSITORY)" = "null" |
| 34 | + |
| 35 | +# osv_config can be modified |
| 36 | +expect_succ pulp rpm repository update --name ${REPOSITORY} --osv-config "${OSV_CONFIG_B}" |
| 37 | +test "$(get_osv_config $REPOSITORY)" != "null" |
| 38 | + |
| 39 | +# vulnerability generates a report |
| 40 | +pulp rpm content -t package create --file-url "${KERNEL_URL}" --repository ${REPOSITORY} |
| 41 | +expect_succ pulp rpm repository version scan --repository ${REPOSITORY} |
| 42 | +VULN_REPORT="$(pulp rpm repository version show --repository ${REPOSITORY} | jq -r '.vuln_report')" |
| 43 | +VULN_COUNT="$(pulp show --href "$VULN_REPORT" | jq '.results[0].vulns | length')" |
| 44 | +test "$VULN_COUNT" -gt 50 # kernels has lots of vuln reports |
| 45 | + |
| 46 | +# absence of osv_config fails |
| 47 | +pulp rpm repository create --name ${REPOSITORY_NO_CONFIG} |
| 48 | +expect_fail pulp rpm repository version scan --repository ${REPOSITORY_NO_CONFIG} |
0 commit comments