예제 #1
0
 def dn2zone_name(self, dn):
     """cn=KSK-20140813162153Z-cede9e182fc4af76c4bddbc19123a565,cn=keys,idnsname=test,cn=dns,dc=ipa,dc=example"""
     # verify that metadata object is under DNS sub-tree
     dn = DN(dn)
     container = DN(self.api.env.container_dns, self.api.env.basedn)
     idx = dn.rfind(container)
     assert idx != -1, "Metadata object %s is not inside %s" % (dn, container)
     assert len(dn[idx - 1]) == 1, "Multi-valued RDN as zone name is not supported"
     return dns.name.from_text(dn[idx - 1]["idnsname"])
예제 #2
0
 def dn2zone_name(self, dn):
     """cn=KSK-20140813162153Z-cede9e182fc4af76c4bddbc19123a565,cn=keys,idnsname=test,cn=dns,dc=ipa,dc=example"""
     # verify that metadata object is under DNS sub-tree
     dn = DN(dn)
     container = DN(self.api.env.container_dns, self.api.env.basedn)
     idx = dn.rfind(container)
     assert idx != -1, 'Metadata object %s is not inside %s' % (dn, container)
     assert len(dn[idx - 1]) == 1, 'Multi-valued RDN as zone name is not supported'
     return dns.name.from_text(dn[idx - 1]['idnsname'])
예제 #3
0
    def test_find(self):
        #        -10 -9  -8     -7  -6  -5  -4     -3  -2  -1
        dn = DN('t=0,t=1,cn=bob,t=3,t=4,t=5,cn=bob,t=7,t=8,t=9')
        pat = DN('cn=bob')

        # forward
        assert dn.find(pat) == 2
        assert dn.find(pat, 1) == 2
        assert dn.find(pat, 1, 3) == 2
        assert dn.find(pat, 2, 3) == 2
        assert dn.find(pat, 6) == 6

        assert dn.find(pat, 7) == -1
        assert dn.find(pat, 1, 2) == -1

        with pytest.raises(ValueError):
            assert dn.index(pat, 7) == -1
        with pytest.raises(ValueError):
            assert dn.index(pat, 1, 2) == -1

        # reverse
        assert dn.rfind(pat) == 6
        assert dn.rfind(pat, -4) == 6
        assert dn.rfind(pat, 6) == 6
        assert dn.rfind(pat, 6, 8) == 6
        assert dn.rfind(pat, 6, 8) == 6
        assert dn.rfind(pat, -8) == 6
        assert dn.rfind(pat, -8, -4) == 6
        assert dn.rfind(pat, -8, -5) == 2

        assert dn.rfind(pat, 7) == -1
        assert dn.rfind(pat, -3) == -1

        with pytest.raises(ValueError):
            assert dn.rindex(pat, 7) == -1
        with pytest.raises(ValueError):
            assert dn.rindex(pat, -3) == -1
예제 #4
0
    def test_find(self):
        #        -10 -9  -8     -7  -6  -5  -4     -3  -2  -1
        dn = DN('t=0,t=1,cn=bob,t=3,t=4,t=5,cn=bob,t=7,t=8,t=9')
        pat = DN('cn=bob')

        # forward
        self.assertEqual(dn.find(pat), 2)
        self.assertEqual(dn.find(pat, 1), 2)
        self.assertEqual(dn.find(pat, 1, 3), 2)
        self.assertEqual(dn.find(pat, 2, 3), 2)
        self.assertEqual(dn.find(pat, 6), 6)

        self.assertEqual(dn.find(pat, 7), -1)
        self.assertEqual(dn.find(pat, 1, 2), -1)

        with self.assertRaises(ValueError):
            self.assertEqual(dn.index(pat, 7), -1)
        with self.assertRaises(ValueError):
            self.assertEqual(dn.index(pat, 1, 2), -1)

        # reverse
        self.assertEqual(dn.rfind(pat), 6)
        self.assertEqual(dn.rfind(pat, -4), 6)
        self.assertEqual(dn.rfind(pat, 6), 6)
        self.assertEqual(dn.rfind(pat, 6, 8), 6)
        self.assertEqual(dn.rfind(pat, 6, 8), 6)
        self.assertEqual(dn.rfind(pat, -8), 6)
        self.assertEqual(dn.rfind(pat, -8, -4), 6)
        self.assertEqual(dn.rfind(pat, -8, -5), 2)

        self.assertEqual(dn.rfind(pat, 7), -1)
        self.assertEqual(dn.rfind(pat, -3), -1)

        with self.assertRaises(ValueError):
            self.assertEqual(dn.rindex(pat, 7), -1)
        with self.assertRaises(ValueError):
            self.assertEqual(dn.rindex(pat, -3), -1)
예제 #5
0
파일: test_dn.py 프로젝트: guanwei/freeipa
    def test_find(self):
        #        -10 -9  -8     -7  -6  -5  -4     -3  -2  -1
        dn = DN('t=0,t=1,cn=bob,t=3,t=4,t=5,cn=bob,t=7,t=8,t=9')
        pat = DN('cn=bob')

        # forward
        self.assertEqual(dn.find(pat),          2)
        self.assertEqual(dn.find(pat,  1),      2)
        self.assertEqual(dn.find(pat,  1,  3),  2)
        self.assertEqual(dn.find(pat,  2,  3),  2)
        self.assertEqual(dn.find(pat,  6),      6)

        self.assertEqual(dn.find(pat,  7),     -1)
        self.assertEqual(dn.find(pat,  1,  2), -1)

        with self.assertRaises(ValueError):
            self.assertEqual(dn.index(pat,  7),     -1)
        with self.assertRaises(ValueError):
            self.assertEqual(dn.index(pat,  1,  2), -1)

        # reverse
        self.assertEqual(dn.rfind(pat),          6)
        self.assertEqual(dn.rfind(pat, -4),      6)
        self.assertEqual(dn.rfind(pat,  6),      6)
        self.assertEqual(dn.rfind(pat,  6,  8),  6)
        self.assertEqual(dn.rfind(pat,  6,  8),  6)
        self.assertEqual(dn.rfind(pat, -8),      6)
        self.assertEqual(dn.rfind(pat, -8, -4),  6)
        self.assertEqual(dn.rfind(pat, -8, -5),  2)

        self.assertEqual(dn.rfind(pat,  7),     -1)
        self.assertEqual(dn.rfind(pat, -3),     -1)

        with self.assertRaises(ValueError):
            self.assertEqual(dn.rindex(pat,  7),     -1)
        with self.assertRaises(ValueError):
            self.assertEqual(dn.rindex(pat, -3),     -1)