Exemplo n.º 1
0
 def test_get_except(self, mock_get):
     """Test handling of request with ConnectionError."""
     before = REGISTRY.get_sample_value("rbac_connection_errors_total")
     rbac = RbacService()
     url = f"{rbac.protocol}://{rbac.host}:{rbac.port}{rbac.path}"
     with self.assertRaises(RbacConnectionError):
         rbac._request_user_access(url, headers={})  # pylint: disable=protected-access
     after = REGISTRY.get_sample_value("rbac_connection_errors_total")
     self.assertEqual(1, after - before)
     mock_get.assert_called()
Exemplo n.º 2
0
 def test_200_exception(self, mock_get):
     """Test handling of request with 200 response and raises a json error."""
     rbac = RbacService()
     url = f"{rbac.protocol}://{rbac.host}:{rbac.port}{rbac.path}"
     access = rbac._request_user_access(url, headers={})  # pylint: disable=protected-access
     self.assertEqual(access, [])
     mock_get.assert_called()
Exemplo n.º 3
0
 def test_200_results_next(self, mock_get):
     """Test handling of request with 200 response with next link."""
     rbac = RbacService()
     url = f"{rbac.protocol}://{rbac.host}:{rbac.port}{rbac.path}"
     access = rbac._request_user_access(url, headers={})  # pylint: disable=protected-access
     self.assertEqual(access, [LIMITED_AWS_ACCESS, LIMITED_AWS_ACCESS])
     mock_get.assert_called()
Exemplo n.º 4
0
 def test_200_text(self, mock_get):
     """Test handling of request with 200 response and non-json error."""
     rbac = RbacService()
     url = f"{rbac.protocol}://{rbac.host}:{rbac.port}{rbac.path}"
     access = rbac._request_user_access(url, headers={})
     self.assertEqual(access, [])
     mock_get.assert_called()
Exemplo n.º 5
0
 def test_200_all_results(self, mock_get):
     """Test handling of request with 200 response with no next link."""
     rbac = RbacService()
     url = '{}://{}:{}{}'.format(rbac.protocol, rbac.host, rbac.port, rbac.path)
     access = rbac._request_user_access(url, headers={})  # pylint: disable=protected-access
     self.assertEqual(access, [LIMITED_AWS_ACCESS])
     mock_get.assert_called()
Exemplo n.º 6
0
 def test_200_text(self, mock_get):
     """Test handling of request with 200 response and non-json error."""
     rbac = RbacService()
     url = '{}://{}:{}{}'.format(rbac.protocol, rbac.host, rbac.port, rbac.path)
     access = rbac._request_user_access(url, headers={})  # pylint: disable=protected-access
     self.assertEqual(access, [])
     mock_get.assert_called()
Exemplo n.º 7
0
 def test_non_200_error_except(self, mock_get):
     """Test handling of request with non-200 response and non-json error."""
     rbac = RbacService()
     url = f"{rbac.protocol}://{rbac.host}:{rbac.port}{rbac.path}"
     logging.disable(logging.NOTSET)
     with self.assertLogs(logger="koku.rbac", level=logging.WARNING):
         access = rbac._request_user_access(url, headers={})  # pylint: disable=protected-access
     self.assertEqual(access, [])
     mock_get.assert_called()
Exemplo n.º 8
0
 def test_500_error_json(self, mock_get):
     """Test handling of request with 500 response and json error."""
     rbac = RbacService()
     url = f"{rbac.protocol}://{rbac.host}:{rbac.port}{rbac.path}"
     with self.assertRaises(RbacConnectionError):
         rbac._request_user_access(url, headers={})  # pylint: disable=protected-access