From 912d3fbc84d72ea112e3a64494e9de69a105b0c3 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Thu, 29 Jan 2015 11:19:22 -0600 Subject: add attribute and objectidentifier classes for x509 name --- tests/test_x509.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests') diff --git a/tests/test_x509.py b/tests/test_x509.py index 5383871a..f8066699 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -248,3 +248,50 @@ class TestECDSACertificate(object): ) with pytest.raises(NotImplementedError): cert.public_key() + + +class TestAttribute(object): + def test_eq(self): + assert x509.Attribute( + x509.ObjectIdentifier('oid', 'name'), 'value' + ) == x509.Attribute( + x509.ObjectIdentifier('oid', 'name'), 'value' + ) + + def test_ne(self): + assert x509.Attribute( + x509.ObjectIdentifier('oid', 'name'), 'value' + ) != x509.Attribute( + x509.ObjectIdentifier('oid2', 'name'), 'value' + ) + assert x509.Attribute( + x509.ObjectIdentifier('oid', 'name'), 'value' + ) != x509.Attribute( + x509.ObjectIdentifier('oid', 'name2'), 'value' + ) + assert x509.Attribute( + x509.ObjectIdentifier('oid', 'name'), 'value' + ) != x509.Attribute( + x509.ObjectIdentifier('oid', 'name'), 'value2' + ) + assert x509.Attribute( + x509.ObjectIdentifier('oid', 'name'), 'value' + ) != object() + + +class TestObjectIdentifier(object): + def test_eq(self): + oid1 = x509.ObjectIdentifier('oid', 'name') + oid2 = x509.ObjectIdentifier('oid', 'name') + assert oid1 == oid2 + + def test_ne(self): + oid1 = x509.ObjectIdentifier('oid', 'name') + assert oid1 != x509.ObjectIdentifier('oid1', 'name') + assert oid1 != x509.ObjectIdentifier('oid', 'name1') + assert oid1 != x509.ObjectIdentifier('oid1', 'name1') + assert oid1 != object() + + def test_repr(self): + oid = x509.ObjectIdentifier("oid1", "name") + assert repr(oid) == "" -- cgit v1.2.3 From 806bfb24feb254287c588da4887b45025bec3623 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 2 Feb 2015 17:05:24 -0600 Subject: rename Attribute to NameAttribute and remove name from OID --- tests/test_x509.py | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/test_x509.py b/tests/test_x509.py index f8066699..cf583247 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -250,48 +250,43 @@ class TestECDSACertificate(object): cert.public_key() -class TestAttribute(object): +class TestNameAttribute(object): def test_eq(self): - assert x509.Attribute( - x509.ObjectIdentifier('oid', 'name'), 'value' - ) == x509.Attribute( - x509.ObjectIdentifier('oid', 'name'), 'value' + assert x509.NameAttribute( + x509.ObjectIdentifier('oid'), 'value' + ) == x509.NameAttribute( + x509.ObjectIdentifier('oid'), 'value' ) def test_ne(self): - assert x509.Attribute( - x509.ObjectIdentifier('oid', 'name'), 'value' - ) != x509.Attribute( - x509.ObjectIdentifier('oid2', 'name'), 'value' + assert x509.NameAttribute( + x509.ObjectIdentifier('2.5.4.3'), 'value' + ) != x509.NameAttribute( + x509.ObjectIdentifier('2.5.4.5'), 'value' ) - assert x509.Attribute( - x509.ObjectIdentifier('oid', 'name'), 'value' - ) != x509.Attribute( - x509.ObjectIdentifier('oid', 'name2'), 'value' + assert x509.NameAttribute( + x509.ObjectIdentifier('oid'), 'value' + ) != x509.NameAttribute( + x509.ObjectIdentifier('oid'), 'value2' ) - assert x509.Attribute( - x509.ObjectIdentifier('oid', 'name'), 'value' - ) != x509.Attribute( - x509.ObjectIdentifier('oid', 'name'), 'value2' - ) - assert x509.Attribute( - x509.ObjectIdentifier('oid', 'name'), 'value' + assert x509.NameAttribute( + x509.ObjectIdentifier('oid'), 'value' ) != object() class TestObjectIdentifier(object): def test_eq(self): - oid1 = x509.ObjectIdentifier('oid', 'name') - oid2 = x509.ObjectIdentifier('oid', 'name') + oid1 = x509.ObjectIdentifier('oid') + oid2 = x509.ObjectIdentifier('oid') assert oid1 == oid2 def test_ne(self): - oid1 = x509.ObjectIdentifier('oid', 'name') - assert oid1 != x509.ObjectIdentifier('oid1', 'name') - assert oid1 != x509.ObjectIdentifier('oid', 'name1') - assert oid1 != x509.ObjectIdentifier('oid1', 'name1') + oid1 = x509.ObjectIdentifier('oid') + assert oid1 != x509.ObjectIdentifier('oid1') assert oid1 != object() def test_repr(self): - oid = x509.ObjectIdentifier("oid1", "name") - assert repr(oid) == "" + oid = x509.ObjectIdentifier("2.5.4.3") + assert repr(oid) == "" + oid = x509.ObjectIdentifier("oid1") + assert repr(oid) == "" -- cgit v1.2.3