Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Add rake task to test authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
pencil committed Oct 1, 2014
1 parent c2f9a0d commit bf71cbb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/processors/casino/processor_concern/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions lib/casino/tasks/authentication.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bf71cbb

Please sign in to comment.