##// END OF EJS Templates
Added some tests for the LDAP authentication....
Eric Davis -
r3324:7b6b147761a6
parent child
Show More
@@ -0,0 +1,82
1 dn: dc=redmine,dc=org
2 objectClass: top
3 objectClass: dcObject
4 objectClass: organization
5 o: redmine.org
6 dc: redmine
7 structuralObjectClass: organization
8 entryUUID: 886f5fca-0a87-102e-8d06-67c361d9bd2d
9 creatorsName:
10 createTimestamp: 20090721211642Z
11 entryCSN: 20090721211642.955188Z#000000#000#000000
12 modifiersName:
13 modifyTimestamp: 20090721211642Z
14
15 dn: cn=admin,dc=redmine,dc=org
16 objectClass: simpleSecurityObject
17 objectClass: organizationalRole
18 cn: admin
19 description: LDAP administrator
20 userPassword:: e2NyeXB0fWlWTU9DcUt6WWxXRDI=
21 structuralObjectClass: organizationalRole
22 entryUUID: 88704e44-0a87-102e-8d07-67c361d9bd2d
23 creatorsName:
24 createTimestamp: 20090721211642Z
25 entryCSN: 20090721211642.961418Z#000000#000#000000
26 modifiersName:
27 modifyTimestamp: 20090721211642Z
28
29 dn: ou=Person,dc=redmine,dc=org
30 ou: Person
31 objectClass: top
32 objectClass: organizationalUnit
33 structuralObjectClass: organizationalUnit
34 entryUUID: d39dd388-0c84-102e-82fa-dff86c63a7d6
35 creatorsName: cn=admin,dc=redmine,dc=org
36 createTimestamp: 20090724100222Z
37 entryCSN: 20090724100222.924226Z#000000#000#000000
38 modifiersName: cn=admin,dc=redmine,dc=org
39 modifyTimestamp: 20090724100222Z
40
41 dn: uid=example1,ou=Person,dc=redmine,dc=org
42 objectClass: posixAccount
43 objectClass: top
44 objectClass: inetOrgPerson
45 gidNumber: 0
46 givenName: Example
47 sn: One
48 uid: example1
49 homeDirectory: /home/example1
50 cn: Example One
51 structuralObjectClass: inetOrgPerson
52 entryUUID: 285d304e-0c8a-102e-82fc-dff86c63a7d6
53 creatorsName: cn=admin,dc=redmine,dc=org
54 createTimestamp: 20090724104032Z
55 uidNumber: 0
56 mail: example1@redmine.org
57 userPassword:: e1NIQX1mRXFOQ2NvM1lxOWg1WlVnbEQzQ1pKVDRsQnM9
58 entryCSN: 20090724105945.375801Z#000000#000#000000
59 modifiersName: cn=admin,dc=redmine,dc=org
60 modifyTimestamp: 20090724105945Z
61
62 dn: uid=edavis,ou=Person,dc=redmine,dc=org
63 objectClass: posixAccount
64 objectClass: top
65 objectClass: inetOrgPerson
66 gidNumber: 0
67 givenName: Eric
68 sn: Davis
69 uid: edavis
70 mail: edavis@littlestreamsoftware.com
71 structuralObjectClass: inetOrgPerson
72 entryUUID: 9c5f0502-0c8b-102e-82fe-dff86c63a7d6
73 creatorsName: cn=admin,dc=redmine,dc=org
74 createTimestamp: 20090724105056Z
75 homeDirectory: /home/edavis
76 cn: Eric Davis
77 uidNumber: 0
78 userPassword:: e1NIQX1mRXFOQ2NvM1lxOWg1WlVnbEQzQ1pKVDRsQnM9
79 entryCSN: 20090724105937.734480Z#000000#000#000000
80 modifiersName: cn=admin,dc=redmine,dc=org
81 modifyTimestamp: 20090724105937Z
82
@@ -22,3 +22,14 To test the support, a test repository needs to be created for each of those.
22 Run `rake --tasks test:scm:setup` for a list of available test-repositories or
22 Run `rake --tasks test:scm:setup` for a list of available test-repositories or
23 run `rake test:scm:setup:all` to set up all of them
23 run `rake test:scm:setup:all` to set up all of them
24
24
25 Creating a test ldap database
26 =============================
27
28 Redmine supports using LDAP for user authentications. To test LDAP
29 with Redmine, load the LDAP export from test/fixtures/ldap/test-ldap.ldif
30 into a testing LDAP server. Test that the ldap server can be accessed
31 at 127.0.0.1 on port 389.
32
33 Setting up the test ldap server is beyond the scope of this documentation.
34 The OpenLDAP project provides a simple LDAP implementation that should work
35 good as a test server.
@@ -76,6 +76,11 class ActiveSupport::TestCase
76 saved_settings.each {|k, v| Setting[k] = v}
76 saved_settings.each {|k, v| Setting[k] = v}
77 end
77 end
78
78
79 def self.ldap_configured?
80 @test_ldap = Net::LDAP.new(:host => '127.0.0.1', :port => 389)
81 return @test_ldap.bind
82 end
83
79 # Shoulda macros
84 # Shoulda macros
80 def self.should_render_404
85 def self.should_render_404
81 should_respond_with :not_found
86 should_respond_with :not_found
@@ -33,4 +33,62 class AuthSourceLdapTest < ActiveSupport::TestCase
33 assert a.save
33 assert a.save
34 assert_equal 'givenName', a.reload.attr_firstname
34 assert_equal 'givenName', a.reload.attr_firstname
35 end
35 end
36
37 if ldap_configured?
38 context '#authenticate' do
39 setup do
40 @auth = AuthSourceLdap.generate!(:name => 'on the fly',
41 :host => '127.0.0.1',
42 :port => 389,
43 :base_dn => 'OU=Person,DC=redmine,DC=org',
44 :attr_login => 'uid',
45 :attr_firstname => 'givenName',
46 :attr_lastname => 'sn',
47 :attr_mail => 'mail',
48 :onthefly_register => true)
49
50 end
51
52 context 'with a valid LDAP user' do
53 should 'return the firstname user attributes' do
54 response = @auth.authenticate('example1','123456')
55 assert response
56 assert_equal 'Example', response.first[:firstname]
57 end
58
59 should 'return the lastname user attributes' do
60 response = @auth.authenticate('example1','123456')
61 assert response
62 assert_equal 'One', response.first[:lastname]
63 end
64
65 should 'return mail user attributes' do
66 response = @auth.authenticate('example1','123456')
67 assert response
68 assert_equal 'example1@redmine.org', response.first[:mail]
69 end
70 end
71
72 context 'with an invalid LDAP user' do
73 should 'return nil' do
74 assert_equal nil, @auth.authenticate('nouser','123456')
75 end
76 end
77
78 context 'without a login' do
79 should 'return nil' do
80 assert_equal nil, @auth.authenticate('','123456')
81 end
82 end
83
84 context 'without a password' do
85 should 'return nil' do
86 assert_equal nil, @auth.authenticate('edavis','')
87 end
88 end
89
90 end
91 else
92 puts '(Test LDAP server not configured)'
93 end
36 end
94 end
General Comments 0
You need to be logged in to leave comments. Login now