Exemplo n.º 1
0
    def test_multi_value(self):
        subject = 'CN=www.redhat.com,OU=engineering,OU=boston+OU=westford,C=US'
        cn_ava = nss.AVA('cn', self.cn_name)
        ou1_ava1 = nss.AVA('ou', 'boston')
        ou1_ava2 = nss.AVA('ou', 'westford')
        ou2_ava1 = nss.AVA('ou', 'engineering')
        c_ava = nss.AVA('c', self.c_name)

        cn_rdn = nss.RDN(cn_ava)
        ou1_rdn = nss.RDN(ou1_ava1, ou1_ava2)
        ou2_rdn = nss.RDN(ou2_ava1)
        c_rdn = nss.RDN(c_ava)

        name = nss.DN(subject)

        self.assertEqual(len(name), 4)

        self.assertEqual(name['cn'], [cn_rdn])
        self.assertEqual(name['ou'], [ou1_rdn, ou2_rdn])
        self.assertEqual(name['c'], [c_rdn])

        rdn = name['ou'][0]
        self.assertEqual(len(rdn), 2)
        self.assertEqual(rdn, ou1_rdn)
        self.assertEqual(rdn[0], ou1_ava1)
        self.assertEqual(rdn[1], ou1_ava2)
        self.assertEqual(list(rdn), [ou1_ava1, ou1_ava2])
        self.assertEqual(rdn[:], [ou1_ava1, ou1_ava2])
Exemplo n.º 2
0
    def test_rdn_compare(self):
        cn_rdn1 = nss.RDN(nss.AVA('cn', self.cn_name))
        cn_rdn2 = nss.RDN(nss.AVA('cn', self.cn_name))
        cn_rdn3 = nss.RDN(nss.AVA('cn', self.cn_name + 'A'))
        ou_rdn = nss.RDN(nss.AVA('ou', self.ou_name))

        self.assertEqual(cmp(cn_rdn1, cn_rdn2), 0)
        self.assertEqual(cmp(cn_rdn1, ou_rdn), -1)
        self.assertEqual(cmp(cn_rdn1, cn_rdn3), -1)
Exemplo n.º 3
0
    def test_rdn_compare(self):
        cn_rdn1 = nss.RDN(nss.AVA('cn', self.cn_name))
        cn_rdn2 = nss.RDN(nss.AVA('cn', self.cn_name))
        cn_rdn3 = nss.RDN(nss.AVA('cn', self.cn_name + 'A'))
        ou_rdn = nss.RDN(nss.AVA('ou', self.ou_name))

        self.assertTrue(cn_rdn1 == cn_rdn2)
        self.assertTrue(cn_rdn1 < ou_rdn)
        self.assertTrue(cn_rdn1 < cn_rdn3)
