def test_alternative_names_ip_bad_domain(self):
        csr = x509_csr.X509Csr()
        ext = x509_ext.X509ExtensionSubjectAltName()
        ext.add_dns_id('test.baddomain.com')
        csr.add_extension(ext)

        with self.assertRaises(validators.ValidationError) as e:
            validators.alternative_names_ip(
                csr=csr,
                allowed_domains=['.test.com'])
        self.assertEqual("Domain 'test.baddomain.com' not allowed (doesn't "
                         "match known domains)", str(e.exception))
Beispiel #2
0
    def test_alternative_names_ip_bad_domain(self):
        csr = x509_csr.X509Csr()
        ext = x509_ext.X509ExtensionSubjectAltName()
        ext.add_dns_id('test.baddomain.com')
        csr.add_extension(ext)

        with self.assertRaises(validators.ValidationError) as e:
            validators.alternative_names_ip(csr=csr,
                                            allowed_domains=['.test.com'])
        self.assertEqual(
            "Domain 'test.baddomain.com' not allowed (doesn't "
            "match known domains)", str(e.exception))
    def test_alternative_names_ip_bad(self):
        csr = x509_csr.X509Csr()
        ext = x509_ext.X509ExtensionSubjectAltName()
        ext.add_ip(netaddr.IPAddress('10.1.1.1'))
        csr.add_extension(ext)

        with self.assertRaises(validators.ValidationError) as e:
            validators.alternative_names_ip(
                csr=csr,
                allowed_domains=['.test.com'],
                allowed_networks=['99/8'])
        self.assertEqual("IP '10.1.1.1' not allowed (doesn't match known "
                         "networks)", str(e.exception))
Beispiel #4
0
    def test_alternative_names_ip_bad(self):
        csr = x509_csr.X509Csr()
        ext = x509_ext.X509ExtensionSubjectAltName()
        ext.add_ip(netaddr.IPAddress('10.1.1.1'))
        csr.add_extension(ext)

        with self.assertRaises(validators.ValidationError) as e:
            validators.alternative_names_ip(csr=csr,
                                            allowed_domains=['.test.com'],
                                            allowed_networks=['99/8'])
        self.assertEqual(
            "IP '10.1.1.1' not allowed (doesn't match known "
            "networks)", str(e.exception))
    def test_alternative_names_ip_ext(self):
        ext_mock = mock.MagicMock()
        ext_mock.get_value.return_value = 'BAD,10.1.1.1'
        ext_mock.get_name.return_value = 'subjectAltName'

        csr_mock = mock.MagicMock()
        csr_mock.get_extensions.return_value = [ext_mock]

        with self.assertRaises(validators.ValidationError) as e:
            validators.alternative_names_ip(
                csr=csr_mock,
                allowed_domains=['.test.com'])
        self.assertEqual("Alt name should have 2 parts, but found: 'BAD'",
                         str(e.exception))
    def test_alternative_names_ip_bad_ext(self):
        ext_mock = mock.MagicMock()
        ext_mock.get_value.return_value = 'BAD:VALUE'
        ext_mock.get_name.return_value = 'subjectAltName'

        csr_mock = mock.MagicMock()
        csr_mock.get_extensions.return_value = [ext_mock]

        with self.assertRaises(validators.ValidationError) as e:
            validators.alternative_names_ip(
                csr=csr_mock,
                allowed_domains=['.test.com'],
                allowed_networks=['99/8'])
        self.assertEqual("Alt name 'VALUE' has unexpected type 'BAD'",
                         str(e.exception))
    def test_alternative_names_ip_bad(self, gethostbyname_ex):
        gethostbyname_ex.return_value = ('master.test.com', [], ['10.0.0.1'])

        ext_mock = mock.MagicMock()
        ext_mock.get_value.return_value = 'IP Address:10.1.1.1'
        ext_mock.get_name.return_value = 'subjectAltName'

        csr_mock = mock.MagicMock()
        csr_mock.get_extensions.return_value = [ext_mock]

        with self.assertRaises(validators.ValidationError) as e:
            validators.alternative_names_ip(
                csr=csr_mock,
                allowed_domains=['.test.com'],
                allowed_networks=['99/8'])
        self.assertEqual("Domain '10.1.1.1' not allowed (doesn't match known "
                         "domains or networks)", str(e.exception))
Beispiel #8
0
    def test_alternative_names_ip_good(self):
        csr = x509_csr.X509Csr()
        ext = x509_ext.X509ExtensionSubjectAltName()
        ext.add_ip(netaddr.IPAddress('10.1.1.1'))
        csr.add_extension(ext)

        self.assertEqual(
            None,
            validators.alternative_names_ip(csr=csr,
                                            allowed_domains=['.test.com'],
                                            allowed_networks=['10/8']))
    def test_alternative_names_ip_good(self):
        csr = x509_csr.X509Csr()
        ext = x509_ext.X509ExtensionSubjectAltName()
        ext.add_ip(netaddr.IPAddress('10.1.1.1'))
        csr.add_extension(ext)

        self.assertEqual(
            None,
            validators.alternative_names_ip(
                csr=csr,
                allowed_domains=['.test.com'],
                allowed_networks=['10/8']
            )
        )
    def test_alternative_names_ip_good(self, gethostbyname_ex):
        gethostbyname_ex.return_value = ('master.test.com', [], ['10.0.0.1'])

        ext_mock = mock.MagicMock()
        ext_mock.get_value.return_value = 'IP Address:10.1.1.1'
        ext_mock.get_name.return_value = 'subjectAltName'

        csr_mock = mock.MagicMock()
        csr_mock.get_extensions.return_value = [ext_mock]

        self.assertEqual(
            None,
            validators.alternative_names_ip(
                csr=csr_mock,
                allowed_domains=['.test.com'],
                allowed_networks=['10/8']
            )
        )