Project

General

Profile

Defect #21674 » ldap_test_bind_user_password.diff

Patch - Helder Manuel Torres Vieira, 2016-01-08 12:16

View differences:

app/models/auth_source_ldap.rb (copia de trabajo)
56 56
    raise AuthSourceException.new(e.message)
57 57
  end
58 58

  
59
  # test the connection to the LDAP
59
  # Test the connection to the LDAP
60 60
  def test_connection
61 61
    with_timeout do
62 62
      ldap_con = initialize_ldap_con(self.account, self.account_password)
63 63
      ldap_con.open { }
64

  
65
      if self.account.present? && self.account_password.present?
66
        ldap_auth = authenticate_dn(self.account, self.account_password)
67
        raise AuthSourceException.new(l(:error_ldap_bind_credentials)) if !ldap_auth
68
      end
64 69
    end
65 70
  rescue *NETWORK_EXCEPTIONS => e
66 71
    raise AuthSourceException.new(e.message)
config/locales/ar.yml (copia de trabajo)
1182 1182
  label_any_open_issues: any open issues
1183 1183
  label_no_open_issues: no open issues
1184 1184
  label_default_values_for_new_users: Default values for new users
1185
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/az.yml (copia de trabajo)
1277 1277
  label_any_open_issues: any open issues
1278 1278
  label_no_open_issues: no open issues
1279 1279
  label_default_values_for_new_users: Default values for new users
1280
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/bg.yml (copia de trabajo)
1173 1173
  description_date_to: Въведете крайна дата
1174 1174
  text_repository_identifier_info: 'Позволени са малки букви (a-z), цифри, тирета и _.<br />Промяна след създаването му не е възможна.'
1175 1175
  label_default_values_for_new_users: Default values for new users
1176
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/bs.yml (copia de trabajo)
1195 1195
  label_any_open_issues: any open issues
1196 1196
  label_no_open_issues: no open issues
1197 1197
  label_default_values_for_new_users: Default values for new users
1198
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/ca.yml (copia de trabajo)
1184 1184
  label_any_open_issues: any open issues
1185 1185
  label_no_open_issues: no open issues
1186 1186
  label_default_values_for_new_users: Default values for new users
1187
  error_ldap_bind_credentials: Compte/Contrasenya LDAP incorrecte
config/locales/cs.yml (copia de trabajo)
1183 1183
  label_any_open_issues: any open issues
1184 1184
  label_no_open_issues: no open issues
1185 1185
  label_default_values_for_new_users: Default values for new users
1186
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/da.yml (copia de trabajo)
1199 1199
  label_any_open_issues: any open issues
1200 1200
  label_no_open_issues: no open issues
1201 1201
  label_default_values_for_new_users: Default values for new users
1202
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/de.yml (copia de trabajo)
1191 1191
  label_any_open_issues: any open issues
1192 1192
  label_no_open_issues: no open issues
1193 1193
  label_default_values_for_new_users: Default values for new users
1194
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/el.yml (copia de trabajo)
1182 1182
  label_any_open_issues: any open issues
1183 1183
  label_no_open_issues: no open issues
1184 1184
  label_default_values_for_new_users: Default values for new users
1185
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/en-GB.yml (copia de trabajo)
1184 1184
  setting_attachment_extensions_allowed: Allowed extensions
1185 1185
  setting_attachment_extensions_denied: Disallowed extensions
1186 1186
  label_default_values_for_new_users: Default values for new users
1187
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/en.yml (copia de trabajo)
1169 1169
  description_date_from: Enter start date
1170 1170
  description_date_to: Enter end date
1171 1171
  text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.'
1172
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/es-PA.yml (copia de trabajo)
932 932
  label_subtask_plural: Subtareas
933 933
  label_project_copy_notifications: Enviar notificaciones por correo electrónico durante la copia del proyecto
934 934
  error_can_not_delete_custom_field: Fue imposible eliminar el campo personalizado
935
  error_unable_to_connect: Fue imposible conectar con (%{value})
935
  error_unable_to_connect: Fue imposible conectarse (%{value})
936 936
  error_can_not_remove_role: Este rol está en uso y no puede ser eliminado.
937 937
  error_can_not_delete_tracker: Este tipo contiene incidencias y no puede ser eliminado.
938 938
  field_principal: Principal
......
1216 1216
  label_any_open_issues: any open issues
1217 1217
  label_no_open_issues: no open issues
1218 1218
  label_default_values_for_new_users: Default values for new users
1219
  error_ldap_bind_credentials: Cuenta/Contraseña LDAP incorrecta
config/locales/es.yml (copia de trabajo)
930 930
  label_subtask_plural: Subtareas
931 931
  label_project_copy_notifications: Enviar notificaciones por correo electrónico durante la copia del proyecto
932 932
  error_can_not_delete_custom_field: Fue imposible eliminar el campo personalizado
