Beispiel #1
0
def test_upload_script_failure_already_exists(requests_mock, mocker):
    from CrowdStrikeFalcon import upload_script_command
    response = {
        "meta": {
            "query_time": 0.01543348,
            "powered_by": "empower",
            "trace_id": "07kk11c3-496g-42df-9157-834e499e279d"
        },
        "errors": [{
            "code": 409,
            "message": "file with given name already exists"
        }]
    }
    requests_mock.post(f'{SERVER_URL}/real-time-response/entities/scripts/v1',
                       json=response,
                       status_code=409,
                       reason='Conflict')
    mocker.patch.object(demisto,
                        'args',
                        return_value={
                            'name': 'iloveny',
                            'content': "Write-Output 'Hello, World!'"
                        })
    return_error_mock = mocker.patch(RETURN_ERROR_TARGET)
    upload_script_command()
    assert return_error_mock.call_count == 1
    err_msg = return_error_mock.call_args[0][0]
    assert err_msg == 'Error in API call to CrowdStrike Falcon: code: 409 - ' \
                      'reason: Conflict\nfile with given name already exists'
Beispiel #2
0
def test_upload_script_given_file(requests_mock, mocker):
    from CrowdStrikeFalcon import upload_script_command
    response = {
        "meta": {
            "query_time": 0.782968846,
            "writes": {
                "resources_affected": 1
            },
            "powered_by": "empower",
            "trace_id": "07kk11c3-496g-42df-9157-834e499e279d"
        }
    }
    requests_mock.post(f'{SERVER_URL}/real-time-response/entities/scripts/v1',
                       json=response,
                       status_code=200)
    mocker.patch.object(demisto,
                        'args',
                        return_value={
                            'name': 'iloveny',
                            'entry_id': '23@32'
                        })
    mocker.patch.object(demisto,
                        'getFilePath',
                        return_value={
                            'path': 'test_data/HelloWorld.ps1',
                            'name': 'HelloWorld.ps1'
                        })
    mocker.patch.object(demisto, 'results')
    results = upload_script_command()
    assert results['HumanReadable'] == 'The script was uploaded successfully'
    assert results['Contents'] == response
Beispiel #3
0
def test_upload_script_failure_bad_inputs(requests_mock, mocker):
    from CrowdStrikeFalcon import upload_script_command

    # test failure given both content and entry_id arguments
    mocker.patch.object(demisto,
                        'args',
                        return_value={
                            'name': 'iloveny',
                            'content': "Write-Output 'Hello, World!'",
                            'entry_id': '23@32'
                        })
    with pytest.raises(ValueError) as e:
        upload_script_command()
    assert str(
        e.value
    ) == 'Only one of the arguments entry_id or content should be provided, not both.'

    # test failure none of the arguments content and entry_id given
    mocker.patch.object(demisto, 'args', return_value={'name': 'iloveny'})
    with pytest.raises(ValueError) as e:
        upload_script_command()
    assert str(
        e.value
    ) == 'One of the arguments entry_id or content must be provided, none given.'