Skip to content

Commit 4467afe

Browse files
committed
tests: add resources and tests for --auto-cpe and --root
1 parent 4acac9b commit 4467afe

7 files changed

Lines changed: 74 additions & 1 deletion

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SECTIONS
2+
{
3+
.note.package (READONLY) : ALIGN(4) {
4+
BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */
5+
BYTE(0x38) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */
6+
BYTE(0x7e) BYTE(0x1a) BYTE(0xfe) BYTE(0xca) /* Note ID */
7+
BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */
8+
BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"rpm","osCpe":"cpe:/o:fedoraproject:fedora:34"}\x00' */
9+
BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a)
10+
BYTE(0x22) BYTE(0x72) BYTE(0x70) BYTE(0x6d)
11+
BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6f)
12+
BYTE(0x73) BYTE(0x43) BYTE(0x70) BYTE(0x65)
13+
BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x63)
14+
BYTE(0x70) BYTE(0x65) BYTE(0x3a) BYTE(0x2f)
15+
BYTE(0x6f) BYTE(0x3a) BYTE(0x66) BYTE(0x65)
16+
BYTE(0x64) BYTE(0x6f) BYTE(0x72) BYTE(0x61)
17+
BYTE(0x70) BYTE(0x72) BYTE(0x6f) BYTE(0x6a)
18+
BYTE(0x65) BYTE(0x63) BYTE(0x74) BYTE(0x3a)
19+
BYTE(0x66) BYTE(0x65) BYTE(0x64) BYTE(0x6f)
20+
BYTE(0x72) BYTE(0x61) BYTE(0x3a) BYTE(0x33)
21+
BYTE(0x34) BYTE(0x22) BYTE(0x7d) BYTE(0x00)
22+
}
23+
}
24+
INSERT AFTER .note.gnu.build-id;
25+
/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SECTIONS
2+
{
3+
.note.package (READONLY) : ALIGN(4) {
4+
BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */
5+
BYTE(0x38) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */
6+
BYTE(0x7e) BYTE(0x1a) BYTE(0xfe) BYTE(0xca) /* Note ID */
7+
BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */
8+
BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"rpm","osCpe":"cpe:/o:fedoraproject:fedora:33"}\x00' */
9+
BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a)
10+
BYTE(0x22) BYTE(0x72) BYTE(0x70) BYTE(0x6d)
11+
BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6f)
12+
BYTE(0x73) BYTE(0x43) BYTE(0x70) BYTE(0x65)
13+
BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x63)
14+
BYTE(0x70) BYTE(0x65) BYTE(0x3a) BYTE(0x2f)
15+
BYTE(0x6f) BYTE(0x3a) BYTE(0x66) BYTE(0x65)
16+
BYTE(0x64) BYTE(0x6f) BYTE(0x72) BYTE(0x61)
17+
BYTE(0x70) BYTE(0x72) BYTE(0x6f) BYTE(0x6a)
18+
BYTE(0x65) BYTE(0x63) BYTE(0x74) BYTE(0x3a)
19+
BYTE(0x66) BYTE(0x65) BYTE(0x64) BYTE(0x6f)
20+
BYTE(0x72) BYTE(0x61) BYTE(0x3a) BYTE(0x33)
21+
BYTE(0x33) BYTE(0x22) BYTE(0x7d) BYTE(0x00)
22+
}
23+
}
24+
INSERT AFTER .note.gnu.build-id;
25+
/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CPE_NAME="cpe:/o:fedoraproject:fedora:34"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ID=fedora
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpe:/o:fedoraproject:fedora:33

tests/test_basics.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import sys
44
from importlib import resources
5+
from pathlib import Path
56

6-
from _generate_package_notes import generate_section
7+
from _generate_package_notes import gather_data, generate_section
78

89

10+
class dict_dot(dict):
11+
__getattr__ = dict.get
12+
913
def test_fedora_package():
1014
input = dict(type='rpm', name='package', version='1.2.3', architecture='noarch', osCpe='CPE')
1115
text = '\n'.join(generate_section(input))
@@ -34,3 +38,17 @@ def test_fedora_long_name():
3438
text = '\n'.join(generate_section(input))
3539
expected = resources.read_text('resources', 'fedora-long-name.ld')
3640
assert text == expected[:-1]
41+
42+
def test_auto_cpe_system_release():
43+
opts = dict_dot(package_type='rpm', cpe='auto', root=Path(__file__).absolute().parent / 'resources/root/')
44+
input = gather_data(opts)
45+
text = '\n'.join(generate_section(input))
46+
expected = resources.read_text('resources', 'fedora-cpe-system-release.ld')
47+
assert text == expected[:-1]
48+
49+
def test_auto_cpe_os_release():
50+
opts = dict_dot(package_type='rpm', cpe='auto', root=Path(__file__).absolute().parent / 'resources/root-no-cpe/')
51+
input = gather_data(opts)
52+
text = '\n'.join(generate_section(input))
53+
expected = resources.read_text('resources', 'fedora-cpe-os-release.ld')
54+
assert text == expected[:-1]

tests/test_basics.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ diff <("${testdir}/../generate-package-notes.sh" --type rpm --name package --ver
99
diff <("${testdir}/../generate-package-notes.sh" --type deb --name A --package-version 0 --architecture x --cpe o) "${testdir}/resources/very-short.ld"
1010
diff <("${testdir}/../generate-package-notes.sh" --type deb --name A --version 0 --architecture x --osCpe o --readonly false) "${testdir}/resources/very-short-rw.ld"
1111
diff <("${testdir}/../generate-package-notes.sh" --type rpm --name rust-plist+enable_unstable_features_that_may_break_with_minor_version_bumps-devel --version 200:1.3.1~rc1.post2^final3 --architecture ppc64le --osCpe cpe:/o:fedoraproject:fedora:35 --debugInfoUrl https://somewhere.on.the.internet.there.is.a.server.which.is.never.wrong/query) "${testdir}/resources/fedora-long-name.ld"
12+
diff <("${testdir}/../generate-package-notes.sh" --type rpm --cpe auto --root "${testdir}/resources/root-no-cpe/") "${testdir}/resources/fedora-cpe-os-release.ld"
13+
diff <("${testdir}/../generate-package-notes.sh" --type rpm --cpe auto --root "${testdir}/resources/root/") "${testdir}/resources/fedora-cpe-system-release.ld"

0 commit comments

Comments
 (0)