Esempio 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])
Esempio n. 2
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)