Add session pinning by country (#3233)

This commit is contained in:
Raphael Michel
2023-04-18 12:29:07 +02:00
committed by GitHub
parent 7b1fa90d70
commit ff86fcf000
2 changed files with 48 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ from django_otp.oath import TOTP
from django_otp.plugins.otp_totp.models import TOTPDevice
from pretix.base.models import U2FDevice, User
from pretix.helpers import security
class LoginFormTest(TestCase):
@@ -797,6 +798,25 @@ class SessionTimeOutTest(TestCase):
response = self.client.get('/control/')
self.assertEqual(response.status_code, 302)
@override_settings(HAS_GEOIP=True)
def test_pinned_country(self):
class FakeGeoIp:
def country(self, ip):
if ip == '1.2.3.4':
return {'country_code': 'DE'}
return {'country_code': 'US'}
security._geoip = FakeGeoIp()
self.client.defaults['REMOTE_ADDR'] = '1.2.3.4'
response = self.client.get('/control/')
self.assertEqual(response.status_code, 200)
self.client.defaults['REMOTE_ADDR'] = '4.3.2.1'
response = self.client.get('/control/')
self.assertEqual(response.status_code, 302)
security._geoip = None
@pytest.fixture
def user():