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')
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)
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)
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)
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')
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 as ce: raise InvalidCLIOptionError( _("Unable to read certificate file '{certificate}': {exception}" ).format(certificate=cert_file, exception=ce))
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))
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
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
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)
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')
def _create_cert(self): return certificate.create_from_file(self._get_file_from_args())
def test_non_existent_file(self): with self.assertRaises(CertificateException): create_from_file("/foo/non_existent_cert.pem")
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')
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')
def read(cls): return create_from_file(cls.PATH)
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)
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')