Exemplo n.º 1
0
def test_process_throws_on_invalid_date(mock_audit_client, mock_utils):
    args = MockArgs(startDate='201ask',
                    limit=False,
                    endDate='adlk2',
                    csv=None,
                    json=None,
                    sysloghost=None,
                    syslogport=None,
                    useCursor=True)
    with pytest.raises(iso8601.ParseError):
        cli.process(args, mock_audit_client, mock_utils)
Exemplo n.º 2
0
def test_process_with_no_new_records_to_save(mock_utiles_checkrecords,
                                             mock_audit_client):
    args = MockArgs(startDate='2017',
                    endDate='2018',
                    csv=None,
                    json=None,
                    sysloghost=None,
                    syslogport=None,
                    useCursor=False,
                    limit=100)
    cli.process(args, mock_audit_client, mock_utiles_checkrecords)
    mock_utiles_checkrecords.saveNextPageCursor.assert_not_called()
    assert mock_audit_client.fetchRecords.call_count == 1
Exemplo n.º 3
0
def test_process_with_cursor(mock_audit_client, mock_utils):
    mock_utils.getnextPageCursor.return_value = CURSOR
    args = MockArgs(startDate='2017',
                    limit=200,
                    endDate='2018',
                    csv=None,
                    json=None,
                    sysloghost=None,
                    syslogport=None,
                    useCursor=True)
    cli.process(args, mock_audit_client, mock_utils)
    mock_audit_client.fetchRecords.assert_called_with({
        'method': 'GET',
        'query': {
            'start': '2017',
            'end': '2018',
            'sort': 'timestamp:asc',
            'cursor': CURSOR['nextPageCursor'],
            'limit': 200
        }
    })
Exemplo n.º 4
0
def test_process_with_next_pagesStartkey(mock_audit_client, mock_utils,
                                         mock_response):
    mock_audit_client.fetchRecords.return_value = None
    SOME_NEXT_PAGE_KEY = 'some-start-key'
    EXPECTED_CALLS = [
        call({
            'method': 'GET',
            'query': {
                'start': '2017',
                'end': '2018'
            }
        }),
        call({
            'method': 'GET',
            'query': {
                'start': '2017',
                'end': '2018',
                'cursor': SOME_NEXT_PAGE_KEY
            }
        })
    ]
    mock_response_2 = mock_response
    mock_response_1 = copy.deepcopy(mock_response)
    mock_response_1['cursor']['after'] = SOME_NEXT_PAGE_KEY
    mock_audit_client.fetchRecords.side_effect = [
        mock_response_1, mock_response_2
    ]

    args = MockArgs(startDate='2017',
                    limit=100,
                    endDate='2018',
                    csv=None,
                    json=None,
                    sysloghost=None,
                    syslogport=None,
                    useCursor=False)
    cli.process(args, mock_audit_client, mock_utils)
    assert mock_audit_client.fetchRecords.call_count == 2
    assert mock_utils.saveNextPageCursor.call_count == 0
Exemplo n.º 5
0
def test_process_succeeds_with_options(mock_utils, mock_audit_client,
                                       mock_response):
    args = MockArgs(startDate='2017',
                    limit=150,
                    endDate='2018',
                    csv='some-csv',
                    json='some-json',
                    sysloghost='some-syslog',
                    syslogport='514',
                    useCursor='some-bmk')
    cli.process(args, mock_audit_client, mock_utils)
    mock_utils.checkRecords.assert_called_with([{
        'recordId': 'some-record-id'
    }], 'some-record-id')
    mock_utils.getnextPageCursor.assert_called_with()
    mock_utils.saveNextPageCursor.assert_called_with(CURSOR['nextPageCursor'],
                                                     SOME_RECORD_ID_1)
    mock_utils.exportToJson.assert_called_with('some-json',
                                               mock_response['data'])
    mock_utils.exportToCsv.assert_called_with('some-csv',
                                              mock_response['data'], {})
    mock_utils.exportToSysLog.assert_called_with(
        'some-syslog', '514', mock_utils.configSysLogger('some-syslog', '514'),
        mock_response['data'])
Exemplo n.º 6
0
def test_process_succeeds_no_options(mock_utils, mock_audit_client):
    args = MockArgs(startDate='2017',
                    endDate='2018',
                    csv=None,
                    json=None,
                    sysloghost=None,
                    syslogport=None,
                    useCursor=False,
                    limit=100)
    cli.process(args, mock_audit_client, mock_utils)
    mock_utils.getnextPageCursor.assert_called_with()
    mock_utils.saveNextPageCursor.assert_not_called()
    mock_utils.exportToJson.assert_not_called()
    mock_utils.exportToCsv.assert_not_called()
    mock_utils.exportToSysLog.assert_not_called()
    mock_audit_client.fetchRecords.assert_called_with({
        'method': 'GET',
        'query': {
            'start': '2017',
            'end': '2018',
            'limit': 100,
            'sort': 'timestamp:asc'
        }
    })