예제 #1
0
def test_anonymiation_salt(app):
    """Test anonymization salt for different days."""
    event = anonymize_user({
        'ip_address': '131.169.180.47',
        'user_id': '100',
        'timestamp': datetime(2018, 1, 1, 12).isoformat(),
    })
    event_same_day = anonymize_user({
        'ip_address':
        '131.169.180.47',
        'user_id':
        '100',
        'timestamp':
        datetime(2018, 1, 1, 21).isoformat(),
    })
    event_other_day = anonymize_user({
        'ip_address':
        '131.169.180.47',
        'user_id':
        '100',
        'timestamp':
        datetime(2018, 1, 2, 12).isoformat(),
    })

    # Same user, same day -> identical visitor id
    assert event['visitor_id'] == event_same_day['visitor_id']
    # Same user, same day, different hour -> different unique session id
    assert event['unique_session_id'] != event_same_day['unique_session_id']
    # Same user, different day -> different visitor id
    assert event['visitor_id'] != event_other_day['visitor_id']
    # Same user, different day and hour -> different unique session id
    assert event['unique_session_id'] != event_other_day['unique_session_id']
예제 #2
0
def test_anonymise_user(app, mock_user_ctx, request_headers, objects):
    """Test anonymize_user preprocessor."""
    with app.test_request_context(headers=request_headers['user']):
        event = file_download_event_builder({}, app, objects[0])
    event = anonymize_user(event)
    assert 'user_id' not in event
    assert 'user_agent' not in event
    assert 'ip_address' not in event
    assert event['visitor_id'] == \
        '78d8045d684abd2eece923758f3cd781489df3a48e1278982466017f'
예제 #3
0
def test_anonymise_user(app, mock_user_ctx, request_headers, objects):
    """Test anonymize_user preprocessor."""
    with app.test_request_context(headers=request_headers['user']):
        event = file_download_event_builder({}, app, objects[0])
    event = anonymize_user(event)
    assert 'user_id' not in event
    assert 'user_agent' not in event
    assert 'ip_address' not in event
    assert event['visitor_id'] == \
        '78d8045d684abd2eece923758f3cd781489df3a48e1278982466017f'
예제 #4
0
def test_anonymize_user(mock_anonymization_salt, ip_addess, user_id,
                        session_id, user_agent, timestamp, exp_country,
                        exp_visitor_id, exp_unique_session_id):
    """Test anonymize_user preprocessor."""
    event = anonymize_user({
        'ip_address': ip_addess,
        'user_id': user_id,
        'session_id': session_id,
        'user_agent': user_agent,
        'timestamp': timestamp.isoformat(),
    })
    assert 'user_id' not in event
    assert 'user_agent' not in event
    assert 'ip_address' not in event
    assert 'session_id' not in event
    assert event['country'] == exp_country
    assert event['visitor_id'] == exp_visitor_id
    assert event['unique_session_id'] == exp_unique_session_id