Browse Source

Refact ldap fixture and add gearbox command to start test ldap server

Bastien Sevajol 8 years ago
parent
commit
0e7a7a7e9c

+ 1 - 0
tracim/__init__.py View File

@@ -0,0 +1 @@
1
+__author__ = 'bux'

+ 0 - 59
tracim/s.py View File

@@ -1,59 +0,0 @@
1
-from time import sleep
2
-
3
-from ldap_test import LdapServer
4
-
5
-server = LdapServer({
6
-            'port': 3333,
7
-            'password': 'toor',
8
-
9
-            'bind_dn': 'cn=admin,dc=directory,dc=fsf,dc=org',
10
-            'base': {
11
-                'objectclass': ['dcObject', 'organization'],
12
-                'dn': 'dc=directory,dc=fsf,dc=org',
13
-                'attributes': {
14
-                    'o': 'Free Software Foundation',
15
-                    'dc': 'directory'
16
-                }
17
-            },
18
-
19
-            'entries': [
20
-                {
21
-                    'objectclass': ['organizationalRole'],
22
-                    'dn': 'cn=admin,dc=directory,dc=fsf,dc=org',
23
-                    'attributes': {
24
-                        'cn': 'admin'
25
-                    }
26
-                },
27
-                {
28
-                    'objectclass': ['organizationalUnit'],
29
-                    'dn': 'ou=people,dc=directory,dc=fsf,dc=org',
30
-                    'attributes': {
31
-                        'ou': 'people',
32
-                    }
33
-                },
34
-                {
35
-                    'objectclass': ['organizationalUnit'],
36
-                    'dn': 'ou=groups,dc=directory,dc=fsf,dc=org',
37
-                    'attributes': {
38
-                        'ou': 'groups',
39
-                    }
40
-                },
41
-                {
42
-                    'objectclass': ['account', 'top'],
43
-                    'dn': 'cn=richard-not-real-email@fsf.org,ou=people,dc=directory,dc=fsf,dc=org',
44
-                    'attributes': {
45
-                        'uid': 'richard-not-real-email@fsf.org',
46
-                        'userPassword': 'rms',
47
-                        'givenName': 'Richard',
48
-                        'sn': 'Stallman',
49
-                        'mail': 'richard-not-real-email@fsf.org'
50
-                    }
51
-                },
52
-            ]
53
-        })
54
-
55
-server.start()
56
-try:
57
-    sleep(999999999)
58
-except KeyboardInterrupt:
59
-    pass

+ 3 - 0
tracim/setup.py View File

@@ -69,6 +69,9 @@ setup(
69 69
         ],
70 70
         'gearbox.plugins': [
71 71
             'turbogears-devtools = tg.devtools'
72
+        ],
73
+        'gearbox.commands': [
74
+            'ldap_server = tracim.command.ldap_test_server:LDAPTestServerCommand',
72 75
         ]
73 76
     },