Exemplo n.º 4
0
    def test_name(self):
        cn_rdn = nss.RDN(nss.AVA('cn', self.cn_name))
        ou_rdn = nss.RDN(nss.AVA('ou', self.ou_name))
        o_rdn = nss.RDN(nss.AVA('o', self.o_name))
        l_rdn = nss.RDN(nss.AVA('l', self.l_name))
        st_rdn = nss.RDN(nss.AVA('st', self.st_name))
        c_rdn = nss.RDN(nss.AVA('c', self.c_name))

        name = nss.DN(self.subject_name)
        self.assertEqual(str(name), self.subject_name)

        self.assertEqual(name[0], c_rdn)
        self.assertEqual(name[1], st_rdn)
        self.assertEqual(name[2], l_rdn)
        self.assertEqual(name[3], o_rdn)
        self.assertEqual(name[4], ou_rdn)
        self.assertEqual(name[5], cn_rdn)

        self.assertEqual(len(name), 6)

        i = 0
        for rdn in name:
            if i == 0: self.assertEqual(rdn, c_rdn)
            elif i == 1: self.assertEqual(rdn, st_rdn)
            elif i == 2: self.assertEqual(rdn, l_rdn)
            elif i == 3: self.assertEqual(rdn, o_rdn)
            elif i == 4: self.assertEqual(rdn, ou_rdn)
            elif i == 5: self.assertEqual(rdn, cn_rdn)
            else: self.fail("excess rdn's")
            i += 1

        self.assertEqual(list(name),
                         [c_rdn, st_rdn, l_rdn, o_rdn, ou_rdn, cn_rdn])
        self.assertEqual(name[:],
                         [c_rdn, st_rdn, l_rdn, o_rdn, ou_rdn, cn_rdn])

        self.assertEqual(name['c'], [c_rdn])
        self.assertEqual(name['st'], [st_rdn])
        self.assertEqual(name['l'], [l_rdn])
        self.assertEqual(name['o'], [o_rdn])
        self.assertEqual(name['ou'], [ou_rdn])
        self.assertEqual(name['cn'], [cn_rdn])

        self.assertEqual(name.email_address, None)
        self.assertEqual(name.common_name, self.cn_name)
        self.assertEqual(name.country_name, self.c_name)
        self.assertEqual(name.locality_name, self.l_name)
        self.assertEqual(name.state_name, self.st_name)
        self.assertEqual(name.org_name, self.o_name)
        self.assertEqual(name.dc_name, None)
        self.assertEqual(name.org_unit_name, self.ou_name)
        self.assertEqual(name.cert_uid, None)

        name = nss.DN()
        self.assertEqual(str(name), '')

        name = nss.DN([])
        self.assertEqual(str(name), '')

        name = nss.DN(())
        self.assertEqual(str(name), '')

        name = nss.DN('')
        self.assertEqual(str(name), '')

        self.assertRaises(TypeError, nss.DN, 1)

        name.add_rdn(cn_rdn)
        self.assertEqual(name[0], cn_rdn)
        self.assertEqual(name['cn'], [cn_rdn])
        self.assertEqual(str(name), 'CN=%s' % self.cn_name)

        name.add_rdn(ou_rdn)
        self.assertEqual(name[0], cn_rdn)
        self.assertEqual(name[1], ou_rdn)
        self.assertEqual(name['cn'], [cn_rdn])
        self.assertEqual(name['ou'], [ou_rdn])
        self.assertEqual(str(name),
                         'OU=%s,CN=%s' % (self.ou_name, self.cn_name))

        name = nss.DN(cn_rdn, ou_rdn)
        self.assertEqual(name[0], cn_rdn)
        self.assertEqual(name[1], ou_rdn)
        self.assertEqual(name['cn'], [cn_rdn])
        self.assertEqual(name['ou'], [ou_rdn])
        self.assertEqual(str(name),
                         'OU=%s,CN=%s' % (self.ou_name, self.cn_name))

        self.assertEqual(name.has_key('cn'), True)
        self.assertEqual(name.has_key('ou'), True)
        self.assertEqual(name.has_key('st'), False)
Exemplo n.º 5
0
    def test_rdn_create(self):
        cn_ava = nss.AVA('cn', self.cn_name)
        ou_ava = nss.AVA('ou', self.ou_name)

        rdn = nss.RDN()
        self.assertEqual(len(rdn), 0)
        self.assertEqual(str(rdn), '')

        rdn = nss.RDN(cn_ava)
        self.assertEqual(len(rdn), 1)
        self.assertEqual(str(rdn), 'CN=%s' % (self.cn_name))
        self.assertEqual(rdn[0], cn_ava)
        self.assertEqual(rdn['cn'], [cn_ava])

        rdn = nss.RDN(cn_ava, ou_ava)
        self.assertEqual(len(rdn), 2)
        self.assertEqual(str(rdn),
                         'CN=%s+OU=%s' % (self.cn_name, self.ou_name))

        self.assertEqual(rdn[0], cn_ava)
        self.assertEqual(rdn[1], ou_ava)

        i = 0
        for ava in rdn:
            if i == 0: self.assertEqual(ava, cn_ava)
            elif i == 1: self.assertEqual(ava, ou_ava)
            else: self.fail("excess ava's")
            i += 1

        self.assertEqual(list(rdn), [cn_ava, ou_ava])
        self.assertEqual(rdn[:], [cn_ava, ou_ava])

        self.assertEqual(rdn['cn'], [cn_ava])
        self.assertEqual(rdn['ou'], [ou_ava])

        self.assertEqual(str(rdn[0]), "CN=%s" % self.cn_name)
        self.assertEqual(str(rdn[1]), "OU=%s" % self.ou_name)

        self.assertEqual(rdn['2.5.4.3'], [cn_ava])
        self.assertEqual(rdn.has_key('cn'), True)
        self.assertEqual(rdn.has_key('2.5.4.3'), True)
        self.assertEqual(rdn.has_key('st'), False)

        self.assertEqual(list(rdn), [cn_ava, ou_ava])
        self.assertEqual(rdn[0:2], [cn_ava, ou_ava])

        i = 0
        for ava in rdn:
            if i == 0: self.assertEqual(rdn[i], cn_ava)
            if i == 1: self.assertEqual(rdn[i], ou_ava)

        try:
            rdn['st']
            self.fail("expected KeyError for 'st'")
        except KeyError:
            pass

        try:
            rdn['junk']
            self.fail("expected KeyError for 'junk'")
        except KeyError:
            pass