Ejemplo n.º 1
0
 def test_process_s3admin_request_success(self, get_client_mock):
     """ Ensure process the request bundle request based on the command
     """
     get_client_mock.return_value = mock.MagicMock(), "Fake_response"
     request_mock = mock.MagicMock()
     command_args = {
         'command': 'access_key',
         'action': 'create',
         'user_name': 'test',
         'access_key': 'TgVCZxb7TY2wG-ySXVIR1w',
         'secret_key': 'Ihcg/nOEMAVuTB8MQZuUdwDaoAkGdkMhl+AFcd+B'
     }
     request_mock.selection_args = command_args
     s3access_key_provider = S3AccessKeyProvider("access_key",
                                                 "handling access_key")
     s3access_key_provider.execute_command = mock.MagicMock()
     with mock.patch('{}.{}.{}'.format(
             "sspl_hl.utils", "message_utils",
             "S3CommandResponse.get_response_message")) \
             as response_mock:
         s3access_key_provider.process_s3auth_request(request_mock)
         self.assertEqual(response_mock.call_count, 0)
         self.assertEqual(request_mock.reply.call_count, 0)
         self.assertEqual(s3access_key_provider.execute_command.call_count,
                          1)
Ejemplo n.º 2
0
 def handle_access_key_command(self, request):
     """
     Handles all access_key related operations.
     """
     self._child_provider = S3AccessKeyProvider("access_key",
                                                "handling access keys")
     self._child_provider.handleRequest(request)
Ejemplo n.º 3
0
 def test_render_query(self):
     """ Ensure request from handleRequest function is received
     and processed further.
     """
     request_mock = mock.MagicMock()
     command_args = {
         'command': 'access_key',
         'action': 'create',
         'user_name': 'test',
         'access_key': 'TgVCZxb7TY2wG-ySXVIR1w',
         'secret_key': 'Ihcg/nOEMAVuTB8MQZuUdwDaoAkGdkMhl+AFcd+B'
     }
     request_mock.selection_args = command_args
     access_key_provider = S3AccessKeyProvider("access_key",
                                               "handling access_key")
     action = request_mock.selection_args.get('action', None)
     self.assertEqual(action, 'create')
     access_key_provider.process_s3auth_request = mock.MagicMock()
     with mock.patch('{}.{}.{}'.format("sspl_hl.utils",
                                       "base_castor_provider",
                                       "BaseCastorProvider.render_query"),
                     return_value=True):
         access_key_provider.render_query(request_mock)
         access_key_provider.process_s3auth_request.assert_called_once_with(
             request_mock)
Ejemplo n.º 4
0
 def test_execute_command_success(self):
     """Ensure execution of thread based on s3access_key operation
     request from client.
     """
     request_mock = mock.MagicMock()
     command_args = {
         'command': 'access_key',
         'action': 'remove',
         'user_name': 'test',
         'user_access_key': 'eGdkxW3QScC5ZU4EUnTRkg',
         'access_key': 'TgVCZxb7TY2wG-ySXVIR1w',
         'secret_key': 'Ihcg/nOEMAVuTB8MQZuUdwDaoAkGdkMhl+AFcd+B'
     }
     request_mock.selection_args = command_args
     s3access_key_provider = S3AccessKeyProvider("access_key",
                                                 "handling access_key")
     s3access_key_provider._handle_success = mock.MagicMock()
     with mock.patch(
             "sspl_hl.providers.s3_access_key.provider.deferToThread",
             return_value=defer.succeed(
                 SsplHlProviderS3AccessKey_list.access_key_list_response)):
         with mock.patch('{}.{}.{}'.format("sspl_hl.utils.s3admin",
                                           "access_key_handler",
                                           "AccessKeyUtility.remove")) \
                 as access_key_remove_handler_mock:
             s3access_key_provider.execute_command(request_mock)
             action = request_mock.selection_args.get('action', None)
             self.assertEqual(action, 'remove')
             s3access_key_provider._handle_success.assert_called_once_with(
                 SsplHlProviderS3AccessKey_list.access_key_list_response,
                 request_mock)
Ejemplo n.º 5
0
 def test_execute_command_failure(self):
     """Handle failure while execution of thread based on s3access_key
     operation request from client.
     """
     request_mock = mock.MagicMock()
     command_args = {
         'command': 'access_key',
         'action': 'create',
         'user_name': 'test',
         'access_key': 'TgVCZxb7TY2wG-ySXVIR1w',
         'secret_key': 'Ihcg/nOEMAVuTB8MQZuUdwDaoAkGdkMhl+AFcd+B'
     }
     request_mock.selection_args = command_args
     s3access_key_provider = S3AccessKeyProvider("access_key",
                                                 "handling access_key")
     s3access_key_provider._handle_failure = mock.MagicMock()
     with mock.patch(
             "sspl_hl.providers.s3_access_key.provider.deferToThread",
             return_value=defer.fail(FakeError('error'))):
         with mock.patch('{}.{}.{}'.format("sspl_hl.utils.s3admin",
                                           "access_key_handler",
                                           "AccessKeyUtility.create")) \
                 as access_key_create_handler_mock:
             s3access_key_provider.execute_command(request_mock)
             action = request_mock.selection_args.get('action', None)
             self.assertEqual(action, 'create')
             self.assertEqual(
                 s3access_key_provider._handle_failure.call_count, 1)
Ejemplo n.º 6
0
 def test_handleRequest(self):
     """ Ensure request from s3admin subcommand is received
     and processed further.
     """
     request_mock = mock.MagicMock()
     s3access_key_provider = S3AccessKeyProvider("access_key",
                                                 "handling access_key")
     s3access_key_provider.render_query = mock.MagicMock()
     s3access_key_provider.handleRequest(request_mock)
     s3access_key_provider.render_query.assert_called_once_with(
         request_mock)
Ejemplo n.º 7
0
 def test_handle_list_success(self):
     """ When access_key list is successful, ensure that further function is
     called to process the recived response from s3 server.
     """
     request_mock = mock.MagicMock()
     s3access_key_provider = S3AccessKeyProvider("access_key",
                                                 "handling access_key")
     with mock.patch('{}.{}.{}'.format(
             "sspl_hl.utils", "message_utils",
             "S3CommandResponse.get_response_message")) \
             as response_mock:
         s3access_key_provider._handle_success(
             self.access_key_list_response, request_mock)
         response_mock.assert_called_once_with(
             self.access_key_list_response)
         self.assertEqual(request_mock.reply.call_count, 1)