예제 #1
0
def test_first_fetch_start_time():
    from AzureADIdentityProtection import get_last_fetch_time
    last_run = {}
    params = {"first_fetch": "2 days"}
    expected_datetime = datetime.now() - timedelta(days=2)

    last_fetch, last_fetch_datetime = get_last_fetch_time(last_run, params)

    assert expected_datetime - timedelta(
        minutes=1) < last_fetch_datetime < expected_datetime + timedelta(
            minutes=1)
def test_first_fetch_start_time():
    from AzureADIdentityProtection import get_last_fetch_time
    last_run = {}
    params = {"first_fetch": "2 days"}
    expected_datetime = datetime.now() - timedelta(days=2)

    last_fetch = get_last_fetch_time(last_run, params)
    last_fetch_datetime = datetime.strptime(last_fetch.removesuffix('Z'),
                                            DATE_FORMAT)

    assert expected_datetime - timedelta(
        minutes=1) < last_fetch_datetime < expected_datetime + timedelta(
            minutes=1)
def test_fetch_new_incidents(mocker):
    """
        Given
            fetch incidents command running for the first time.
        When
            mock the Client's http_request.
        Then
            validate fetch incidents command using the Client gets all relevant incidents
    """
    from AzureADIdentityProtection import detections_to_incidents, get_last_fetch_time
    test_incidents = util_load_json('test_data/incidents.json')
    last_run = {'latest_detection_found': '2021-07-20T11:02:54Z'}
    last_fetch = get_last_fetch_time(last_run, {})
    incidents, last_item_time = detections_to_incidents(
        test_incidents.get('value', []), last_fetch)
    assert len(incidents) == 10
    assert incidents[0].get(
        'name') == 'Azure AD: 17 newCountry adminDismissedAllRiskForUser'
    assert last_item_time == '2021-07-20T11:02:54Z'
def test_non_first_fetch_start_time():
    from AzureADIdentityProtection import get_last_fetch_time
    last_run = {"latest_detection_found": '2021-07-28T00:10:00.000Z'}
    params = {"first_fetch": "2 days"}
    last_fetch = get_last_fetch_time(last_run, params)
    assert last_fetch == '2021-07-28T00:10:00.000Z'