From bf71cbb5866bc79eb742f1e9e3d3c72977d730fc Mon Sep 17 00:00:00 2001 From: Nils Caspar Date: Wed, 1 Oct 2014 20:04:29 +0200 Subject: [PATCH] Add rake task to test authentication --- .../processor_concern/authentication.rb | 4 +-- lib/casino/tasks/authentication.rake | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 lib/casino/tasks/authentication.rake diff --git a/app/processors/casino/processor_concern/authentication.rb b/app/processors/casino/processor_concern/authentication.rb index 125f1c88..28443ed6 100644 --- a/app/processors/casino/processor_concern/authentication.rb +++ b/app/processors/casino/processor_concern/authentication.rb @@ -21,7 +21,7 @@ def validate_login_credentials(username, password) def authenticators @authenticators ||= begin - CASino.config.authenticators.each do |name, auth| + CASino.config[:authenticators].each do |name, auth| next unless auth.is_a?(Hash) authenticator = if auth[:class] @@ -30,7 +30,7 @@ def authenticators load_authenticator(auth[:authenticator]) end - CASino.config.authenticators[name] = authenticator.new(auth[:options]) + CASino.config[:authenticators][name] = authenticator.new(auth[:options]) end end end diff --git a/lib/casino/tasks/authentication.rake b/lib/casino/tasks/authentication.rake new file mode 100644 index 00000000..b49efafa --- /dev/null +++ b/lib/casino/tasks/authentication.rake @@ -0,0 +1,29 @@ +require 'io/console' + +namespace :casino do + namespace :authentication do + desc 'Test authentication.' + task test: :environment do |task, args| + include CASino::ProcessorConcern::Authentication + print "Username: " + username = STDIN.gets.chomp + print "Password (won't be shown): " + password = STDIN.noecho(&:gets).chomp + 2.times { puts } + puts "Testing credentials against #{authenticators.length} authenticators" + authenticators.each do |authenticator_name, authenticator| + puts "'#{authenticator_name}' (#{authenticator.class}):" + print ' ' + begin + if data = authenticator.validate(username, password) + p data + else + puts "Invalid credentials" + end + rescue CASino::Authenticator::AuthenticatorError => e + puts "#{e}" + end + end + end + end +end