Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: RPM package comparison by adding exceptions for version #313

Merged
merged 1 commit into from Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions notus/scanner/models/packages/rpm.py
Expand Up @@ -18,6 +18,11 @@

logger = logging.getLogger(__name__)

excpetions = [
"_fips",
".ksplice",
]


@dataclass
class RPMPackage(Package):
Expand All @@ -33,6 +38,12 @@ def _compare(self, other: "RPMPackage") -> PackageComparison:
if self.arch != other.arch:
return PackageComparison.NOT_COMPARABLE

for e in excpetions:
if (self.full_version.find(e) > -1) != (
other.full_version.find(e) > -1
):
return PackageComparison.NOT_COMPARABLE

if self.full_version == other.full_version:
return PackageComparison.EQUAL

Expand Down
30 changes: 30 additions & 0 deletions tests/models/packages/test_rpm.py
Expand Up @@ -253,3 +253,33 @@ def test_from_name_and_full_version(self):
self.assertEqual(package.version, "1.6.3")
self.assertEqual(package.release, "26.h1")
self.assertEqual(package.full_name, "cups-libs-1.6.3-26.h1.x86_64")

def test_exceptions(self):
"""tests for the exceptions _fips and .ksplice"""
package1 = RPMPackage.from_full_name("gnutls-3.6.16-4.el8.x86_64")
package2 = RPMPackage.from_full_name(
"gnutls-3.6.16-4.0.1.el8_fips.x86_64"
)

self.assertFalse(package1 > package2)
self.assertFalse(package2 > package1)

package1 = RPMPackage.from_full_name("gnutls-3.6.16-4.el8_fips.x86_64")

self.assertTrue(package2 > package1)

package1 = RPMPackage.from_full_name(
"openssl-libs-1.0.2k-24.0.3.el7_8.x86_64"
)
package2 = RPMPackage.from_full_name(
"openssl-libs-1.0.2k-24.0.3.ksplice1.el7_9.x86_64"
)

self.assertFalse(package1 > package2)
self.assertFalse(package2 > package1)

package1 = RPMPackage.from_full_name(
"openssl-libs-1.0.2k-24.0.3.ksplice1.el7_8.x86_64"
)

self.assertTrue(package2 > package1)