|
2 | 2 | # SPDX-License-Identifier: GPL-3.0-or-later
|
3 | 3 |
|
4 | 4 | import subprocess
|
5 |
| -from os import environ |
6 | 5 | from os.path import dirname, join
|
7 |
| -from sys import platform |
8 | 6 |
|
9 | 7 | import distro
|
10 | 8 | import pytest
|
@@ -38,16 +36,43 @@ class TestPackageListParser:
|
38 | 36 | },
|
39 | 37 | }
|
40 | 38 |
|
| 39 | + # Find the versions of the ubuntu packages |
| 40 | + UBUNTU_PACKAGE_VERSIONS = ( |
| 41 | + ( |
| 42 | + subprocess.run( |
| 43 | + [ |
| 44 | + "dpkg-query", |
| 45 | + "--show", |
| 46 | + "--showformat=${Version}\n", |
| 47 | + "bash", |
| 48 | + "binutils", |
| 49 | + "wget", |
| 50 | + ], |
| 51 | + stdout=subprocess.PIPE, |
| 52 | + ) |
| 53 | + .stdout.decode("utf-8") |
| 54 | + .splitlines() |
| 55 | + ) |
| 56 | + if "ubuntu" in distro.id() |
| 57 | + else ["dummy", "array", "for windows"] |
| 58 | + ) |
| 59 | + |
41 | 60 | UBUNTU_PARSED_TRIAGE_DATA = {
|
42 |
| - ProductInfo(vendor="gnu*", product="bash", version="5.0-6ubuntu1.1"): { |
| 61 | + ProductInfo( |
| 62 | + vendor="gnu*", product="bash", version=UBUNTU_PACKAGE_VERSIONS[0] |
| 63 | + ): { |
43 | 64 | "default": {"remarks": Remarks.NewFound, "comments": "", "severity": ""},
|
44 | 65 | "paths": {""},
|
45 | 66 | },
|
46 |
| - ProductInfo(vendor="gnu*", product="binutils", version="2.34-6ubuntu1.3"): { |
| 67 | + ProductInfo( |
| 68 | + vendor="gnu*", product="binutils", version=UBUNTU_PACKAGE_VERSIONS[1] |
| 69 | + ): { |
47 | 70 | "default": {"remarks": Remarks.NewFound, "comments": "", "severity": ""},
|
48 | 71 | "paths": {""},
|
49 | 72 | },
|
50 |
| - ProductInfo(vendor="gnu*", product="wget", version="1.20.3-1ubuntu1"): { |
| 73 | + ProductInfo( |
| 74 | + vendor="gnu*", product="wget", version=UBUNTU_PACKAGE_VERSIONS[2] |
| 75 | + ): { |
51 | 76 | "default": {"remarks": Remarks.NewFound, "comments": "", "severity": ""},
|
52 | 77 | "paths": {""},
|
53 | 78 | },
|
@@ -103,25 +128,13 @@ def test_invalid_linux_list(self, filepath, caplog):
|
103 | 128 | assert expected_output == [rec.message for rec in caplog.records]
|
104 | 129 |
|
105 | 130 | @pytest.mark.skipif(
|
106 |
| - "ACTIONS" not in environ |
107 |
| - or not platform == "linux" |
108 |
| - or ("ubuntu" not in distro.id() and "20.04" not in distro.version()), |
109 |
| - reason="Running locally requires root permission", |
| 131 | + "ubuntu" not in distro.id(), |
| 132 | + reason="Test for Ubuntu systems", |
110 | 133 | )
|
111 | 134 | @pytest.mark.parametrize(
|
112 | 135 | "filepath, parsed_data",
|
113 | 136 | [(join(TXT_PATH, "test_ubuntu_list.txt"), UBUNTU_PARSED_TRIAGE_DATA)],
|
114 | 137 | )
|
115 | 138 | def test_valid_ubuntu_list(self, filepath, parsed_data):
|
116 |
| - subprocess.run( |
117 |
| - [ |
118 |
| - "sudo", |
119 |
| - "apt-get", |
120 |
| - "install", |
121 |
| - "bash=5.0-6ubuntu1.1", |
122 |
| - "binutils=2.34-6ubuntu1.3", |
123 |
| - "wget=1.20.3-1ubuntu1", |
124 |
| - ] |
125 |
| - ) |
126 | 139 | package_list = PackageListParser(filepath, error_mode=ErrorMode.FullTrace)
|
127 | 140 | assert package_list.parse_list() == parsed_data
|
0 commit comments