Commit a9a9fa1fbf971f19329a42f2520c70e919e8b903

Authored by Rodrigo Souto
1 parent df990a64

Removing trailing whitespaces from ldap plugin

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