933
  error_unable_to_connect: Fue imposible conectar con (%{value})
933
  error_unable_to_connect: Fue imposible conectarse (%{value})
934 934
  error_can_not_remove_role: Este rol está en uso y no puede ser eliminado.
935 935
  error_can_not_delete_tracker: Este tipo contiene peticiones y no puede ser eliminado.
936 936
  field_principal: Principal
......
1214 1214
  label_any_open_issues: any open issues
1215 1215
  label_no_open_issues: no open issues
1216 1216
  label_default_values_for_new_users: Default values for new users
1217
  error_ldap_bind_credentials: Cuenta/Contraseña LDAP incorrecta
config/locales/et.yml (copia de trabajo)
1195 1195
  label_any_open_issues: any open issues
1196 1196
  label_no_open_issues: no open issues
1197 1197
  label_default_values_for_new_users: Default values for new users
1198
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/eu.yml (copia de trabajo)
1183 1183
  label_any_open_issues: any open issues
1184 1184
  label_no_open_issues: no open issues
1185 1185
  label_default_values_for_new_users: Default values for new users
1186
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/fa.yml (copia de trabajo)
1183 1183
  label_any_open_issues: any open issues
1184 1184
  label_no_open_issues: no open issues
1185 1185
  label_default_values_for_new_users: Default values for new users
1186
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/fi.yml (copia de trabajo)
1203 1203
  label_any_open_issues: any open issues
1204 1204
  label_no_open_issues: no open issues
1205 1205
  label_default_values_for_new_users: Default values for new users
1206
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/fr.yml (copia de trabajo)
1189 1189
  text_repository_identifier_info: 'Seuls les lettres minuscules (a-z), chiffres, tirets et tirets bas sont autorisés.<br />Un fois sauvegardé, l''identifiant ne pourra plus être modifié.'
1190 1190
  label_parent_task_attributes_derived: Calculated from subtasks
1191 1191
  label_parent_task_attributes_independent: Independent of subtasks
1192
  error_ldap_bind_credentials: Compte/Mot de Passe LDAP incorrect
config/locales/gl.yml (copia de trabajo)
1190 1190
  label_any_open_issues: any open issues
1191 1191
  label_no_open_issues: no open issues
1192 1192
  label_default_values_for_new_users: Default values for new users
1193
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/he.yml (copia de trabajo)
1187 1187
  label_any_open_issues: any open issues
1188 1188
  label_no_open_issues: no open issues
1189 1189
  label_default_values_for_new_users: Default values for new users
1190
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/hr.yml (copia de trabajo)
1181 1181
  label_any_open_issues: any open issues
1182 1182
  label_no_open_issues: no open issues
1183 1183
  label_default_values_for_new_users: Default values for new users
1184
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/hu.yml (copia de trabajo)
1201 1201
  label_any_open_issues: any open issues
1202 1202
  label_no_open_issues: no open issues
1203 1203
  label_default_values_for_new_users: Default values for new users
1204
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/id.yml (copia de trabajo)
1186 1186
  label_any_open_issues: any open issues
1187 1187
  label_no_open_issues: no open issues
1188 1188
  label_default_values_for_new_users: Default values for new users
1189
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/it.yml (copia de trabajo)
1177 1177
  label_any_open_issues: any open issues
1178 1178
  label_no_open_issues: no open issues
1179 1179
  label_default_values_for_new_users: Default values for new users
1180
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/ja.yml (copia de trabajo)
1195 1195
  label_any_open_issues: 未完了のチケット
1196 1196
  label_no_open_issues: なし または完了したチケット
1197 1197
  label_default_values_for_new_users: Default values for new users
1198
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/ko.yml (copia de trabajo)
1226 1226
  label_any_open_issues: any open issues
1227 1227
  label_no_open_issues: no open issues
1228 1228
  label_default_values_for_new_users: Default values for new users
1229
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/lt.yml (copia de trabajo)
1241 1241
  label_any_open_issues: any open issues
1242 1242
  label_no_open_issues: no open issues
1243 1243
  label_default_values_for_new_users: Default values for new users
1244
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/lv.yml (copia de trabajo)
1176 1176
  label_any_open_issues: any open issues
1177 1177
  label_no_open_issues: no open issues
1178 1178
  label_default_values_for_new_users: Default values for new users
1179
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/mk.yml (copia de trabajo)
1182 1182
  label_any_open_issues: any open issues
1183 1183
  label_no_open_issues: no open issues
1184 1184
  label_default_values_for_new_users: Default values for new users
1185
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/mn.yml (copia de trabajo)
1183 1183
  label_any_open_issues: any open issues
1184 1184
  label_no_open_issues: no open issues
1185 1185
  label_default_values_for_new_users: Default values for new users
1186
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/nl.yml (copia de trabajo)
1161 1161
  label_any_open_issues: any open issues
