def test_invalid_password_for_command(mocker, args): """" Given: - Cortex XSOAR params, having additional_password parameter fulfilled. - Cortex XSOAR arguments. When: - Executing a command. Cases: Case a: No additional_password was given in the arguments. Case a: Incorrect additional_password was given in the arguments. Then: - Ensure DemistoException is thrown with the expected error message. """ from RemoteAccessv2 import main mocker.patch.object( demisto, 'params', return_value={'additional_password': { 'password': '******' }}) mocker.patch.object(demisto, 'args', return_value=args) with pytest.raises( DemistoException, match='Additional password to use the module have been supplied.\n' 'Please supply "additional_password" argument that matches ' 'the "Additional Password" parameter value.'): main()
def test_copy_from_command_valid(mocker, file_name, expected_file_name): """ Given: - Cortex XSOAR arguments When: - Calling the copy-to command. Case a: Calling the command without specified file name. Case b: Calling the command with specified file name. Then: - Ensure expected fileResult object is returned. """ from RemoteAccessv2 import main from paramiko import SSHClient import RemoteAccessv2 mock_client: SSHClient = SSHClient() mocker_results = mocker.patch.object(RemoteAccessv2, 'fileResult') mocker.patch.object(demisto, 'command', return_value='copy-from') mocker.patch.object(RemoteAccessv2, 'create_paramiko_ssh_client', return_value=mock_client) mocker.patch.object(RemoteAccessv2, 'return_results') args = {'file_path': 'mock_path.txt'} if file_name: args['file_name'] = file_name mocker.patch.object(demisto, 'args', return_value=args) mocker.patch('RemoteAccessv2.perform_copy_command', return_value='RemoteFileData') main() assert mocker_results.call_args[0][0] == expected_file_name assert mocker_results.call_args[0][1] == 'RemoteFileData'
def test_failed_authentication(mocker): """ Given: - Cortex XSOAR arguments. - Cortex XSOAR command for Remote Access integration. When: - No credentials are given. Then: - Ensure error is returned. """ from RemoteAccessv2 import main import RemoteAccessv2 mocker.patch.object(RemoteAccessv2, 'return_error') mocker.patch.object(demisto, 'error') main() assert RemoteAccessv2.return_error.called