Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Disable validations of devise's validatable module in LDAP setups
Browse files Browse the repository at this point in the history
Signed-off-by: Bartholomaeus Gillner <bartholomaeus@gmail.com>
  • Loading branch information
BBBernsteyn committed Sep 28, 2016
1 parent adb3ae9 commit 381fd61
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
class User < ActiveRecord::Base
include PublicActivity::Common

devise :database_authenticatable, :registerable, :lockable,
:recoverable, :rememberable, :trackable, :validatable, authentication_keys: [:username]
enabled_devise_modules = [:database_authenticatable, :registerable, :lockable,
:recoverable, :rememberable, :trackable, :validatable,
authentication_keys: [:username]]

enabled_devise_modules.delete(:validatable) if Portus::LDAP.enabled?
devise(*enabled_devise_modules)

APPLICATION_TOKENS_MAX = 5

Expand Down
23 changes: 23 additions & 0 deletions spec/features/auth/login_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@
expect(page).to_not have_content("The first user to be created will have admin permissions !")
end

scenario "Skips validation of minimum password length when authenticating via LDAP" do
APP_CONFIG["ldap"] = { "enabled" => true }

# Skipping validation for LDAP users is configured when the user model is first interpreted
# Use a clean room to guard against side effects
module CleanRoom
# rubocop:disable Lint/Eval
eval File.read(File.join(Rails.root, "app", "models", "user.rb"))
# rubocop:enable Lint/Eval
end

ldap_user = CleanRoom::User.first
ldap_user.password = "short"
expect(ldap_user.save).to eql(true)

fill_in "user_username", with: ldap_user.username
fill_in "user_password", with: ldap_user.password
click_button "Login"

expect(page).to have_content("Recent activities")
expect(page).to have_content("Repositories")
end

scenario "Existing user is able using his login and password to login into Portus", js: true do
expect(page).to_not have_content("Invalid username or password")

Expand Down

0 comments on commit 381fd61

Please sign in to comment.