|
| 1 | +# This file is part of CycloneDX Python Library |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | +# Copyright (c) OWASP Foundation. All Rights Reserved. |
| 17 | + |
| 18 | +from unittest import TestCase |
| 19 | + |
| 20 | +from packageurl import PackageURL |
| 21 | + |
| 22 | +from cyclonedx._internal.compare import ComparablePackageURL |
| 23 | + |
| 24 | + |
| 25 | +class TestComparablePackageURL(TestCase): |
| 26 | + |
| 27 | + def test_differs_by_name(self) -> None: |
| 28 | + """ |
| 29 | + regression for https://github.com/CycloneDX/cyclonedx-python-lib/issues/1021 |
| 30 | +
|
| 31 | + name was missing from the comparison tuple, so two purls that differ |
| 32 | + only by name compared equal |
| 33 | + """ |
| 34 | + purl1 = ComparablePackageURL(PackageURL(type='pypi', name='foo', version='1.0.0')) |
| 35 | + purl2 = ComparablePackageURL(PackageURL(type='pypi', name='bar', version='1.0.0')) |
| 36 | + self.assertNotEqual(purl1, purl2) |
| 37 | + self.assertGreater(purl1, purl2) |
| 38 | + self.assertLess(purl2, purl1) |
| 39 | + |
| 40 | + def test_equal_same_purl(self) -> None: |
| 41 | + purl1 = ComparablePackageURL(PackageURL(type='pypi', name='foo', version='1.0.0')) |
| 42 | + purl2 = ComparablePackageURL(PackageURL(type='pypi', name='foo', version='1.0.0')) |
| 43 | + self.assertEqual(purl1, purl2) |
0 commit comments