1162 1162
  label_no_open_issues: no open issues
1163 1163
  label_default_values_for_new_users: Default values for new users
1164
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/no.yml (copia de trabajo)
1172 1172
  label_any_open_issues: any open issues
1173 1173
  label_no_open_issues: no open issues
1174 1174
  label_default_values_for_new_users: Default values for new users
1175
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/pl.yml (copia de trabajo)
1197 1197
  label_any_open_issues: any open issues
1198 1198
  label_no_open_issues: no open issues
1199 1199
  label_default_values_for_new_users: Default values for new users
1200
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/pt-BR.yml (copia de trabajo)
1201 1201
  label_any_open_issues: any open issues
1202 1202
  label_no_open_issues: no open issues
1203 1203
  label_default_values_for_new_users: Default values for new users
1204
  error_ldap_bind_credentials: Conta/Palavra-chave do LDAP não é válida
config/locales/pt.yml (copia de trabajo)
1184 1184
  label_any_open_issues: any open issues
1185 1185
  label_no_open_issues: no open issues
1186 1186
  label_default_values_for_new_users: Default values for new users
1187
  error_ldap_bind_credentials: Conta/Palavra-chave do LDAP não é válida
config/locales/ro.yml (copia de trabajo)
1177 1177
  label_any_open_issues: any open issues
1178 1178
  label_no_open_issues: no open issues
1179 1179
  label_default_values_for_new_users: Default values for new users
1180
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/ru.yml (copia de trabajo)
1285 1285
  label_any_open_issues: any open issues
1286 1286
  label_no_open_issues: no open issues
1287 1287
  label_default_values_for_new_users: Default values for new users
1288
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/sk.yml (copia de trabajo)
1172 1172
  label_any_open_issues: any open issues
1173 1173
  label_no_open_issues: no open issues
1174 1174
  label_default_values_for_new_users: Default values for new users
1175
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/sl.yml (copia de trabajo)
1182 1182
  label_any_open_issues: any open issues
1183 1183
  label_no_open_issues: no open issues
1184 1184
  label_default_values_for_new_users: Default values for new users
1185
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/sq.yml (copia de trabajo)
1178 1178
  label_any_open_issues: any open issues
1179 1179
  label_no_open_issues: no open issues
1180 1180
  label_default_values_for_new_users: Default values for new users
1181
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/sr-YU.yml (copia de trabajo)
1184 1184
  label_any_open_issues: any open issues
1185 1185
  label_no_open_issues: no open issues
1186 1186
  label_default_values_for_new_users: Default values for new users
1187
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/sr.yml (copia de trabajo)
1183 1183
  label_any_open_issues: any open issues
1184 1184
  label_no_open_issues: no open issues
1185 1185
  label_default_values_for_new_users: Default values for new users
1186
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/sv.yml (copia de trabajo)
1215 1215
  label_any_open_issues: any open issues
1216 1216
  label_no_open_issues: no open issues
1217 1217
  label_default_values_for_new_users: Default values for new users
1218
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/th.yml (copia de trabajo)
1179 1179
  label_any_open_issues: any open issues
1180 1180
  label_no_open_issues: no open issues
1181 1181
  label_default_values_for_new_users: Default values for new users
1182
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/tr.yml (copia de trabajo)
1191 1191
  label_any_open_issues: any open issues
1192 1192
  label_no_open_issues: no open issues
1193 1193
  label_default_values_for_new_users: Default values for new users
1194
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/uk.yml (copia de trabajo)
1177 1177
  label_any_open_issues: any open issues
1178 1178
  label_no_open_issues: no open issues
1179 1179
  label_default_values_for_new_users: Default values for new users
1180
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/vi.yml (copia de trabajo)
1235 1235
  label_any_open_issues: any open issues
1236 1236
  label_no_open_issues: no open issues
1237 1237
  label_default_values_for_new_users: Default values for new users
1238
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/zh-TW.yml (copia de trabajo)
1256 1256
  description_date_to: 輸入結束日期
1257 1257
  text_repository_identifier_info: '僅允許使用小寫英文字母 (a-z), 阿拉伯數字, 虛線與底線。<br />一旦儲存之後, 代碼便無法再次被更改。'
1258 1258
  label_default_values_for_new_users: Default values for new users
1259
  error_ldap_bind_credentials: Invalid LDAP Account/Password
config/locales/zh.yml (copia de trabajo)
1179 1179
  label_any_open_issues: any open issues
1180 1180
  label_no_open_issues: no open issues
1181 1181
  label_default_values_for_new_users: Default values for new users
1182
  error_ldap_bind_credentials: Invalid LDAP Account/Password
test/unit/auth_source_ldap_test.rb (copia de trabajo)
24 24
  def setup
25 25
  end
26 26

  
27
  def test_initialize
28
    auth_source = AuthSourceLdap.new
29
    assert_nil auth_source.id
30
    assert_equal "AuthSourceLdap", auth_source.type
31
    assert_equal "", auth_source.name
32
    assert_nil auth_source.host
33
    assert_nil auth_source.port
34
    assert_nil auth_source.account
35
    assert_equal "", auth_source.account_password
36
    assert_nil auth_source.base_dn
37
    assert_nil auth_source.attr_login
38
    assert_nil auth_source.attr_firstname
39
    assert_nil auth_source.attr_lastname
40
    assert_nil auth_source.attr_mail
41
    assert_equal false, auth_source.onthefly_register
42
    assert_equal false, auth_source.tls
43
    assert_nil auth_source.filter
44
    assert_nil auth_source.timeout
45
  end
46

  
27 47
  def test_create
28 48
    a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName')
29 49
    assert a.save
......
135 155
      results = AuthSource.search("exa")
136 156
      assert_equal [], results
137 157
    end
158

  
159
    def test_ldap_with_correct_host
160
      auth_source = AuthSourceLdap.find(1)
161

  
162
      assert_equal "127.0.0.1", auth_source.host
163
      assert_equal 389, auth_source.port
164
      assert_nothing_raised Net::LDAP::Error do
165
        auth_source.test_connection
166
      end
167
    end
168

  
169
    def test_ldap_with_incorrect_host
170
      auth_source = AuthSourceLdap.find(1)
171
      auth_source.host = "badhost"
172
      auth_source.save!
173

  
174
      assert_equal "badhost", auth_source.host
175
      assert_equal 389, auth_source.port
176
      assert_raise Net::LDAP::Error do
177
        auth_source.test_connection
178
      end
179
    end
180

  
181
    def test_ldap_with_correct_port
182
      auth_source = AuthSourceLdap.find(1)
183

  
184
      assert_equal "127.0.0.1", auth_source.host
185
      assert_equal 389, auth_source.port
186
      assert_nothing_raised Net::LDAP::Error do
187
        auth_source.test_connection
188
      end
189
    end
190

  
191
    def test_ldap_with_incorrect_port
192
      auth_source = AuthSourceLdap.find(1)
193
      auth_source.port = 1234
194
      auth_source.save!
195

  
196
      assert_equal "127.0.0.1", auth_source.host
197
      assert_equal 1234, auth_source.port
198
      assert_raise Net::LDAP::Error do
199
        auth_source.test_connection
200
      end
201
    end
202

  
203
    def test_ldap_bind_with_account_and_password
204
      auth_source = AuthSourceLdap.find(1)
205
      auth_source.account = "cn=Manager,dc=redmine,dc=org"
206
      auth_source.account_password = "secret"
207
      auth_source.save!
208

  
209
      assert_equal "127.0.0.1", auth_source.host
210
      assert_equal 389, auth_source.port
211
      assert_equal "cn=Manager,dc=redmine,dc=org", auth_source.account
212
      assert_equal "secret", auth_source.account_password
213
      assert_nil auth_source.test_connection
214
    end
215

  
216
    def test_ldap_bind_without_account_and_password
217
      auth_source = AuthSourceLdap.find(1)
218

  
219
      assert_equal "127.0.0.1", auth_source.host
220
      assert_equal 389, auth_source.port
221
      assert_nil auth_source.account
222
      assert_equal "", auth_source.account_password
223
      assert_nil auth_source.test_connection
224
    end
225

  
226
    def test_ldap_bind_with_incorrect_account
227
      auth_source = AuthSourceLdap.find(1)
228
      auth_source.account = "cn=baduser,dc=redmine,dc=org"
229
      auth_source.account_password = "secret"
230
      auth_source.save!
231

  
232
      assert_equal "127.0.0.1", auth_source.host
233
      assert_equal 389, auth_source.port
234
      assert_equal "cn=baduser,dc=redmine,dc=org", auth_source.account
235
      assert_equal "secret", auth_source.account_password
236
      assert_raise AuthSourceException do
237
        auth_source.test_connection
238
      end
239
    end
240

  
241
    def test_ldap_bind_with_incorrect_password
242
      auth_source = AuthSourceLdap.find(1)
243
      auth_source.account = "cn=Manager,dc=redmine,dc=org"
244
      auth_source.account_password = "badpassword"
245
      auth_source.save!
246

  
247
      assert_equal "127.0.0.1", auth_source.host
248
      assert_equal 389, auth_source.port
249
      assert_equal "cn=Manager,dc=redmine,dc=org", auth_source.account
250
      assert_equal "badpassword", auth_source.account_password
251
      assert_raise AuthSourceException do
252
        auth_source.test_connection
253
      end
254
    end
138 255
  else
139 256
    puts '(Test LDAP server not configured)'
140 257
  end
(4-4/4)