Exemplo n.º 1
0
def test_fetch_incidents_for_alert_success(mock_api_token, mock_request,
                                           set_attachment, replace_url,
                                           client):
    """
    When fetch_incidents() method called with fetch_type='Alerts' and pass all required arg it success.
    """
    from FireEyeNX import fetch_incidents

    # Configure
    mock_last_run = {
        'start_time': datetime.now().replace(tzinfo=timezone.utc).timestamp()
    }
    dummy_first_fetch = 1
    mock_fetch_limit = 12
    mock_malware_type = 'malware-type'
    mock_api_token.return_value = API_TOKEN

    with open('TestData/fetch_incidents_alert_response.json', 'r') as f:
        dummy_response = f.read()

    resp = Response()
    resp._content = dummy_response.encode()
    resp.status_code = 200
    resp._ok = True
    resp.headers = {'Content-Type': CONTENT_TYPE_JSON}
    mock_request.return_value = resp

    set_attachment.return_value = None
    replace_url.return_value = None

    # Execute
    next_run, incidents = fetch_incidents(
        client=client,
        malware_type=mock_malware_type,
        last_run=mock_last_run,
        first_fetch=dummy_first_fetch,
        fetch_limit=mock_fetch_limit,
        fetch_type='Alerts',
        mvx_correlated=False,
        replace_alert_url=True,
        instance_url=SAMPLE_URL,
        fetch_artifacts=True,
        is_test=False,
    )

    # Assert
    assert len(incidents) == mock_fetch_limit
    assert next_run.get('start_time') is not None
Exemplo n.º 2
0
 def test_sync_update_existing(self, fake_requests, mock_update, mock_cache,
                               mock_cat, mock_get):
     project_syncer = ProjectSyncer(self.target_url, self.target_key)
     user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
     project_syncer.syncer = user
     res = Response()
     res._ok = False
     res.status_code = 403
     res._content = ""
     mock_get.return_value = create_target()
     mock_update.return_value = res
     project = ProjectFactory.create()
     project_syncer.sync(project)
     project_syncer.get_target.assert_called_once()
     project_syncer.cache_target.assert_called_once()
     project_syncer._sync.assert_called_once()
     mock_cat.assert_called_once()
Exemplo n.º 3
0
def test_set_attachment_file(mock_request, client):
    # incident: dict, uuid: str, headers: dict
    from FireEyeNX import set_attachment_file

    uuid = 'abc'
    headers = {}

    resp = Response()
    resp._ok = True
    resp.status_code = 200
    resp._content = b'a'
    resp.headers = {'Content-Length': '1'}

    mock_request.return_value = resp
    excepted_incident = {}

    set_attachment_file(client, excepted_incident, uuid, headers)
    assert excepted_incident != {}
def create_response(ok=True, status_code=200, content=None):
    res = Response()
    res._ok = ok
    res.status_code = status_code
    res._content = content
    return res