[poky,master,3/3] cve_export.py: Add new selftest for cve-export.bbclass

Message ID 20220511143613.25002-3-akash.hadke@kpit.com
State New
Headers show
Series [poky,master,1/3] cve_check.py: Add new method get_ignored_cves | expand

Commit Message

Akash Hadke May 11, 2022, 2:36 p.m. UTC
This test compares values of variables CVE_CHECK_IGNORE with
CVE_IGNORED that is exported from cve-export.bbclass

Signed-off-by: Akash Hadke <akash.hadke@kpit.com>
Signed-off-by: Akash Hadke <hadkeakash4@gmail.com>
---
 meta/lib/oeqa/selftest/cases/cve_export.py | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 meta/lib/oeqa/selftest/cases/cve_export.py

Patch

diff --git a/meta/lib/oeqa/selftest/cases/cve_export.py b/meta/lib/oeqa/selftest/cases/cve_export.py
new file mode 100644
index 0000000000..7c7fd07957
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/cve_export.py
@@ -0,0 +1,24 @@ 
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import bitbake, get_bb_var
+from oe.cve_check import get_ignored_cves
+
+class CveExportTest (OESelftestTestCase):
+
+    def test_ignored_cves(self):
+        """
+        This test compares the values of variables CVE_CHECK_IGNORE with
+        CVE_IGNORED that is exported from cve-export.bbclass
+        """
+        target = 'unzip'
+        feature = 'INHERIT += "cve-export"\n'
+        feature += 'require conf/distro/include/cve-extra-exclusions.inc'
+        self.write_config(feature)
+
+        res = bitbake("%s -c fetch" % target, ignore_status=True)
+        self.assertEqual(res.status, 0, "\nCouldn't build.\nbitbake output %s" % res.output)
+
+        paths = get_bb_var('PATH', target).split(':')
+        cves = get_bb_var('CVE_CHECK_IGNORE', target).split()
+        final_cve = get_ignored_cves(paths, cves)
+        ignore_cves_from_exported_variable = get_bb_var('CVE_IGNORED', target)
+        self.assertEqual(final_cve, ignore_cves_from_exported_variable.strip(), "Ignored CVEs are not matching")