Browse Source

Write tests for LDAP disabled feature

Bastien Sevajol 9 years ago
parent
commit
f6f27c42d7
1 changed files with 76 additions and 0 deletions
  1. 76 0
      tracim/tracim/tests/functional/test_ldap_restrictions.py

+ 76 - 0
tracim/tracim/tests/functional/test_ldap_restrictions.py View File

@@ -0,0 +1,76 @@
1
+# -*- coding: utf-8 -*-
2
+from collections import OrderedDict
3
+
4
+from bs4 import BeautifulSoup
5
+from nose.tools import eq_, ok_
6
+
7
+from tracim.fixtures.ldap import ldap_test_server_fixtures
8
+from tracim.lib.base import current_user
9
+from tracim.model import DBSession, User
10
+from tracim.tests import LDAPTest, TracimTestController
11
+
12
+
13
+class TestAuthentication(LDAPTest, TracimTestController):
14
+    application_under_test = 'ldap'
15
+    ldap_server_data = ldap_test_server_fixtures
16
+
17
+    def test_password_disabled(self):
18
+        """
19
+        Password change is disabled
20
+        :return:
21
+        """
22
+        lawrence = DBSession.query(User).filter(User.email == 'lawrence-not-real-email@fsf.org').one()
23
+        self._connect_user('lawrence-not-real-email@fsf.org', 'foobarbaz')
24
+        home = self.app.get('/home/',)
25
+
26
+        # HTML button is not here
27
+        eq_(None, BeautifulSoup(home.body).find(attrs={'class': 'change-password-btn'}))
28
+
29
+        # If we force passwd update, we got 403
30
+        try_post_passwd = self.app.post(
31
+            '/user/%d/password?_method=PUT' % lawrence.user_id,
32
+            OrderedDict([
33
+                ('current_password', 'fooobarbaz'),
34
+                ('new_password1', 'foobar'),
35
+                ('new_password2', 'foobar'),
36
+            ]),
37
+            expect_errors=403
38
+        )
39
+        eq_(try_post_passwd.status_code, 403, "Code should be 403, but is %d" % try_post_passwd.status_code)
40
+
41
+    def test_fields_disabled(self):
42
+        """
43
+        Some fields (email) are not editable on user interface: they are managed by LDAP
44
+        :return:
45
+        """
46
+        lawrence = DBSession.query(User).filter(User.email == 'lawrence-not-real-email@fsf.org').one()
47
+        self._connect_user('lawrence-not-real-email@fsf.org', 'foobarbaz')
48
+
49
+        edit = self.app.get('/user/5/edit')
50
+
51
+        # email input field is disabled
52
+        email_input = BeautifulSoup(edit.body).find(attrs={'id': 'email'})
53
+        ok_('readonly' in email_input.attrs)
54
+        eq_(email_input.attrs['readonly'], "readonly")
55
+
56
+        # Name is not (see attributes configuration of LDAP fixtures)
57
+        name_input = BeautifulSoup(edit.body).find(attrs={'id': 'name'})
58
+        ok_('readonly' not in name_input.attrs)
59
+
60
+        # If we force edit of user, "email" field will be not updated
61
+        eq_(lawrence.email, 'lawrence-not-real-email@fsf.org')
62
+        eq_(lawrence.display_name, 'Lawrence Lessig')
63
+
64
+        try_post_user = self.app.post(
65
+            '/user/%d?_method=PUT' % lawrence.user_id,
66
+            OrderedDict([
67
+                ('name', 'Lawrence Lessig YEAH'),
68
+                ('email', 'An-other-email@fsf.org'),
69
+            ])
70
+        )
71
+
72
+        eq_(try_post_user.status_code, 302, "Code should be 302, but is %d" % try_post_user.status_code)
73
+
74
+        lawrence = DBSession.query(User).filter(User.email == 'lawrence-not-real-email@fsf.org').one()
75
+        eq_(lawrence.email, 'lawrence-not-real-email@fsf.org', "email should be unmodified")
76
+        eq_(lawrence.display_name, 'Lawrence Lessig YEAH', "Name should be updated")