Exemplo n.º 1
0
 def test_if_protected(self, mock_get_cert):
     cert = certificate.create_from_file(
         demo_data.demo_entitlement_cert_path)
     cert.check_path = mock.Mock(return_value=True)
     mock_get_cert.return_value = cert
     result = mock_name_func('protected')
     self.assertEquals(result, 'foo')
Exemplo n.º 2
0
    def test_not_authorized(self, mock_get_cert):
        cert = certificate.create_from_file(demo_data.demo_entitlement_cert_path)
        mock_get_cert.return_value = cert

        with self.assertRaises(exceptions.HTTPError) as assertion:
            mock_image_func('qux123')
        self.assertEquals(assertion.exception.status_code, httplib.NOT_FOUND)
Exemplo n.º 3
0
 def test_auth_fails_if_no_path_matches_credentials(self, mock_get_cert):
     cert = certificate.create_from_file(
         demo_data.demo_entitlement_cert_path)
     mock_get_cert.return_value = cert
     with self.assertRaises(exceptions.HTTPError) as assertion:
         mock_repo_func('qux')
     self.assertEqual(assertion.exception.status_code, httplib.NOT_FOUND)
Exemplo n.º 4
0
 def test_raises_not_found_if_id_invalid(self, mock_get_cert):
     cert = certificate.create_from_file(
         demo_data.demo_entitlement_cert_path)
     mock_get_cert.return_value = cert
     with self.assertRaises(exceptions.HTTPError) as assertion:
         mock_name_func('qux')
     self.assertEqual(assertion.exception.status_code, httplib.NOT_FOUND)
Exemplo n.º 5
0
    def test_passes_if_auth_valid(self, mock_get_cert):
        cert = certificate.create_from_file(
            demo_data.demo_entitlement_cert_path)
        mock_get_cert.return_value = cert

        result = mock_name_func('v2/bar')
        self.assertEquals(result, 'foo')
Exemplo n.º 6
0
    def test_not_authorized(self, mock_get_cert):
        cert = certificate.create_from_file(demo_data.demo_entitlement_cert_path)
        mock_get_cert.return_value = cert

        with self.assertRaises(exceptions.HTTPError) as assertion:
            mock_image_func('qux123')
        self.assertEquals(assertion.exception.status_code, httplib.NOT_FOUND)
Exemplo n.º 7
0
 def uuid(self):
     """ Read consumer certificate and get consumer UUID from it. """
     if not self.cert_uuid:
         try:
             certificate = rhsm_certificate.create_from_file(self.cert_file)
             self.cert_uuid = certificate.subject["CN"]
         except Exception, e:
             raise SubscriptionManagerError("Unable to open certificate %s (%s):" % (self.cert_file, str(e)))
Exemplo n.º 8
0
 def _create_cert(self):
     cert_file = self._get_file_from_args()
     try:
         return certificate.create_from_file(cert_file)
     except certificate.CertificateException as ce:
         raise InvalidCLIOptionError(
             _("Unable to read certificate file '{certificate}': {exception}"
               ).format(certificate=cert_file, exception=ce))
Exemplo n.º 9
0
 def _create_cert(self):
     cert_file = self._get_file_from_args()
     try:
         return certificate.create_from_file(cert_file)
     except certificate.CertificateException as ce:
         raise InvalidCLIOptionError(
             _("Unable to read certificate file '%s': %s") %
             (cert_file, ce))
Exemplo n.º 10
0
 def uuid(self):
     """ Read consumer certificate and get consumer UUID from it. """
     if not self.cert_uuid:
         try:
             certificate = rhsm_certificate.create_from_file(self.cert_file)
             self.cert_uuid = certificate.subject["CN"]
         except Exception, e:
             raise SubscriptionManagerError("Unable to open certificate %s (%s):" % (self.cert_file, str(e)))
 def _create_cert(self):
     cert_file = self._get_file_from_args()
     try:
         return certificate.create_from_file(cert_file)
     except certificate.CertificateException, ce:
         raise InvalidCLIOptionError(
                 _("Unable to read certificate file '%s': %s") % (cert_file,
                     ce))
 def list(self):
     if self._listing is not None:
         return self._listing
     listing = []
     for p, fn in Directory.list(self):
         if not fn.endswith('.pem') or fn.endswith(self.KEY):
             continue
         path = self.abspath(fn)
         listing.append(create_from_file(path))
     self._listing = listing
     return listing
Exemplo n.º 13
0
 def list(self):
     if self._listing is not None:
         return self._listing
     listing = []
     for _p, fn in Directory.list(self):
         if not fn.endswith('.pem') or fn.endswith(self.KEY):
             continue
         path = self.abspath(fn)
         listing.append(create_from_file(path))
     self._listing = listing
     return listing
Exemplo n.º 14
0
 def test_auth_fails_if_no_path_matches_credentials(self, mock_get_cert):
     cert = certificate.create_from_file(demo_data.demo_entitlement_cert_path)
     mock_get_cert.return_value = cert
     with self.assertRaises(exceptions.HTTPError) as assertion:
         mock_repo_func('qux')
     self.assertEqual(assertion.exception.status_code, httplib.NOT_FOUND)
Exemplo n.º 15
0
 def test_if_protected(self, mock_get_cert):
     cert = certificate.create_from_file(demo_data.demo_entitlement_cert_path)
     cert.check_path = mock.Mock(return_value=True)
     mock_get_cert.return_value = cert
     result = mock_name_func('protected')
     self.assertEquals(result, 'foo')
Exemplo n.º 16
0
 def _create_cert(self):
     return certificate.create_from_file(self._get_file_from_args())
Exemplo n.º 17
0
 def test_non_existent_file(self):
     with self.assertRaises(CertificateException):
         create_from_file("/foo/non_existent_cert.pem")
Exemplo n.º 18
0
 def _create_cert(self):
     return certificate.create_from_file(self._get_file_from_args())
Exemplo n.º 19
0
 def test_passes_if_auth_valid(self, mock_get_cert):
     cert = certificate.create_from_file(demo_data.demo_entitlement_cert_path)
     mock_get_cert.return_value = cert
     result = mock_repo_func('baz')
     self.assertEquals(result, 'foo')
Exemplo n.º 20
0
 def test_bypass_if_not_protected(self, mock_get_cert):
     cert = certificate.create_from_file(demo_data.demo_entitlement_cert_path)
     mock_get_cert.return_value = cert
     result = mock_repo_func('redhat/foo')
     self.assertEquals(result, 'foo')
Exemplo n.º 21
0
 def read(cls):
     return create_from_file(cls.PATH)
Exemplo n.º 22
0
 def test_raises_not_found_if_id_invalid(self, mock_get_cert):
     cert = certificate.create_from_file(demo_data.demo_entitlement_cert_path)
     mock_get_cert.return_value = cert
     with self.assertRaises(exceptions.HTTPError) as assertion:
         mock_name_func('qux')
     self.assertEqual(assertion.exception.status_code, httplib.NOT_FOUND)
Exemplo n.º 23
0
 def test_bypass_if_not_protected(self, mock_get_cert):
     cert = certificate.create_from_file(
         demo_data.demo_entitlement_cert_path)
     mock_get_cert.return_value = cert
     result = mock_repo_func('redhat/foo')
     self.assertEquals(result, 'foo')