74 77
     dependency_links=[

+ 1 - 0
tracim/tracim/command/__init__.py View File

@@ -0,0 +1 @@
1
+__author__ = 'bux'

+ 18 - 0
tracim/tracim/command/ldap_test_server.py View File

@@ -0,0 +1,18 @@
1
+from time import sleep
2
+from tracim.fixtures.ldap import ldap_test_server_fixtures
3
+from gearbox.command import Command
4
+from ldap_test import LdapServer
5
+
6
+
7
+class LDAPTestServerCommand(Command):
8
+    def take_action(self, parsed_args):
9
+        # TODO - B.S. - 20160210: paramètre argv pour preciser les fixtures
10
+        server = LdapServer(ldap_test_server_fixtures)
11
+        print("Starting LDAP server on localhost (port %d)" % ldap_test_server_fixtures.get('port'))
12
+        print("Press CTRL+C to stop it")
13
+        server.start()
14
+        try:
15
+            while True:
16
+                sleep(1)
17
+        except KeyboardInterrupt:
18
+            pass

+ 0 - 0
tracim/tracim/fixtures/__init__.py View File


+ 56 - 0
tracim/tracim/fixtures/ldap.py View File

@@ -0,0 +1,56 @@
1
+ldap_test_server_fixtures = {
2
+    'port': 3333,
3
+    'password': 'toor',
4
+
5
+    'bind_dn': 'cn=admin,dc=directory,dc=fsf,dc=org',
6
+    'base': {
7
+        'objectclass': ['dcObject', 'organization'],
8
+        'dn': 'dc=directory,dc=fsf,dc=org',
9
+        'attributes': {
10
+            'o': 'Free Software Foundation',
11
+            'dc': 'directory'
12
+        }
13
+    },
14
+
15
+    'entries': [
16
+        {
17
+            'objectclass': ['organizationalRole'],
18
+            'dn': 'cn=admin,dc=directory,dc=fsf,dc=org',
19
+            'attributes': {
20
+                'cn': 'admin'
21
+            }
22
+        },
23
+        {
24
+            'objectclass': ['organizationalUnit'],
25
+            'dn': 'ou=people,dc=directory,dc=fsf,dc=org',
26
+            'attributes': {
27
+                'ou': 'people',
28
+            }
29
+        },
30
+        {
31
+            'objectclass': ['organizationalUnit'],
32
+            'dn': 'ou=groups,dc=directory,dc=fsf,dc=org',
33
+            'attributes': {
34
+                'ou': 'groups',
35
+            }
36
+        },
37
+        {
38
+            'objectclass': ['account', 'top'],
39
+            'dn': 'cn=richard-not-real-email@fsf.org,ou=people,dc=directory,dc=fsf,dc=org',
40
+            'attributes': {
41
+                'uid': 'richard-not-real-email@fsf.org',
42
+                'userPassword': 'rms',
43
+                'mail': 'richard-not-real-email@fsf.org'
44
+            }
45
+        },
46
+        {
47
+            'objectclass': ['account', 'top'],
48
+            'dn': 'cn=lawrence-not-real-email@fsf.org,ou=people,dc=directory,dc=fsf,dc=org',
49
+            'attributes': {
50
+                'uid': 'lawrence-not-real-email@fsf.org',
51
+                'userPassword': 'foobarbaz',
52
+                'mail': 'lawrence-not-real-email@fsf.org'
53
+            }
54
+        },
55
+    ]
56
+}

+ 2 - 48
tracim/tracim/tests/functional/test_ldap_authentication.py View File

@@ -2,8 +2,8 @@
2 2
 """
3 3
 Integration tests for the ldap authentication sub-system.
4 4
 """
5
+from tracim.fixtures.ldap import ldap_test_server_fixtures
5 6
 from nose.tools import eq_
6
-from tg import config
7 7
 
8 8
 from tracim.model import DBSession, User
9 9
 from tracim.tests import LDAPTest, TracimTestController
@@ -11,53 +11,7 @@ from tracim.tests import LDAPTest, TracimTestController
11 11
 
12 12
 class TestAuthentication(LDAPTest, TracimTestController):
13 13
     application_under_test = 'ldap'
14
-    ldap_server_data = {
15
-            'port': 3333,
16
-            'password': 'toor',
17
-
18
-            'bind_dn': 'cn=admin,dc=directory,dc=fsf,dc=org',
19
-            'base': {
20
-                'objectclass': ['dcObject', 'organization'],
21
-                'dn': 'dc=directory,dc=fsf,dc=org',
22
-                'attributes': {
23
-                    'o': 'Free Software Foundation',
24
-                    'dc': 'directory'
25
-                }
26
-            },
27
-
28
-            'entries': [
29
-                {
30
-                    'objectclass': ['organizationalRole'],
31
-                    'dn': 'cn=admin,dc=directory,dc=fsf,dc=org',
32
-                    'attributes': {
33
-                        'cn': 'admin'
34
-                    }
35
-                },
36
-                {
37
-                    'objectclass': ['organizationalUnit'],
38
-                    'dn': 'ou=people,dc=directory,dc=fsf,dc=org',
39
-                    'attributes': {
40
-                        'ou': 'people',
41
-                    }
42
-                },
43
-                {
44
-                    'objectclass': ['organizationalUnit'],
45
-                    'dn': 'ou=groups,dc=directory,dc=fsf,dc=org',
46
-                    'attributes': {
47
-                        'ou': 'groups',
48
-                    }
49
-                },
50
-                {
51
-                    'objectclass': ['account', 'top'],
52
-                    'dn': 'cn=richard-not-real-email@fsf.org,ou=people,dc=directory,dc=fsf,dc=org',
53
-                    'attributes': {
54
-                        'uid': 'richard-not-real-email@fsf.org',
55
-                        'userPassword': 'rms',
56
-                        'mail': 'richard-not-real-email@fsf.org'
57
-                    }
58
-                },
59
-            ]
60
-        }
14
+    ldap_server_data = ldap_test_server_fixtures
61 15
 
62 16
     def test_ldap_auth_fail(self):
63 17
         # User is unknown in tracim database