casino 3.0.0.pre.1 → 3.0.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,10 @@ class CASino::ApplicationController < ::ApplicationController
7
7
  layout 'application'
8
8
  before_filter :set_locale
9
9
 
10
+ unless Rails.env.development?
11
+ rescue_from ActionView::MissingTemplate, with: :missing_template
12
+ end
13
+
10
14
  def cookies
11
15
  super
12
16
  end
@@ -31,4 +35,8 @@ class CASino::ApplicationController < ::ApplicationController
31
35
  def http_accept_language
32
36
  HttpAcceptLanguage::Parser.new request.env['HTTP_ACCEPT_LANGUAGE']
33
37
  end
38
+
39
+ def missing_template(exception)
40
+ render plain: 'Format not supported', status: :not_acceptable
41
+ end
34
42
  end
@@ -19,7 +19,12 @@ class CASino::LoginCredentialRequestorProcessor < CASino::Processor
19
19
  @params = params || {}
20
20
  @cookies = cookies || {}
21
21
  @user_agent = user_agent || {}
22
- if check_service_allowed
22
+ begin
23
+ @service_url = clean_service_url(@params[:service]) unless @params[:service].nil?
24
+ rescue Addressable::URI::InvalidURIError => e
25
+ Rails.logger.warn "Service #{@params[:service]} not valid: #{e}"
26
+ end
27
+ if service_allowed?
23
28
  handle_allowed_service
24
29
  end
25
30
  end
@@ -34,8 +39,8 @@ class CASino::LoginCredentialRequestorProcessor < CASino::Processor
34
39
  end
35
40
 
36
41
  def handle_logged_in
37
- service_url_with_ticket = unless @params[:service].nil?
38
- acquire_service_ticket(@ticket_granting_ticket, @params[:service], true).service_with_ticket_url
42
+ service_url_with_ticket = unless @service_url.nil?
43
+ acquire_service_ticket(@ticket_granting_ticket, @service_url, true).service_with_ticket_url
39
44
  end
40
45
  @listener.user_logged_in(service_url_with_ticket)
41
46
  end
@@ -43,24 +48,23 @@ class CASino::LoginCredentialRequestorProcessor < CASino::Processor
43
48
  def handle_not_logged_in
44
49
  if gateway_request?
45
50
  # we actually lie to the listener to simplify things
46
- @listener.user_logged_in(@params[:service])
51
+ @listener.user_logged_in(@service_url)
47
52
  else
48
53
  login_ticket = acquire_login_ticket
49
54
  @listener.user_not_logged_in(login_ticket)
50
55
  end
51
56
  end
52
57
 
53
- def check_service_allowed
54
- service_url = clean_service_url(@params[:service]) unless @params[:service].nil?
55
- if service_url.nil? || CASino::ServiceRule.allowed?(service_url)
58
+ def service_allowed?
59
+ if @service_url.nil? || CASino::ServiceRule.allowed?(@service_url)
56
60
  true
57
61
  else
58
- @listener.service_not_allowed(service_url)
62
+ @listener.service_not_allowed(@service_url)
59
63
  false
60
64
  end
61
65
  end
62
66
 
63
67
  def gateway_request?
64
- @params[:gateway] == 'true' && @params[:service]
68
+ @params[:gateway] == 'true' && @service_url
65
69
  end
66
70
  end
@@ -0,0 +1,32 @@
1
+ require 'terminal-table'
2
+
3
+ namespace :casino do
4
+ namespace :user do
5
+ desc 'Search users by name.'
6
+ task :search, [:query] => :environment do |task, args|
7
+ users = CASino::User.where('username LIKE ?', "%#{args[:query]}%")
8
+ if users.any?
9
+ headers = ['User ID', 'Username', 'Authenticator', 'Two-factor authentication enabled?']
10
+ table = Terminal::Table.new :headings => headers do |t|
11
+ users.each do |user|
12
+ two_factor_enabled = user.active_two_factor_authenticator ? 'yes' : 'no'
13
+ t.add_row [user.id, user.username, user.authenticator, two_factor_enabled]
14
+ end
15
+ end
16
+ puts table
17
+ else
18
+ puts "No users found matching your query \"#{args[:query]}\"."
19
+ end
20
+ end
21
+
22
+ desc 'Deactivate two-factor authentication for a user.'
23
+ task :deactivate_two_factor_authentication, [:user_id] => :environment do |task, args|
24
+ if CASino::User.find(args[:user_id]).active_two_factor_authenticator
25
+ CASino::User.find(args[:user_id]).active_two_factor_authenticator.destroy
26
+ puts "Successfully deactivated two-factor authentication for user ##{args[:user_id]}."
27
+ else
28
+ puts "No two-factor authenticator found for user ##{args[:user_id]}."
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module CASino
2
- VERSION = '3.0.0.pre.1'
2
+ VERSION = '3.0.0.pre.2'
3
3
  end
@@ -6,6 +6,13 @@ describe CASino::SessionsController do
6
6
  CASino::LoginCredentialRequestorProcessor.any_instance.should_receive(:process)
7
7
  get :new, use_route: :casino
8
8
  end
9
+
10
+ context 'with an unsupported format' do
11
+ it 'sets the status code to 406' do
12
+ get :new, use_route: :casino, format: :xml
13
+ response.status.should == 406
14
+ end
15
+ end
9
16
  end
10
17
 
11
18
  describe 'POST "create"' do
@@ -40,7 +40,7 @@ describe CASino::ServiceRule do
40
40
  it 'does not take too long to check a denied service' do
41
41
  start = Time.now
42
42
  described_class.allowed?(service_url).should == false
43
- (Time.now - start).should < 0.1
43
+ (Time.now - start).should < 1.0
44
44
  end
45
45
  end
46
46
 
@@ -109,6 +109,16 @@ describe CASino::LoginCredentialRequestorProcessor do
109
109
  end
110
110
  end
111
111
 
112
+ context 'with a broken service' do
113
+ let(:service) { '%3Atest' }
114
+ let(:params) { { service: service } }
115
+
116
+ it 'calls the #user_logged_in method on the listener' do
117
+ listener.should_receive(:user_logged_in).with(nil)
118
+ processor.process(params, cookies, user_agent)
119
+ end
120
+ end
121
+
112
122
  context 'without a service' do
113
123
  it 'calls the #user_logged_in method on the listener' do
114
124
  listener.should_receive(:user_logged_in).with(nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casino
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre.1
4
+ version: 3.0.0.pre.2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-04-17 00:00:00.000000000 Z
14
+ date: 2014-05-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: capybara
@@ -299,7 +299,7 @@ files:
299
299
  - app/assets/javascripts/casino/sessions.js
300
300
  - app/assets/stylesheets/casino.scss
301
301
  - app/assets/stylesheets/casino/icons.scss
302
- - app/assets/stylesheets/casino/normalize.css
302
+ - app/assets/stylesheets/casino/normalize.scss
303
303
  - app/authenticators/casino/static_authenticator.rb
304
304
  - app/builders/casino/ticket_validation_response_builder.rb
305
305
  - app/controllers/casino/api/v1/tickets_controller.rb
@@ -397,6 +397,7 @@ files:
397
397
  - lib/casino/tasks.rb
398
398
  - lib/casino/tasks/cleanup.rake
399
399
  - lib/casino/tasks/service_rule.rake
400
+ - lib/casino/tasks/user.rake
400
401
  - lib/casino/version.rb
401
402
  - lib/generators/casino/install/USAGE
402
403
  - lib/generators/casino/install/install_generator.rb