Ejemplo n.º 1
0
    def test_common_name_no_CN(self):
        csr = x509_csr.X509Csr()

        with self.assertRaises(errors.ValidationError) as e:
            custom.common_name(csr=csr,
                               allowed_domains=[],
                               allowed_networks=[])
        self.assertEqual(
            "Alt subjects have to exist if the main subject"
            " doesn't", str(e.exception))
Ejemplo n.º 2
0
    def test_common_name_no_CN(self):
        csr = x509_csr.X509Csr()

        with self.assertRaises(errors.ValidationError) as e:
            custom.common_name(
                csr=csr,
                allowed_domains=[],
                allowed_networks=[])
        self.assertEqual("Alt subjects have to exist if the main subject"
                         " doesn't", str(e.exception))
Ejemplo n.º 3
0
    def test_common_name_bad_CN(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, 'bad.example.org')

        with self.assertRaises(errors.ValidationError) as e:
            custom.common_name(csr=csr, allowed_domains=['.example.com'])
        self.assertEqual(
            "Domain 'bad.example.org' not allowed (does not "
            "match known domains)", str(e.exception))
Ejemplo n.º 4
0
    def test_common_name_bad_CN(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, 'bad.example.org')

        with self.assertRaises(errors.ValidationError) as e:
            custom.common_name(
                csr=csr,
                allowed_domains=['.example.com'])
        self.assertEqual("Domain 'bad.example.org' not allowed (does not "
                         "match known domains)", str(e.exception))
Ejemplo n.º 5
0
    def test_common_name_with_two_CN(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, "dummy_value")
        name.add_name_entry(x509_name.OID_commonName, "dummy_value")

        with self.assertRaises(errors.ValidationError) as e:
            custom.common_name(csr=csr,
                               allowed_domains=[],
                               allowed_networks=[])
        self.assertEqual("Too many CNs in the request", str(e.exception))
Ejemplo n.º 6
0
    def test_common_name_with_two_CN(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, "dummy_value")
        name.add_name_entry(x509_name.OID_commonName, "dummy_value")

        with self.assertRaises(errors.ValidationError) as e:
            custom.common_name(
                csr=csr,
                allowed_domains=[],
                allowed_networks=[])
        self.assertEqual("Too many CNs in the request", str(e.exception))
Ejemplo n.º 7
0
    def test_common_name_ip_bad(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, '15.1.1.1')

        with self.assertRaises(errors.ValidationError) as e:
            custom.common_name(
                csr=csr,
                allowed_domains=['.example.com'],
                allowed_networks=['10/8'])
        self.assertEqual("Address '15.1.1.1' not allowed (does not "
                         "match known networks)", str(e.exception))
Ejemplo n.º 8
0
    def test_common_name_ip_bad(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, '15.1.1.1')

        with self.assertRaises(errors.ValidationError) as e:
            custom.common_name(csr=csr,
                               allowed_domains=['.example.com'],
                               allowed_networks=['10/8'])
        self.assertEqual(
            "Address '15.1.1.1' not allowed (does not "
            "match known networks)", str(e.exception))
Ejemplo n.º 9
0
    def test_common_name_ip_good(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, '10.1.1.1')

        self.assertEqual(
            None,
            custom.common_name(csr=csr,
                               allowed_domains=['.example.com'],
                               allowed_networks=['10/8']))
Ejemplo n.º 10
0
    def test_common_name_good_CN(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, "good.example.com")

        self.assertEqual(
            None,
            custom.common_name(
                csr=csr,
                allowed_domains=['.example.com'],
            ))
Ejemplo n.º 11
0
    def test_common_name_good_CN(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, "good.example.com")

        self.assertEqual(
            None,
            custom.common_name(
                csr=csr,
                allowed_domains=['.example.com'],
            )
        )
Ejemplo n.º 12
0
    def test_common_name_ip_good(self):
        csr = x509_csr.X509Csr()
        name = csr.get_subject()
        name.add_name_entry(x509_name.OID_commonName, '10.1.1.1')

        self.assertEqual(
            None,
            custom.common_name(
                csr=csr,
                allowed_domains=['.example.com'],
                allowed_networks=['10/8']
            )
        )