Commit a9a9fa1fbf971f19329a42f2520c70e919e8b903
1 parent
df990a64
Exists in
master
and in
29 other branches
Removing trailing whitespaces from ldap plugin
Also fixing a typo
Showing
7 changed files
with
31 additions
and
31 deletions
Show diff stats
plugins/ldap/lib/ext/environment.rb
@@ -18,7 +18,7 @@ class Environment | @@ -18,7 +18,7 @@ class Environment | ||
18 | def ldap_plugin_host | 18 | def ldap_plugin_host |
19 | self.ldap_plugin['host'] | 19 | self.ldap_plugin['host'] |
20 | end | 20 | end |
21 | - | 21 | + |
22 | def ldap_plugin_port= port | 22 | def ldap_plugin_port= port |
23 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 23 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
24 | self.ldap_plugin['port'] = port | 24 | self.ldap_plugin['port'] = port |
@@ -29,7 +29,7 @@ class Environment | @@ -29,7 +29,7 @@ class Environment | ||
29 | self.ldap_plugin['port'] ||= 389 | 29 | self.ldap_plugin['port'] ||= 389 |
30 | self.ldap_plugin['port'] | 30 | self.ldap_plugin['port'] |
31 | end | 31 | end |
32 | - | 32 | + |
33 | def ldap_plugin_account | 33 | def ldap_plugin_account |
34 | self.ldap_plugin['account'] | 34 | self.ldap_plugin['account'] |
35 | end | 35 | end |
@@ -38,7 +38,7 @@ class Environment | @@ -38,7 +38,7 @@ class Environment | ||
38 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 38 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
39 | self.ldap_plugin['account'] = account | 39 | self.ldap_plugin['account'] = account |
40 | end | 40 | end |
41 | - | 41 | + |
42 | def ldap_plugin_account_password | 42 | def ldap_plugin_account_password |
43 | self.ldap_plugin['account_password'] | 43 | self.ldap_plugin['account_password'] |
44 | end | 44 | end |
@@ -47,16 +47,16 @@ class Environment | @@ -47,16 +47,16 @@ class Environment | ||
47 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 47 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
48 | self.ldap_plugin['account_password'] = password | 48 | self.ldap_plugin['account_password'] = password |
49 | end | 49 | end |
50 | - | 50 | + |
51 | def ldap_plugin_base_dn | 51 | def ldap_plugin_base_dn |
52 | self.ldap_plugin['base_dn'] | 52 | self.ldap_plugin['base_dn'] |
53 | end | 53 | end |
54 | - | 54 | + |
55 | def ldap_plugin_base_dn= base_dn | 55 | def ldap_plugin_base_dn= base_dn |
56 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 56 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
57 | self.ldap_plugin['base_dn'] = base_dn | 57 | self.ldap_plugin['base_dn'] = base_dn |
58 | end | 58 | end |
59 | - | 59 | + |
60 | def ldap_plugin_attr_login | 60 | def ldap_plugin_attr_login |
61 | self.ldap_plugin['attr_login'] | 61 | self.ldap_plugin['attr_login'] |
62 | end | 62 | end |
@@ -65,47 +65,47 @@ class Environment | @@ -65,47 +65,47 @@ class Environment | ||
65 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 65 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
66 | self.ldap_plugin['attr_login'] = login | 66 | self.ldap_plugin['attr_login'] = login |
67 | end | 67 | end |
68 | - | 68 | + |
69 | def ldap_plugin_attr_fullname | 69 | def ldap_plugin_attr_fullname |
70 | self.ldap_plugin['attr_fullname'] | 70 | self.ldap_plugin['attr_fullname'] |
71 | end | 71 | end |
72 | - | 72 | + |
73 | def ldap_plugin_attr_fullname= fullname | 73 | def ldap_plugin_attr_fullname= fullname |
74 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 74 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
75 | self.ldap_plugin['attr_fullname'] = fullname | 75 | self.ldap_plugin['attr_fullname'] = fullname |
76 | end | 76 | end |
77 | - | 77 | + |
78 | def ldap_plugin_attr_mail | 78 | def ldap_plugin_attr_mail |
79 | self.ldap_plugin['attr_mail'] | 79 | self.ldap_plugin['attr_mail'] |
80 | end | 80 | end |
81 | - | 81 | + |
82 | def ldap_plugin_attr_mail= mail | 82 | def ldap_plugin_attr_mail= mail |
83 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 83 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
84 | self.ldap_plugin['attr_mail'] = mail | 84 | self.ldap_plugin['attr_mail'] = mail |
85 | end | 85 | end |
86 | - | 86 | + |
87 | def ldap_plugin_onthefly_register | 87 | def ldap_plugin_onthefly_register |
88 | self.ldap_plugin['onthefly_register'].to_s == 'true' | 88 | self.ldap_plugin['onthefly_register'].to_s == 'true' |
89 | end | 89 | end |
90 | - | 90 | + |
91 | def ldap_plugin_onthefly_register= value | 91 | def ldap_plugin_onthefly_register= value |
92 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 92 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
93 | self.ldap_plugin['onthefly_register'] = (value.to_s == '1') ? true : false | 93 | self.ldap_plugin['onthefly_register'] = (value.to_s == '1') ? true : false |
94 | end | 94 | end |
95 | - | 95 | + |
96 | def ldap_plugin_filter | 96 | def ldap_plugin_filter |
97 | self.ldap_plugin['filter'] | 97 | self.ldap_plugin['filter'] |
98 | end | 98 | end |
99 | - | 99 | + |
100 | def ldap_plugin_filter= filter | 100 | def ldap_plugin_filter= filter |
101 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 101 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
102 | self.ldap_plugin['filter'] = filter | 102 | self.ldap_plugin['filter'] = filter |
103 | end | 103 | end |
104 | - | 104 | + |
105 | def ldap_plugin_tls | 105 | def ldap_plugin_tls |
106 | self.ldap_plugin['tls'] ||= false | 106 | self.ldap_plugin['tls'] ||= false |
107 | end | 107 | end |
108 | - | 108 | + |
109 | def ldap_plugin_tls= value | 109 | def ldap_plugin_tls= value |
110 | self.ldap_plugin = {} if self.ldap_plugin.blank? | 110 | self.ldap_plugin = {} if self.ldap_plugin.blank? |
111 | self.ldap_plugin['tls'] = (value.to_s == '1') ? true : false | 111 | self.ldap_plugin['tls'] = (value.to_s == '1') ? true : false |
plugins/ldap/lib/ldap_plugin.rb
@@ -34,7 +34,7 @@ class LdapPlugin < Noosfero::Plugin | @@ -34,7 +34,7 @@ class LdapPlugin < Noosfero::Plugin | ||
34 | rescue Net::LDAP::LdapError => e | 34 | rescue Net::LDAP::LdapError => e |
35 | puts "LDAP is not configured correctly" | 35 | puts "LDAP is not configured correctly" |
36 | end | 36 | end |
37 | - | 37 | + |
38 | if attrs | 38 | if attrs |
39 | user.login = login | 39 | user.login = login |
40 | user.email = attrs[:mail] | 40 | user.email = attrs[:mail] |
@@ -54,19 +54,19 @@ class LdapPlugin < Noosfero::Plugin | @@ -54,19 +54,19 @@ class LdapPlugin < Noosfero::Plugin | ||
54 | else | 54 | else |
55 | user = nil | 55 | user = nil |
56 | end | 56 | end |
57 | - | 57 | + |
58 | else | 58 | else |
59 | 59 | ||
60 | return nil if !user.activated? | 60 | return nil if !user.activated? |
61 | 61 | ||
62 | begin | 62 | begin |
63 | - # user si defined as nil if ldap authentication failed | 63 | + # user is defined as nil if ldap authentication failed |
64 | user = nil if ldap.authenticate(login, password).nil? | 64 | user = nil if ldap.authenticate(login, password).nil? |
65 | rescue Net::LDAP::LdapError => e | 65 | rescue Net::LDAP::LdapError => e |
66 | user = nil | 66 | user = nil |
67 | puts "LDAP is not configured correctly" | 67 | puts "LDAP is not configured correctly" |
68 | end | 68 | end |
69 | - end | 69 | + end |
70 | 70 | ||
71 | user | 71 | user |
72 | end | 72 | end |
@@ -77,7 +77,7 @@ class LdapPlugin < Noosfero::Plugin | @@ -77,7 +77,7 @@ class LdapPlugin < Noosfero::Plugin | ||
77 | @profile_data = @person | 77 | @profile_data = @person |
78 | labelled_fields_for :profile_data, @person do |f| | 78 | labelled_fields_for :profile_data, @person do |f| |
79 | render :partial => 'profile_editor/person_form', :locals => {:f => f} | 79 | render :partial => 'profile_editor/person_form', :locals => {:f => f} |
80 | - end | 80 | + end |
81 | end | 81 | end |
82 | end | 82 | end |
83 | 83 |
plugins/ldap/test/functional/account_controller_plugin_test.rb
@@ -9,7 +9,7 @@ class AccountControllerPluginTest < ActionController::TestCase | @@ -9,7 +9,7 @@ class AccountControllerPluginTest < ActionController::TestCase | ||
9 | @controller = AccountController.new | 9 | @controller = AccountController.new |
10 | @request = ActionController::TestRequest.new | 10 | @request = ActionController::TestRequest.new |
11 | @response = ActionController::TestResponse.new | 11 | @response = ActionController::TestResponse.new |
12 | - | 12 | + |
13 | @environment = Environment.default | 13 | @environment = Environment.default |
14 | @environment.enabled_plugins = ['LdapPlugin'] | 14 | @environment.enabled_plugins = ['LdapPlugin'] |
15 | @ldap_config = load_ldap_config | 15 | @ldap_config = load_ldap_config |
@@ -51,14 +51,14 @@ class AccountControllerPluginTest < ActionController::TestCase | @@ -51,14 +51,14 @@ class AccountControllerPluginTest < ActionController::TestCase | ||
51 | assert session[:user] | 51 | assert session[:user] |
52 | assert_equal count, User.count | 52 | assert_equal count, User.count |
53 | end | 53 | end |
54 | - | 54 | + |
55 | should 'login and create a new noosfero user if ldap authentication works properly' do | 55 | should 'login and create a new noosfero user if ldap authentication works properly' do |
56 | count = User.count | 56 | count = User.count |
57 | post :login, :user => @ldap_config['user'] | 57 | post :login, :user => @ldap_config['user'] |
58 | assert session[:user] | 58 | assert session[:user] |
59 | assert_equal count + 1, User.count | 59 | assert_equal count + 1, User.count |
60 | end | 60 | end |
61 | - | 61 | + |
62 | should 'login on ldap if required fields are defined' do | 62 | should 'login on ldap if required fields are defined' do |
63 | count = User.count | 63 | count = User.count |
64 | @environment.custom_person_fields = {"contact_phone"=>{"required"=>"true", "signup"=>"false", "active"=>"true"}} | 64 | @environment.custom_person_fields = {"contact_phone"=>{"required"=>"true", "signup"=>"false", "active"=>"true"}} |
@@ -66,14 +66,14 @@ class AccountControllerPluginTest < ActionController::TestCase | @@ -66,14 +66,14 @@ class AccountControllerPluginTest < ActionController::TestCase | ||
66 | post :login, :user => @ldap_config['user'], :profile_data => {:contact_phone => '11111111'} | 66 | post :login, :user => @ldap_config['user'], :profile_data => {:contact_phone => '11111111'} |
67 | assert session[:user] | 67 | assert session[:user] |
68 | end | 68 | end |
69 | - | 69 | + |
70 | should 'not login on ldap if required fields are not defined' do | 70 | should 'not login on ldap if required fields are not defined' do |
71 | @environment.custom_person_fields = {"contact_phone"=>{"required"=>"true", "signup"=>"false", "active"=>"true"}} | 71 | @environment.custom_person_fields = {"contact_phone"=>{"required"=>"true", "signup"=>"false", "active"=>"true"}} |
72 | @environment.save | 72 | @environment.save |
73 | post :login, :user => @ldap_config['user'] | 73 | post :login, :user => @ldap_config['user'] |
74 | assert_nil session[:user] | 74 | assert_nil session[:user] |
75 | end | 75 | end |
76 | - | 76 | + |
77 | should 'authenticate user if its not a local user but is a ldap user' do | 77 | should 'authenticate user if its not a local user but is a ldap user' do |
78 | post :login, :user => @ldap_config['user'] | 78 | post :login, :user => @ldap_config['user'] |
79 | assert session[:user] | 79 | assert session[:user] |
plugins/ldap/test/functional/ldap_plugin_admin_controller_test.rb
@@ -10,7 +10,7 @@ class LdapPluginAdminControllerTest < ActionController::TestCase | @@ -10,7 +10,7 @@ class LdapPluginAdminControllerTest < ActionController::TestCase | ||
10 | @controller = LdapPluginAdminController.new | 10 | @controller = LdapPluginAdminController.new |
11 | @request = ActionController::TestRequest.new | 11 | @request = ActionController::TestRequest.new |
12 | @response = ActionController::TestResponse.new | 12 | @response = ActionController::TestResponse.new |
13 | - | 13 | + |
14 | @environment = Environment.default | 14 | @environment = Environment.default |
15 | user_login = create_admin_user(@environment) | 15 | user_login = create_admin_user(@environment) |
16 | login_as(user_login) | 16 | login_as(user_login) |
plugins/ldap/test/test_helper.rb
1 | require File.dirname(__FILE__) + '/../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../test/test_helper' |
2 | 2 | ||
3 | -def load_ldap_config | 3 | +def load_ldap_config |
4 | begin | 4 | begin |
5 | YAML.load_file(File.dirname(__FILE__) + '/../fixtures/ldap.yml') | 5 | YAML.load_file(File.dirname(__FILE__) + '/../fixtures/ldap.yml') |
6 | rescue Errno::ENOENT => e | 6 | rescue Errno::ENOENT => e |
7 | # There is no config file | 7 | # There is no config file |
8 | return nil | 8 | return nil |
9 | - end | 9 | + end |
10 | end | 10 | end |
11 | 11 | ||
12 | def ldap_configured? | 12 | def ldap_configured? |
plugins/ldap/test/unit/ext/environment_test.rb
@@ -166,7 +166,7 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -166,7 +166,7 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
166 | should 'validates presence of host' do | 166 | should 'validates presence of host' do |
167 | @enviroment.ldap_plugin= {:port => 3000} | 167 | @enviroment.ldap_plugin= {:port => 3000} |
168 | @enviroment.valid? | 168 | @enviroment.valid? |
169 | - | 169 | + |
170 | assert @enviroment.errors.invalid?(:ldap_plugin_host) | 170 | assert @enviroment.errors.invalid?(:ldap_plugin_host) |
171 | 171 | ||
172 | @enviroment.ldap_plugin_host= "http://somehost.com" | 172 | @enviroment.ldap_plugin_host= "http://somehost.com" |
plugins/ldap/test/unit/ldap_authentication_test.rb