From 6b550e05474c6a8ca6730638a4d2770f9a3da0f8 Mon Sep 17 00:00:00 2001 From: Matthias <code@mjmair.com> Date: Fri, 13 May 2022 01:23:12 +0200 Subject: [PATCH] Tests for token Auth --- InvenTree/InvenTree/test_middleware.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/InvenTree/InvenTree/test_middleware.py b/InvenTree/InvenTree/test_middleware.py index fbf08eb172..8728955b1c 100644 --- a/InvenTree/InvenTree/test_middleware.py +++ b/InvenTree/InvenTree/test_middleware.py @@ -47,3 +47,20 @@ class MiddlewareTests(TestCase): # check that a 401 is raised self.check_path(reverse('settings.js'), 401) + + def test_token_auth(self): + """Test auth with token auth""" + # get token + response = self.client.get(reverse('api-token'), format='json', data={}) + token = response.data['token'] + + # logout + self.client.logout() + # this should raise a 401 + self.check_path(reverse('settings.js'), 401) + + # request with token + self.check_path(reverse('settings.js'), HTTP_Authorization= f'Token {token}') + + # should still fail without token + self.check_path(reverse('settings.js'), 401)