From 9e1873af35a2b530e71e1579b2d62c233b75ba26 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Mon, 9 Jul 2018 16:11:18 +0300 Subject: Make RelativeDistinguishedName preserve attribtue order (#4306) Duplicate attributes now raise an error instead of silently discarding duplicates. --- tests/x509/test_x509.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/x509/test_x509.py b/tests/x509/test_x509.py index 335a0fbf..7f9f1830 100644 --- a/tests/x509/test_x509.py +++ b/tests/x509/test_x509.py @@ -3886,11 +3886,11 @@ class TestRelativeDistinguishedName(object): x509.RelativeDistinguishedName(["not-a-NameAttribute"]) def test_init_duplicate_attribute(self): - rdn = x509.RelativeDistinguishedName([ - x509.NameAttribute(x509.ObjectIdentifier('2.999.1'), u'value1'), - x509.NameAttribute(x509.ObjectIdentifier('2.999.1'), u'value1'), - ]) - assert len(rdn) == 1 + with pytest.raises(ValueError): + x509.RelativeDistinguishedName([ + x509.NameAttribute(x509.ObjectIdentifier('2.999.1'), u'val1'), + x509.NameAttribute(x509.ObjectIdentifier('2.999.1'), u'val1'), + ]) def test_hash(self): rdn1 = x509.RelativeDistinguishedName([ @@ -3932,8 +3932,11 @@ class TestRelativeDistinguishedName(object): assert rdn1 != object() def test_iter_input(self): + # Order must be preserved too attrs = [ - x509.NameAttribute(x509.ObjectIdentifier('2.999.1'), u'value1') + x509.NameAttribute(x509.ObjectIdentifier('2.999.1'), u'value1'), + x509.NameAttribute(x509.ObjectIdentifier('2.999.1'), u'value2'), + x509.NameAttribute(x509.ObjectIdentifier('2.999.1'), u'value3') ] rdn = x509.RelativeDistinguishedName(iter(attrs)) assert list(rdn) == attrs -- cgit v1.2.3