Ejemplo n.º 1
0
def test_tracker_with_no_referer_gives_no_cookie(setup):
    request = {"path": "/tracker.gif", "headers": {}}
    response = lambda_handler(request, None)

    assert 'statusCode' in response
    assert response['statusCode'] == 200
    assert 'Content-Type' in response['headers']
    assert response['headers']['Content-Type'] == 'image/gif'
    assert response['isBase64Encoded'] == True
    assert 'body' in response
    assert 'set-cookie' not in response['headers']
Ejemplo n.º 2
0
def test_report(setup):
    """Verify that we can get a report"""

    request = {"path": "/report", "queryStringParameters": {}}

    response = lambda_handler(request, None)

    assert 'statusCode' in response
    assert response['statusCode'] == 200
    assert 'Content-Type' in response['headers']
    assert response['headers']['Content-Type'] == 'application/json'
    assert 'body' in response
    data = json.loads(response['body'])
    assert len(data) == 1
Ejemplo n.º 3
0
def test_tracker_with_bad_cookie_returns_new_cookie(setup):
    request = {
        "path": "/tracker.gif",
        "headers": {
            "referer": "http://localhost/random_url",
            "cookie": "xxx=foobar"
        }
    }
    response = lambda_handler(request, None)

    assert 'statusCode' in response
    assert response['statusCode'] == 200
    assert 'Content-Type' in response['headers']
    assert response['headers']['Content-Type'] == 'image/gif'
    assert response['isBase64Encoded'] == True
    assert 'body' in response
    assert 'set-cookie' in response['headers']
    assert response['headers']['set-cookie'] != 'userid=foobar'
Ejemplo n.º 4
0
def test_log_with_to_parameter(setup):
    """Verify that we can get a log to specific datetime"""

    request = {
        "path": "/log",
        "queryStringParameters": {
            "to": quote(formatted_timestamp(datetime.now()))
        }
    }

    response = lambda_handler(request, None)

    assert 'statusCode' in response
    assert response['statusCode'] == 200
    assert 'Content-Type' in response['headers']
    assert response['headers']['Content-Type'] == 'application/json'
    assert 'body' in response
    data = json.loads(response['body'])
    assert len(data) == 3
Ejemplo n.º 5
0
def test_bad_path_gives_404(setup):
    request = {"path": "/random-path", "headers": {}}
    response = lambda_handler(request, None)

    assert 'statusCode' in response
    assert response['statusCode'] == 404