Skip to content

Commit cab062d

Browse files
committed
Add regipy and packagedcode-msitools as deps #2565
* Add cli tests for win_pe and mum package detection * Update test results Signed-off-by: Jono Yang <[email protected]>
1 parent e2d3534 commit cab062d

File tree

12 files changed

+200
-5
lines changed

12 files changed

+200
-5
lines changed

requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ chardet==4.0.0
1010
click==8.0.1
1111
colorama==0.4.4
1212
commoncode==21.5.25
13+
construct==2.10.67
1314
cryptography==3.4.7
1415
debian-inspector==21.5.25
1516
dparse==0.5.1
@@ -24,18 +25,22 @@ gemfileparser==0.8.0
2425
html5lib==1.1
2526
idna==2.10
2627
importlib-metadata==4.4.0
28+
inflection==0.5.1
2729
intbitset==2.4.1
2830
isodate==0.6.0
2931
jaraco.functools==3.3.0
3032
javaproperties==0.8.0
3133
Jinja2==3.0.1
34+
jsonlines==2.0.0
3235
jsonstreams==0.6.0
3336
license-expression==1.2
37+
Logbook==1.5.3
3438
lxml==4.6.3
3539
MarkupSafe==2.0.1
3640
more-itertools==8.8.0
3741
nltk==3.4.5
3842
normality==2.2.2
43+
packagedcode-msitools==0.101.210706
3944
packageurl-python==0.9.4
4045
packaging==20.9
4146
patch==1.16
@@ -52,8 +57,10 @@ pycparser==2.20
5257
Pygments==2.9.0
5358
pymaven-patch==0.3.0
5459
pyparsing==2.4.7
60+
pytz==2021.1
5561
PyYAML==5.4.1
5662
rdflib==5.0.0
63+
regipy==1.9.3
5764
requests==2.25.1
5865
rpm-inspector-rpm==4.16.1.3.210404
5966
saneyaml==0.5.2
@@ -62,8 +69,10 @@ six==1.16.0
6269
sortedcontainers==2.4.0
6370
soupsieve==2.2.1
6471
spdx-tools==0.6.1
72+
tabulate==0.8.9
6573
text-unidecode==1.3
6674
toml==0.10.2
75+
tqdm==4.61.2
6776
typecode==21.6.1
6877
typecode-libmagic==5.39.210531
6978
typing==3.6.6

setup-mini.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ full =
112112
# linux-only package handling
113113
packages =
114114
rpm_inspector_rpm >= 4.16.1.3; platform_system == 'Linux'
115+
regipy >= 1.9.3; platform_system == 'Linux'
116+
packagedcode_msitools >= 0.101.210706; platform_system == 'Linux'
115117

116118
dev =
117119
pytest

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ full =
112112
# linux-only package handling
113113
packages =
114114
rpm_inspector_rpm >= 4.16.1.3; platform_system == 'Linux'
115+
regipy >= 1.9.3; platform_system == 'Linux'
116+
packagedcode_msitools >= 0.101.210706; platform_system == 'Linux'
115117

116118
dev =
117119
pytest

src/packagedcode/msi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from commoncode.command import execute
1818
from commoncode.command import find_in_path
19+
from commoncode.system import on_linux
1920
from commoncode.version import VERSION_PATTERNS_REGEX
2021
from packagedcode import models
2122

@@ -175,4 +176,5 @@ class MsiInstallerPackage(models.Package):
175176

176177
@classmethod
177178
def recognize(cls, location):
178-
yield msi_parse(location)
179+
if on_linux:
180+
yield msi_parse(location)

src/packagedcode/windows.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def logger_debug(*args):
3636
@attr.s()
3737
class MicrosoftUpdateManifestPackage(models.Package):
3838
extensions = ('.mum',)
39+
filetypes = ('xml 1.0 document',)
40+
mimetypes = ('text/xml',)
3941

4042
default_type = 'windows-update'
4143

@@ -53,7 +55,7 @@ def parse_mum(location):
5355
if not location.endswith('.mum'):
5456
return
5557
with open(location , 'rb') as loc:
56-
return xmltodict.parse(loc)
58+
return xmltodict.parse(loc)
5759

5860

5961
def parse(location):

tests/packagedcode/data/plugin/help.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Package: mozilla
187187

188188
--------------------------------------------
189189
Package: msi
190-
class: packagedcode.models:MsiInstallerPackage
190+
class: packagedcode.msi:MsiInstallerPackage
191191
extensions: .msi
192192
filetypes: msi installer
193193

@@ -258,6 +258,12 @@ Package: war
258258
extensions: .war
259259
filetypes: java archive , zip archive
260260

