def test_simple_rdn_1(self): rdn1 = RelativeDistinguishedName.create("CN", "Rick Astley") rdn2 = RelativeDistinguishedName.create("CN", "Rick Astley") rdn3 = RelativeDistinguishedName.create("CN", "Darude") self.assertEqual(rdn1, rdn2) self.assertNotEqual(rdn1, rdn3) self.assertEqual(rdn1.rfc2253_str, "CN=Rick Astley")
def test_string_parse(self): dn = DistinguishedName.from_rfc2253_str("cn=foo,ou=bar,o=koo") self.assertEqual(dn, DistinguishedName([ RelativeDistinguishedName.create("CN", "foo"), RelativeDistinguishedName.create("OU", "bar"), RelativeDistinguishedName.create("O", "koo") ])) dn = DistinguishedName.from_rfc2253_str("cn=foo,ou=bar,o=koo+ou=moo") self.assertEqual(dn, DistinguishedName([ RelativeDistinguishedName.create("CN", "foo"), RelativeDistinguishedName.create("OU", "bar"), RelativeDistinguishedName.create("O", "koo", "OU", "moo") ])) dn = DistinguishedName.from_rfc2253_str("") self.assertEqual(dn, DistinguishedName([ ]))
def test_simple_dn_2(self): elements = [ RelativeDistinguishedName.create("CN", "Rick Astley"), RelativeDistinguishedName.create("OU", "Infinite Persistence Systems Inc.") ] dn1 = DistinguishedName(elements) self.assertEqual(dn1.rfc2253_str, "OU=Infinite Persistence Systems Inc.,CN=Rick Astley") elements = [ RelativeDistinguishedName.create("OU", "Infinite Persistence Systems Inc."), RelativeDistinguishedName.create("CN", "Rick Astley") ] dn2 = DistinguishedName(elements) self.assertEqual(dn2.rfc2253_str, "CN=Rick Astley,OU=Infinite Persistence Systems Inc.") self.assertNotEqual(dn1, dn2)
def _decode_hook(self): if self.asn1 is None: self._distribution_points = None return self._distribution_points = [] for asn1_point in self.asn1: point_name_rdn_malformed = False if asn1_point["distributionPoint"].hasValue(): point_name_asn1 = asn1_point["distributionPoint"].getComponent( ) if asn1_point["distributionPoint"]["fullName"].hasValue(): # GeneralNames point_name = ASN1GeneralNamesWrapper.from_asn1( point_name_asn1) else: # RelativeDistinguishedName try: point_name = RelativeDistinguishedName.from_asn1( point_name_asn1) except InvalidInputException: point_name = None point_name_rdn_malformed = True else: point_name = None if asn1_point["reasons"].hasValue(): reasons = set() for (bitno, value) in enumerate(asn1_point["reasons"]): if value == 1: value = self._KNOWN_REASON_BITS.get(bitno, bitno) reasons.add(value) reasons_trailing_zero = ASN1Tools.bitstring_has_trailing_zeros( asn1_point["reasons"]) else: reasons = None reasons_trailing_zero = False if asn1_point["cRLIssuer"].hasValue(): crl_issuer = ASN1GeneralNamesWrapper.from_asn1( asn1_point["cRLIssuer"]) else: crl_issuer = None cdp = self._DistributionPoint( point_name=point_name, point_name_rdn_malformed=point_name_rdn_malformed, reasons=reasons, reasons_trailing_zero=reasons_trailing_zero, crl_issuer=crl_issuer) self._distribution_points.append(cdp)
def test_equality_dn(self): dn1 = DistinguishedName([ RelativeDistinguishedName.create("CN", "Foo"), RelativeDistinguishedName.create("CN", "Bar") ]) dn2 = DistinguishedName([ RelativeDistinguishedName.create("CN", "Bar"), RelativeDistinguishedName.create("CN", "Foo") ]) dn3 = DistinguishedName([ RelativeDistinguishedName.create("CN", "Foo"), RelativeDistinguishedName.create("CN", "Bar") ]) self.assertNotEqual(dn1, dn2) self.assertEqual(dn1, dn3)
def test_equality_rdn(self): rdn1 = RelativeDistinguishedName.create("CN", "Foo", "O", "Bar") rdn2 = RelativeDistinguishedName.create("O", "Bar", "CN", "Foo") self.assertEqual(rdn1, rdn2)
def test_simple_dn_3(self): elements = [ RelativeDistinguishedName.create("CN", "Rick Astley"), RelativeDistinguishedName.create("CN", "Foo Bar"), RelativeDistinguishedName.create("OU", "OrgUnit"), RelativeDistinguishedName.create("CN", "Bar Foo") ] dn = DistinguishedName(elements) self.assertEqual(dn.rfc2253_str, "CN=Bar Foo,OU=OrgUnit,CN=Foo Bar,CN=Rick Astley")
def test_simple_dn_1(self): elements = [ RelativeDistinguishedName.create("CN", "Rick Astley") ] dn = DistinguishedName(elements) self.assertEqual(dn.rfc2253_str, "CN=Rick Astley")
def test_simple_mvrdn_2(self): rdn = RelativeDistinguishedName.create("CN", "Rick Astley", "CN", "Foo Bar") self.assertIn(rdn.rfc2253_str, [ "CN=Rick Astley+CN=Foo Bar", "CN=Foo Bar+CN=Rick Astley" ])
def test_simple_mvrdn_1(self): # Order of elements in RDN does not matter rdn = RelativeDistinguishedName.create("CN", "Rick Astley", "OU", "Infinite Persistence Systems Inc.") self.assertIn(rdn.rfc2253_str, [ "CN=Rick Astley+OU=Infinite Persistence Systems Inc.", "OU=Infinite Persistence Systems Inc.+CN=Rick Astley" ])