mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
added remote user auth test
This commit is contained in:
parent
72ebe7df58
commit
c7abdb61e8
66
src/documents/tests/test_auth.py
Normal file
66
src/documents/tests/test_auth.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.test import override_settings, Client, modify_settings, TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestRemoteUserAuthentication(TestCase):
|
||||||
|
|
||||||
|
def test_no_remote_user_auth(self):
|
||||||
|
client = Client()
|
||||||
|
|
||||||
|
response = client.get("/api/documents/")
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
|
response = client.get("/api/documents/", HTTP_REMOTE_USER="someone")
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
|
response = client.get("/api/documents/", HTTP_X_FORWARDED_USER="someone")
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
|
@modify_settings(
|
||||||
|
MIDDLEWARE={
|
||||||
|
'append': 'paperless.auth.HttpRemoteUserMiddleware'
|
||||||
|
},
|
||||||
|
AUTHENTICATION_BACKENDS={
|
||||||
|
'prepend': 'django.contrib.auth.backends.RemoteUserBackend'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
def test_standard_remote_user_auth(self):
|
||||||
|
client = Client()
|
||||||
|
|
||||||
|
response = client.get("/api/documents/")
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
|
response = client.get("/api/documents/", HTTP_X_FORWARDED_USER="someone")
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
|
self.assertFalse(User.objects.filter(username="someone").exists())
|
||||||
|
|
||||||
|
response = client.get("/api/documents/", HTTP_REMOTE_USER="someone")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
self.assertTrue(User.objects.filter(username="someone").exists())
|
||||||
|
|
||||||
|
@modify_settings(
|
||||||
|
MIDDLEWARE={
|
||||||
|
'append': 'paperless.auth.HttpRemoteUserMiddleware'
|
||||||
|
},
|
||||||
|
AUTHENTICATION_BACKENDS={
|
||||||
|
'prepend': 'django.contrib.auth.backends.RemoteUserBackend'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@override_settings(HTTP_REMOTE_USER_HEADER_NAME="HTTP_X_FORWARDED_USER")
|
||||||
|
def test_custom_remote_user_auth(self):
|
||||||
|
client = Client()
|
||||||
|
|
||||||
|
response = client.get("/api/documents/")
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
|
response = client.get("/api/documents/", HTTP_REMOTE_USER="someone")
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
|
self.assertFalse(User.objects.filter(username="someone").exists())
|
||||||
|
|
||||||
|
response = client.get("/api/documents/", HTTP_X_FORWARDED_USER="someone")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
self.assertTrue(User.objects.filter(username="someone").exists())
|
Loading…
x
Reference in New Issue
Block a user