Test the authentication
- An "outsider" must use django's authentication backend - A user with a login_clipper should use CAS
This commit is contained in:
parent
8b620a5319
commit
0420839b20
1 changed files with 35 additions and 0 deletions
|
@ -70,3 +70,38 @@ class TestProfile(TestCase):
|
||||||
c.login(username='root', password='root')
|
c.login(username='root', password='root')
|
||||||
response = c.get('/')
|
response = c.get('/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
class AuthTest(TestCase):
|
||||||
|
def test_login(self):
|
||||||
|
client = Client()
|
||||||
|
# Setup a regular Django user
|
||||||
|
user = User.objects.create(username="foo")
|
||||||
|
user.set_password("bar")
|
||||||
|
user.save()
|
||||||
|
# Test the django auth
|
||||||
|
resp = client.post(
|
||||||
|
"/outsider/login",
|
||||||
|
{"username": "foo", "password": "bar"},
|
||||||
|
follow=True
|
||||||
|
)
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
resp = client.get("/logout")
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
# Give the user a clipper login
|
||||||
|
user.profile.login_clipper = "foo"
|
||||||
|
user.profile.save()
|
||||||
|
# Assert that it cannot use the regular auth
|
||||||
|
resp = client.post(
|
||||||
|
"/outsider/login",
|
||||||
|
{"username": "foo", "password": "bar"}
|
||||||
|
)
|
||||||
|
self.assertIn("error_type", resp.context)
|
||||||
|
self.assertEqual(resp.context["error_type"], "use_clipper_login")
|
||||||
|
# Test the CAS redirect
|
||||||
|
resp = client.get("/cas/login")
|
||||||
|
self.assertEqual(resp.status_code, 302)
|
||||||
|
self.assertEqual(
|
||||||
|
resp.url.split('?')[0],
|
||||||
|
"https://cas.eleves.ens.fr/login"
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue