@@ -404,24 +404,6 class UserTest < ActiveSupport::TestCase | |||||
404 | assert_not_nil u.errors[:mail_notification] |
|
404 | assert_not_nil u.errors[:mail_notification] | |
405 | end |
|
405 | end | |
406 |
|
406 | |||
407 | test "User#try_to_login should fall-back to case-insensitive if user login is not found as-typed" do |
|
|||
408 | user = User.try_to_login("AdMin", "admin") |
|
|||
409 | assert_kind_of User, user |
|
|||
410 | assert_equal "admin", user.login |
|
|||
411 | end |
|
|||
412 |
|
||||
413 | test "User#try_to_login should select the exact matching user first" do |
|
|||
414 | case_sensitive_user = User.generate! do |user| |
|
|||
415 | user.password = "admin123" |
|
|||
416 | end |
|
|||
417 | # bypass validations to make it appear like existing data |
|
|||
418 | case_sensitive_user.update_attribute(:login, 'ADMIN') |
|
|||
419 |
|
||||
420 | user = User.try_to_login("ADMIN", "admin123") |
|
|||
421 | assert_kind_of User, user |
|
|||
422 | assert_equal "ADMIN", user.login |
|
|||
423 | end |
|
|||
424 |
|
||||
425 | def test_password |
|
407 | def test_password | |
426 | user = User.try_to_login("admin", "admin") |
|
408 | user = User.try_to_login("admin", "admin") | |
427 | assert_kind_of User, user |
|
409 | assert_kind_of User, user | |
@@ -513,25 +495,48 class UserTest < ActiveSupport::TestCase | |||||
513 | end |
|
495 | end | |
514 | end |
|
496 | end | |
515 |
|
497 | |||
516 | def test_lock |
|
498 | test ".try_to_login with good credentials should return the user" do | |
517 |
user = User.try_to_login(" |
|
499 | user = User.try_to_login("admin", "admin") | |
518 |
assert_ |
|
500 | assert_kind_of User, user | |
|
501 | assert_equal "admin", user.login | |||
|
502 | end | |||
519 |
|
503 | |||
|
504 | test ".try_to_login with wrong credentials should return nil" do | |||
|
505 | assert_nil User.try_to_login("admin", "foo") | |||
|
506 | end | |||
|
507 | ||||
|
508 | def test_try_to_login_with_locked_user_should_return_nil | |||
520 | @jsmith.status = User::STATUS_LOCKED |
|
509 | @jsmith.status = User::STATUS_LOCKED | |
521 |
|
|
510 | @jsmith.save! | |
522 |
|
511 | |||
523 | user = User.try_to_login("jsmith", "jsmith") |
|
512 | user = User.try_to_login("jsmith", "jsmith") | |
524 | assert_equal nil, user |
|
513 | assert_equal nil, user | |
525 | end |
|
514 | end | |
526 |
|
515 | |||
527 |
|
|
516 | def test_try_to_login_with_locked_user_and_not_active_only_should_return_user | |
528 | user = User.try_to_login("admin", "admin") |
|
517 | @jsmith.status = User::STATUS_LOCKED | |
|
518 | @jsmith.save! | |||
|
519 | ||||
|
520 | user = User.try_to_login("jsmith", "jsmith", false) | |||
|
521 | assert_equal @jsmith, user | |||
|
522 | end | |||
|
523 | ||||
|
524 | test ".try_to_login should fall-back to case-insensitive if user login is not found as-typed" do | |||
|
525 | user = User.try_to_login("AdMin", "admin") | |||
529 | assert_kind_of User, user |
|
526 | assert_kind_of User, user | |
530 | assert_equal "admin", user.login |
|
527 | assert_equal "admin", user.login | |
531 | end |
|
528 | end | |
532 |
|
529 | |||
533 | test ".try_to_login with wrong credentials should return nil" do |
|
530 | test ".try_to_login should select the exact matching user first" do | |
534 | assert_nil User.try_to_login("admin", "foo") |
|
531 | case_sensitive_user = User.generate! do |user| | |
|
532 | user.password = "admin123" | |||
|
533 | end | |||
|
534 | # bypass validations to make it appear like existing data | |||
|
535 | case_sensitive_user.update_attribute(:login, 'ADMIN') | |||
|
536 | ||||
|
537 | user = User.try_to_login("ADMIN", "admin123") | |||
|
538 | assert_kind_of User, user | |||
|
539 | assert_equal "ADMIN", user.login | |||
535 | end |
|
540 | end | |
536 |
|
541 | |||
537 | if ldap_configured? |
|
542 | if ldap_configured? |
General Comments 0
You need to be logged in to leave comments.
Login now