summaryrefslogtreecommitdiffstats
path: root/tests_multitenant/test_xforwardedfor.py
blob: 8c841d28085a4ef1d56f90680a7adfcea604c2a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from django.db import connection


def test_xforwardedfor(settings, tenants, client):
    settings.USE_X_FORWARDED_FOR = True
    for tenant in tenants:
        settings.ALLOWED_HOSTS.append(tenant.domain_url)
        response = client.get('/', SERVER_NAME=tenant.domain_url,
                           HTTP_X_FORWARDED_FOR='99.99.99.99, 127.0.0.1')
        assert '99.99.99.99' in response.content
    connection.set_schema_to_public()
    settings.USE_X_FORWARDED_FOR = False
    for tenant in tenants:
        response = client.get('/', SERVER_NAME=tenant.domain_url,
                           HTTP_X_FORWARDED_FOR='99.99.99.99, 127.0.0.1')
        assert not '99.99.99.99' in response.content