Project

General

Profile

Defect #4483 » fixed-4483.patch

Yuichi HARADA, 2020-11-24 06:17

View differences:

app/models/auth_source_ldap.rb
71 71
    with_timeout do
72 72
      ldap_con = initialize_ldap_con(self.account, self.account_password)
73 73
      ldap_con.open {}
74
      if self.account.present? && !self.account.include?("$login") && self.account_password.present?
75
        ldap_auth = authenticate_dn(self.account, self.account_password)
76
        raise AuthSourceException.new(l(:error_ldap_bind_credentials)) if !ldap_auth
77
      end
74
      return if self.account.present? && self.account.include?("$login")
75
      ldap_auth = authenticate_dn(self.account, self.account_password)
76
      raise AuthSourceException.new(l(:error_ldap_bind_credentials)) if !ldap_auth
78 77
    end
79 78
  rescue *NETWORK_EXCEPTIONS => e
80 79
    raise AuthSourceException.new(e.message)
test/unit/auth_source_ldap_test.rb
197 197
      assert_equal [], results
198 198
    end
199 199

  
200
    def test_test_connection_with_correct_host_and_port
201
      auth_source = AuthSourceLdap.find(1)
202

  
203
      assert_nothing_raised do
204
        auth_source.test_connection
205
      end
206
    end
207

  
208 200
    def test_test_connection_with_incorrect_host
209 201
      auth_source = AuthSourceLdap.find(1)
210 202
      auth_source.host = "badhost"
......
233 225

  
234 226
      assert_equal "cn=admin,dc=redmine,dc=org", auth_source.account
235 227
      assert_equal "secret", auth_source.account_password
236
      assert_nil auth_source.test_connection
228
      assert_nothing_raised do
229
        auth_source.test_connection
230
      end
231
    end
232

  
233
    def test_test_connection_bind_with_dynamic_bind_account
234
      auth_source = AuthSourceLdap.find(1)
235
      auth_source.account = "cn=$login,dc=redmine,dc=org"
236
      auth_source.save!
237

  
238
      assert_equal "cn=$login,dc=redmine,dc=org", auth_source.account
239
      assert_nothing_raised do
240
        auth_source.test_connection
241
      end
237 242
    end
238 243

  
239 244
    def test_test_connection_bind_without_account_and_password
......
241 246

  
242 247
      assert_nil auth_source.account
243 248
      assert_equal "", auth_source.account_password
244
      assert_nil auth_source.test_connection
249
      assert_raise AuthSourceException do
250
        auth_source.test_connection
251
      end
245 252
    end
246 253

  
247 254
    def test_test_connection_bind_with_incorrect_account
(2-2/2)