261+
--------------------------------------------
262+
Package: windows-update
263+
class: packagedcode.windows:MicrosoftUpdateManifestPackage
264+
extensions: .mum
265+
filetypes: xml 1.0 document
266+
261267
--------------------------------------------
262268
Package: winexe
263269
class: packagedcode.win_pe:WindowsExecutable
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"headers": [
3+
{
4+
"tool_name": "scancode-toolkit",
5+
"options": {
6+
"input": "<path>",
7+
"--json": "<file>",
8+
"--package": true,
9+
"--processes": "-1",
10+
"--strip-root": true
11+
},
12+
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
13+
"message": null,
14+
"errors": [],
15+
"extra_data": {
16+
"files_count": 1
17+
}
18+
}
19+
],
20+
"files": [
21+
{
22+
"path": "test.mum",
23+
"type": "file",
24+
"packages": [
25+
{
26+
"type": "windows-update",
27+
"namespace": null,
28+
"name": "Package_1_for_KB4601060",
29+
"version": "10.0.3770.4",
30+
"qualifiers": {},
31+
"subpath": null,
32+
"primary_language": null,
33+
"description": "Fix for KB4601060",
34+
"release_date": null,
35+
"parties": [
36+
{
37+
"type": "organization",
38+
"role": "owner",
39+
"name": "Microsoft Corporation",
40+
"email": null,
41+
"url": null
42+
}
43+
],
44+
"keywords": [],
45+
"homepage_url": "http://support.microsoft.com/?kbid=4601060",
46+
"download_url": null,
47+
"size": null,
48+
"sha1": null,
49+
"md5": null,
50+
"sha256": null,
51+
"sha512": null,
52+
"bug_tracking_url": null,
53+
"code_view_url": null,
54+
"vcs_url": null,
55+
"copyright": "Microsoft Corporation",
56+
"license_expression": null,
57+
"declared_license": null,
58+
"notice_text": null,
59+
"root_path": null,
60+
"dependencies": [],
61+
"contains_source_code": null,
62+
"source_packages": [],
63+
"extra_data": {},
64+
"purl": "pkg:windows-update/[email protected]",
65+
"repository_homepage_url": null,
66+
"repository_download_url": null,
67+
"api_data_url": null
68+
}
69+
],
70+
"scan_errors": []
71+
}
72+
]
73+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"headers": [
3+
{
4+
"tool_name": "scancode-toolkit",
5+
"options": {
6+
"input": "<path>",
7+
"--json": "<file>",
8+
"--package": true,
9+
"--processes": "-1",
10+
"--strip-root": true
11+
},
12+
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
13+
"message": null,
14+
"errors": [],
15+
"extra_data": {
16+
"files_count": 1
17+
}
18+
}
19+
],
20+
"files": [
21+
{
22+
"path": "file.exe",
23+
"type": "file",
24+
"packages": [
25+
{
26+
"type": "winexe",
27+
"namespace": null,
28+
"name": "File",
29+
"version": "5.03.3414.16721",
30+
"qualifiers": {},
31+
"subpath": null,
32+
"primary_language": null,
33+
"description": "File: determine file type",
34+
"release_date": null,
35+
"parties": [
36+
{
37+
"type": "organization",
38+
"role": "author",
39+
"name": "GnuWin32 <http://gnuwin32.sourceforge.net>",
40+
"email": null,
41+
"url": null
42+
}
43+
],
44+
"keywords": [],
45+
"homepage_url": "http://www.darwinsys.com/file/",
46+
"download_url": null,
47+
"size": null,
48+
"sha1": null,
49+
"md5": null,
50+
"sha256": null,
51+
"sha512": null,
52+
"bug_tracking_url": null,
53+
"code_view_url": null,
54+
"vcs_url": null,
55+
"copyright": "\u00a9 2009 Ian F. Darwin",
56+
"license_expression": "unknown",
57+
"declared_license": {
58+
"LegalCopyright": "\u00a9 2009 Ian F. Darwin",
59+
"LegalTrademarks": "GnuWin32\u00ae, File\u00ae, file\u00ae",
60+
"License": "Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995. Software written by Ian F. Darwin and others; maintained 1994-2004 Christos Zoulas. This software is not subject to any export provision of the United States Department of Commerce, and may be exported to any country or planet. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice immediately at the beginning of the file, without modification, this list of conditions, and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
61+
},
62+
"notice_text": null,
63+
"root_path": null,
64+
"dependencies": [],
65+
"contains_source_code": null,
66+
"source_packages": [],
67+
"extra_data": {},
68+
"purl": "pkg:winexe/[email protected]",
69+
"repository_homepage_url": null,
70+
"repository_download_url": null,
71+
"api_data_url": null
72+
}
73+
],
74+
"scan_errors": []
75+
}
76+
]
77+
}

tests/packagedcode/test_msi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
import os
1111

12+
import pytest
13+
14+
from commoncode.system import on_linux
15+
1216
from packagedcode.models import Party
1317
from packagedcode.msi import create_package_from_msiinfo_results
1418
from packagedcode.msi import MsiInstallerPackage
@@ -17,6 +21,7 @@
1721
from packages_test_utils import PackageTester
1822

1923

24+
@pytest.mark.skipif(not on_linux, reason='msiinfo only runs on Linux')
2025
class TestMsi(PackageTester):
2126
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')
2227

tests/packagedcode/test_plugin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,17 @@ def test_package_command_scan_cran_r_package(self):
139139
expected_file = self.get_test_loc('plugin/cran-package-expected.json')
140140
run_scan_click(['--package', '--strip-root', '--processes', '-1', test_dir, '--json', result_file])
141141
check_json_scan(expected_file, result_file, regen=False)
142+
143+
def test_package_command_scan_win_pe(self):
144+
test_dir = self.get_test_loc('win_pe/file.exe')
145+
result_file = self.get_temp_file('json')
146+
expected_file = self.get_test_loc('plugin/win_pe-package-expected.json')
147+
run_scan_click(['--package', '--strip-root', '--processes', '-1', test_dir, '--json', result_file])
148+
check_json_scan(expected_file, result_file, regen=False)
149+
150+
def test_package_command_scan_mum(self):
151+
test_dir = self.get_test_loc('windows/mum/test.mum')
152+
result_file = self.get_temp_file('json')
153+
expected_file = self.get_test_loc('plugin/mum-package-expected.json')
154+
run_scan_click(['--package', '--strip-root', '--processes', '-1', test_dir, '--json', result_file])
155+
check_json_scan(expected_file, result_file, regen=False)

0 commit comments

Comments
 (0)