casino 1.3.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +1 -1
  4. data/README.md +1 -8
  5. data/Rakefile +0 -2
  6. data/app/assets/javascripts/casino/application.js +1 -0
  7. data/app/assets/javascripts/casino/index.js +0 -2
  8. data/app/assets/javascripts/casino/sessions.js +32 -0
  9. data/app/authenticators/casino/static_authenticator.rb +23 -0
  10. data/app/builders/casino/ticket_validation_response_builder.rb +84 -0
  11. data/app/controllers/casino/api/v1/tickets_controller.rb +7 -4
  12. data/app/controllers/casino/application_controller.rb +2 -3
  13. data/{lib/casino/listener/legacy_validator.rb → app/listeners/casino/legacy_validator_listener.rb} +2 -2
  14. data/app/listeners/casino/listener.rb +16 -0
  15. data/{lib/casino/listener/login_credential_acceptor.rb → app/listeners/casino/login_credential_acceptor_listener.rb} +2 -2
  16. data/{lib/casino/listener/login_credential_requestor.rb → app/listeners/casino/login_credential_requestor_listener.rb} +2 -2
  17. data/{lib/casino/listener/logout.rb → app/listeners/casino/logout_listener.rb} +2 -2
  18. data/{lib/casino/listener/other_sessions_destroyer.rb → app/listeners/casino/other_sessions_destroyer_listener.rb} +2 -2
  19. data/{lib/casino/listener/proxy_ticket_provider.rb → app/listeners/casino/proxy_ticket_provider_listener.rb} +2 -2
  20. data/{lib/casino/listener/second_factor_authentication_acceptor.rb → app/listeners/casino/second_factor_authentication_acceptor_listener.rb} +2 -2
  21. data/{lib/casino/listener/session_destroyer.rb → app/listeners/casino/session_destroyer_listener.rb} +2 -2
  22. data/{lib/casino/listener/session_overview.rb → app/listeners/casino/session_overview_listener.rb} +2 -2
  23. data/{lib/casino/listener/ticket_validator.rb → app/listeners/casino/ticket_validator_listener.rb} +2 -2
  24. data/{lib/casino/listener/two_factor_authenticator_activator.rb → app/listeners/casino/two_factor_authenticator_activator_listener.rb} +2 -2
  25. data/{lib/casino/listener/two_factor_authenticator_destroyer.rb → app/listeners/casino/two_factor_authenticator_destroyer_listener.rb} +2 -2
  26. data/{lib/casino/listener/two_factor_authenticator_overview.rb → app/listeners/casino/two_factor_authenticator_overview_listener.rb} +2 -2
  27. data/{lib/casino/listener/two_factor_authenticator_registrator.rb → app/listeners/casino/two_factor_authenticator_registrator_listener.rb} +2 -2
  28. data/app/models/casino/login_ticket.rb +12 -0
  29. data/app/models/casino/proxy_granting_ticket.rb +8 -0
  30. data/app/models/casino/proxy_ticket.rb +25 -0
  31. data/app/models/casino/service_rule.rb +27 -0
  32. data/app/models/casino/service_ticket.rb +43 -0
  33. data/app/models/casino/service_ticket/single_sign_out_notifier.rb +44 -0
  34. data/app/models/casino/ticket_granting_ticket.rb +57 -0
  35. data/app/models/casino/two_factor_authenticator.rb +18 -0
  36. data/app/models/casino/user.rb +12 -0
  37. data/app/models/casino/validation_result.rb +5 -0
  38. data/app/processors/casino/api/login_credential_acceptor_processor.rb +46 -0
  39. data/app/processors/casino/api/logout_processor.rb +17 -0
  40. data/app/processors/casino/api/service_ticket_provider_processor.rb +69 -0
  41. data/app/processors/casino/legacy_validator_processor.rb +19 -0
  42. data/app/processors/casino/login_credential_acceptor_processor.rb +63 -0
  43. data/app/processors/casino/login_credential_requestor_processor.rb +66 -0
  44. data/app/processors/casino/logout_processor.rb +23 -0
  45. data/app/processors/casino/other_sessions_destroyer_processor.rb +26 -0
  46. data/app/processors/casino/processor.rb +5 -0
  47. data/app/processors/casino/processor_concern/authentication.rb +87 -0
  48. data/app/processors/casino/processor_concern/browser.rb +14 -0
  49. data/app/processors/casino/processor_concern/login_tickets.rb +28 -0
  50. data/app/processors/casino/processor_concern/proxy_granting_tickets.rb +43 -0
  51. data/app/processors/casino/processor_concern/proxy_tickets.rb +56 -0
  52. data/app/processors/casino/processor_concern/service_tickets.rb +50 -0
  53. data/app/processors/casino/processor_concern/ticket_granting_tickets.rb +65 -0
  54. data/app/processors/casino/processor_concern/tickets.rb +17 -0
  55. data/app/processors/casino/processor_concern/two_factor_authenticators.rb +22 -0
  56. data/app/processors/casino/proxy_ticket_provider_processor.rb +41 -0
  57. data/app/processors/casino/proxy_ticket_validator_processor.rb +22 -0
  58. data/app/processors/casino/second_factor_authentication_acceptor_processor.rb +45 -0
  59. data/app/processors/casino/service_ticket_validator_processor.rb +46 -0
  60. data/app/processors/casino/session_destroyer_processor.rb +25 -0
  61. data/app/processors/casino/session_overview_processor.rb +21 -0
  62. data/app/processors/casino/two_factor_authenticator_activator_processor.rb +41 -0
  63. data/app/processors/casino/two_factor_authenticator_destroyer_processor.rb +33 -0
  64. data/app/processors/casino/two_factor_authenticator_overview_processor.rb +20 -0
  65. data/app/processors/casino/two_factor_authenticator_registrator_processor.rb +24 -0
  66. data/app/views/casino/application/_footer.html.erb +1 -1
  67. data/app/views/casino/sessions/new.html.erb +2 -1
  68. data/app/views/casino/sessions/validate_otp.html.erb +1 -1
  69. data/app/views/casino/two_factor_authenticators/new.html.erb +2 -2
  70. data/app/views/layouts/application.html.erb +1 -1
  71. data/casino.gemspec +9 -4
  72. data/db/migrate/20130809135400_create_core_schema.rb +117 -0
  73. data/db/migrate/20130809135401_rename_base_models.rb +101 -0
  74. data/db/migrate/20131022110146_cleanup_indexes.rb +27 -0
  75. data/db/migrate/20131022110246_fix_long_index_names.rb +12 -0
  76. data/db/migrate/20131022110346_change_service_to_text.rb +6 -0
  77. data/lib/casino.rb +47 -3
  78. data/lib/casino/authenticator.rb +9 -0
  79. data/lib/casino/engine.rb +26 -0
  80. data/lib/casino/inflections.rb +7 -0
  81. data/lib/casino/tasks.rb +1 -0
  82. data/lib/casino/tasks/cleanup.rake +59 -0
  83. data/lib/casino/tasks/service_rule.rake +49 -0
  84. data/lib/casino/version.rb +1 -1
  85. data/lib/generators/casino/install/USAGE +13 -0
  86. data/lib/generators/casino/install/install_generator.rb +47 -0
  87. data/lib/generators/casino/{templates → install/templates}/README +3 -4
  88. data/lib/generators/casino/{templates → install/templates}/cas.yml +2 -2
  89. data/lib/generators/casino/{templates → install/templates}/casino_and_overrides.scss +0 -0
  90. data/lib/generators/casino/templates/casino_core.rb +1 -1
  91. data/spec/authenticator/base_spec.rb +13 -0
  92. data/spec/authenticator/static_spec.rb +42 -0
  93. data/spec/controllers/api/v1/tickets_controller_spec.rb +15 -15
  94. data/spec/controllers/listener/legacy_validator_spec.rb +1 -1
  95. data/spec/controllers/listener/login_credential_acceptor_spec.rb +1 -1
  96. data/spec/controllers/listener/login_credential_requestor_spec.rb +1 -1
  97. data/spec/controllers/listener/logout_spec.rb +1 -1
  98. data/spec/controllers/listener/other_sessions_destroyer_spec.rb +1 -1
  99. data/spec/controllers/listener/proxy_ticket_provider_spec.rb +1 -1
  100. data/spec/controllers/listener/second_factor_authentication_acceptor_spec.rb +1 -1
  101. data/spec/controllers/listener/session_destroyer_spec.rb +1 -1
  102. data/spec/controllers/listener/session_overview_spec.rb +1 -1
  103. data/spec/controllers/listener/ticket_validator_spec.rb +1 -1
  104. data/spec/controllers/listener/two_factor_authenticator_activator_spec.rb +1 -1
  105. data/spec/controllers/listener/two_factor_authenticator_destroyer_spec.rb +1 -1
  106. data/spec/controllers/listener/two_factor_authenticator_overview_spec.rb +1 -1
  107. data/spec/controllers/listener/two_factor_authenticator_registrator_spec.rb +1 -1
  108. data/spec/controllers/proxy_tickets_controller_spec.rb +4 -4
  109. data/spec/controllers/service_tickets_controller_spec.rb +4 -4
  110. data/spec/controllers/sessions_controller_spec.rb +15 -15
  111. data/spec/controllers/two_factor_authenticators_controller_spec.rb +6 -6
  112. data/spec/dummy/app/assets/stylesheets/casino_and_overrides.scss +13 -0
  113. data/spec/dummy/config/cas.yml +11 -11
  114. data/spec/dummy/config/routes.rb +1 -2
  115. data/spec/dummy/db/migrate/20130910094259_create_base_models.casino.rb +95 -0
  116. data/spec/dummy/db/schema.rb +107 -0
  117. data/spec/model/login_ticket_spec.rb +23 -0
  118. data/spec/model/proxy_ticket_spec.rb +63 -0
  119. data/spec/model/service_rule_spec.rb +65 -0
  120. data/spec/model/service_ticket/single_sign_out_notifier_spec.rb +61 -0
  121. data/spec/model/service_ticket_spec.rb +124 -0
  122. data/spec/model/ticket_granting_ticket_spec.rb +204 -0
  123. data/spec/model/two_factor_authenticator_spec.rb +31 -0
  124. data/spec/processor/api/login_credential_acceptor_spec.rb +52 -0
  125. data/spec/processor/api/logout_spec.rb +34 -0
  126. data/spec/processor/api/service_ticket_provider_spec.rb +61 -0
  127. data/spec/processor/legacy_validator_spec.rb +78 -0
  128. data/spec/processor/login_credential_acceptor_spec.rb +164 -0
  129. data/spec/processor/login_credential_requestor_spec.rb +135 -0
  130. data/spec/processor/logout_other_sessions_spec.rb +53 -0
  131. data/spec/processor/logout_spec.rb +72 -0
  132. data/spec/processor/processor_concern/service_tickets_spec.rb +49 -0
  133. data/spec/processor/proxy_ticket_provider_spec.rb +66 -0
  134. data/spec/processor/proxy_ticket_validator_spec.rb +65 -0
  135. data/spec/processor/second_factor_authenticaton_acceptor_spec.rb +94 -0
  136. data/spec/processor/session_destroyer_spec.rb +75 -0
  137. data/spec/processor/session_overview_spec.rb +49 -0
  138. data/spec/processor/ticket_validator_spec.rb +199 -0
  139. data/spec/processor/two_factor_authenticator_activator_spec.rb +122 -0
  140. data/spec/processor/two_factor_authenticator_destroyer_spec.rb +71 -0
  141. data/spec/processor/two_factor_authenticator_overview_spec.rb +56 -0
  142. data/spec/processor/two_factor_authenticator_registrator_spec.rb +48 -0
  143. data/spec/spec_helper.rb +8 -19
  144. data/spec/support/casino.rb +12 -0
  145. data/spec/support/factories/login_ticket_factory.rb +16 -0
  146. data/spec/support/factories/proxy_granting_ticket_factory.rb +16 -0
  147. data/spec/support/factories/proxy_ticket_factory.rb +17 -0
  148. data/spec/support/factories/service_rule_factory.rb +16 -0
  149. data/spec/support/factories/service_ticket_factory.rb +17 -0
  150. data/spec/support/factories/ticket_granting_ticket_factory.rb +15 -0
  151. data/spec/support/factories/two_factor_authenticator_factory.rb +16 -0
  152. data/spec/support/factories/user_factory.rb +11 -0
  153. data/spec/support/rspec.rb +8 -0
  154. data/spec/support/sqlite3.rb +4 -0
  155. metadata +284 -48
  156. metadata.gz.sig +2 -0
  157. data/.powrc +0 -4
  158. data/Gemfile.lock +0 -149
  159. data/app/assets/javascripts/casino/application.js.coffee +0 -5
  160. data/app/assets/javascripts/casino/sessions.js.coffee +0 -15
  161. data/config/initializers/frontend_config.rb +0 -9
  162. data/config/initializers/inflections.rb +0 -19
  163. data/config/initializers/yaml.rb +0 -1
  164. data/lib/casino/listener.rb +0 -31
  165. data/lib/generators/casino/install_generator.rb +0 -35
  166. data/spec/dummy/config/initializers/casino_core.rb +0 -1
@@ -3,17 +3,17 @@ require 'spec_helper'
3
3
  describe CASino::TwoFactorAuthenticatorsController do
4
4
  describe 'GET "new"' do
5
5
  it 'calls the process method of the TwoFactorAuthenticatorRegistrator' do
6
- CASinoCore::Processor::TwoFactorAuthenticatorRegistrator.any_instance.should_receive(:process)
7
- get :new
6
+ CASino::TwoFactorAuthenticatorRegistratorProcessor.any_instance.should_receive(:process)
7
+ get :new, use_route: :casino
8
8
  end
9
9
  end
10
10
 
11
11
  describe 'POST "create"' do
12
12
  it 'calls the process method of the TwoFactorAuthenticatorActivator' do
13
- CASinoCore::Processor::TwoFactorAuthenticatorActivator.any_instance.should_receive(:process) do
13
+ CASino::TwoFactorAuthenticatorActivatorProcessor.any_instance.should_receive(:process) do
14
14
  @controller.render nothing: true
15
15
  end
16
- post :create
16
+ post :create, use_route: :casino
17
17
  end
18
18
  end
19
19
 
@@ -22,13 +22,13 @@ describe CASino::TwoFactorAuthenticatorsController do
22
22
  let(:tgt) { 'TGT-foobar' }
23
23
  it 'calls the process method of the TwoFactorAuthenticatorDestroyer processor' do
24
24
  request.cookies[:tgt] = tgt
25
- CASinoCore::Processor::TwoFactorAuthenticatorDestroyer.any_instance.should_receive(:process) do |params, cookies, user_agent|
25
+ CASino::TwoFactorAuthenticatorDestroyerProcessor.any_instance.should_receive(:process) do |params, cookies, user_agent|
26
26
  params[:id].should == id
27
27
  cookies[:tgt].should == tgt
28
28
  user_agent.should == request.user_agent
29
29
  @controller.render nothing: true
30
30
  end
31
- delete :destroy, id: id
31
+ delete :destroy, id:id, use_route: :casino
32
32
  end
33
33
  end
34
34
  end
@@ -0,0 +1,13 @@
1
+
2
+ // Default CASino settings
3
+
4
+ // $buttonColor: #0074ad;
5
+ // $buttonSecondaryColor: #c2c2c2;
6
+ // $linkColor: #0074ad;
7
+ // $logo: "logo.png";
8
+ // $logoRetina: "logo@2x.png";
9
+ // $logoWidth: 146px;
10
+ // $logoHeight: 34px;
11
+
12
+
13
+ @import 'casino';
@@ -7,23 +7,23 @@ defaults: &defaults
7
7
  proxy_ticket:
8
8
  lifetime_unconsumed: 300
9
9
  lifetime_consumed: 86400
10
-
11
- development:
12
- <<: *defaults
10
+ frontend:
11
+ sso_name: "CASino"
12
+ footer_text: "Powered by <a href=\"http://rbcas.com/\">CASino</a>"
13
13
  authenticators:
14
14
  static:
15
- class: "CASinoCore::Authenticator::Static"
15
+ class: "CASino::StaticAuthenticator"
16
16
  options:
17
17
  users:
18
18
  testuser:
19
19
  password: "foobar123"
20
+ name: "Test User"
21
+
22
+ development:
23
+ <<: *defaults
20
24
 
21
25
  test:
22
26
  <<: *defaults
23
- authenticators:
24
- static:
25
- class: "CASinoCore::Authenticator::Static"
26
- options:
27
- users:
28
- testuser:
29
- password: "foobar123"
27
+
28
+ production:
29
+ <<: *defaults
@@ -1,4 +1,3 @@
1
1
  Dummy::Application.routes.draw do
2
- mount CASino::Engine => '/', :as => 'CASino'
3
-
2
+ mount CASino::Engine => '/', :as => 'casino'
4
3
  end
@@ -0,0 +1,95 @@
1
+ # This migration comes from casino (originally 20130809135401)
2
+ class CreateBaseModels < ActiveRecord::Migration
3
+ def change
4
+ # Login Tickets
5
+ create_table :casino_login_tickets do |t|
6
+ t.string :ticket, :null => false
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :casino_login_tickets, :ticket, :unique => true
11
+
12
+ # Proxy Granting Tickets
13
+ create_table :casino_proxy_granting_tickets do |t|
14
+ t.string :ticket, :null => false
15
+ t.string :iou, :null => false
16
+ t.integer :granter_id, :null => false
17
+ t.string :pgt_url, :null => false
18
+ t.string :granter_type, :null => false
19
+
20
+ t.timestamps
21
+ end
22
+ add_index :casino_proxy_granting_tickets, :ticket, :unique => true
23
+ add_index :casino_proxy_granting_tickets, :iou, :unique => true
24
+ add_index :casino_proxy_granting_tickets, [:granter_type, :granter_id], :name => "index_casino_proxy_granting_tickets_on_granter", :unique => true
25
+
26
+ # Proxy Tickets
27
+ create_table :casino_proxy_tickets do |t|
28
+ t.string :ticket, :null => false
29
+ t.string :service, :null => false
30
+ t.boolean :consumed, :default => false, :null => false
31
+ t.integer :proxy_granting_ticket_id, :null => false
32
+
33
+ t.timestamps
34
+ end
35
+ add_index :casino_proxy_tickets, :ticket, :unique => true
36
+ add_index :casino_proxy_tickets, :proxy_granting_ticket_id
37
+
38
+ # Service Rules
39
+ create_table :casino_service_rules do |t|
40
+ t.boolean :enabled, :default => true, :null => false
41
+ t.integer :order, :default => 10, :null => false
42
+ t.string :name, :null => false
43
+ t.string :url, :null => false
44
+ t.boolean :regex, :default => false, :null => false
45
+
46
+ t.timestamps
47
+ end
48
+ add_index :casino_service_rules, :url, :unique => true
49
+
50
+ # Service Tickets
51
+ create_table :casino_service_tickets do |t|
52
+ t.string :ticket, :null => false
53
+ t.string :service, :null => false
54
+ t.integer :ticket_granting_ticket_id
55
+ t.boolean :consumed, :default => false, :null => false
56
+ t.boolean :issued_from_credentials, :default => false, :null => false
57
+
58
+ t.timestamps
59
+ end
60
+ add_index :casino_service_tickets, :ticket, :unique => true
61
+ add_index :casino_service_tickets, :ticket_granting_ticket_id
62
+
63
+ # Ticket Granting Tickets
64
+ create_table :casino_ticket_granting_tickets do |t|
65
+ t.string :ticket, :null => false
66
+ t.string :user_agent
67
+ t.integer :user_id, :null => false
68
+ t.boolean :awaiting_two_factor_authentication, :default => false, :null => false
69
+ t.boolean :long_term, :default => false, :null => false
70
+
71
+ t.timestamps
72
+ end
73
+ add_index :casino_ticket_granting_tickets, :ticket, :unique => true
74
+
75
+ # Two Factor Authenticators
76
+ create_table :casino_two_factor_authenticators do |t|
77
+ t.integer :user_id, :null => false
78
+ t.string :secret, :null => false
79
+ t.boolean :active, :default => false, :null => false
80
+
81
+ t.timestamps
82
+ end
83
+ add_index :casino_two_factor_authenticators, :user_id
84
+
85
+ # Users
86
+ create_table :casino_users do |t|
87
+ t.string :authenticator, :null => false
88
+ t.string :username, :null => false
89
+ t.text :extra_attributes
90
+
91
+ t.timestamps
92
+ end
93
+ add_index :casino_users, [:authenticator, :username], :unique => true
94
+ end
95
+ end
@@ -0,0 +1,107 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20130910094259) do
15
+
16
+ create_table "casino_login_tickets", :force => true do |t|
17
+ t.string "ticket", :null => false
18
+ t.datetime "created_at", :null => false
19
+ t.datetime "updated_at", :null => false
20
+ end
21
+
22
+ add_index "casino_login_tickets", ["ticket"], :name => "index_casino_login_tickets_on_ticket", :unique => true
23
+
24
+ create_table "casino_proxy_granting_tickets", :force => true do |t|
25
+ t.string "ticket", :null => false
26
+ t.string "iou", :null => false
27
+ t.integer "granter_id", :null => false
28
+ t.string "pgt_url", :null => false
29
+ t.string "granter_type", :null => false
30
+ t.datetime "created_at", :null => false
31
+ t.datetime "updated_at", :null => false
32
+ end
33
+
34
+ add_index "casino_proxy_granting_tickets", ["granter_type", "granter_id"], :name => "index_casino_proxy_granting_tickets_on_granter", :unique => true
35
+ add_index "casino_proxy_granting_tickets", ["iou"], :name => "index_casino_proxy_granting_tickets_on_iou", :unique => true
36
+ add_index "casino_proxy_granting_tickets", ["ticket"], :name => "index_casino_proxy_granting_tickets_on_ticket", :unique => true
37
+
38
+ create_table "casino_proxy_tickets", :force => true do |t|
39
+ t.string "ticket", :null => false
40
+ t.string "service", :null => false
41
+ t.boolean "consumed", :default => false, :null => false
42
+ t.integer "proxy_granting_ticket_id", :null => false
43
+ t.datetime "created_at", :null => false
44
+ t.datetime "updated_at", :null => false
45
+ end
46
+
47
+ add_index "casino_proxy_tickets", ["proxy_granting_ticket_id"], :name => "index_casino_proxy_tickets_on_proxy_granting_ticket_id"
48
+ add_index "casino_proxy_tickets", ["ticket"], :name => "index_casino_proxy_tickets_on_ticket", :unique => true
49
+
50
+ create_table "casino_service_rules", :force => true do |t|
51
+ t.boolean "enabled", :default => true, :null => false
52
+ t.integer "order", :default => 10, :null => false
53
+ t.string "name", :null => false
54
+ t.string "url", :null => false
55
+ t.boolean "regex", :default => false, :null => false
56
+ t.datetime "created_at", :null => false
57
+ t.datetime "updated_at", :null => false
58
+ end
59
+
60
+ add_index "casino_service_rules", ["url"], :name => "index_casino_service_rules_on_url", :unique => true
61
+
62
+ create_table "casino_service_tickets", :force => true do |t|
63
+ t.string "ticket", :null => false
64
+ t.string "service", :null => false
65
+ t.integer "ticket_granting_ticket_id"
66
+ t.boolean "consumed", :default => false, :null => false
67
+ t.boolean "issued_from_credentials", :default => false, :null => false
68
+ t.datetime "created_at", :null => false
69
+ t.datetime "updated_at", :null => false
70
+ end
71
+
72
+ add_index "casino_service_tickets", ["ticket"], :name => "index_casino_service_tickets_on_ticket", :unique => true
73
+ add_index "casino_service_tickets", ["ticket_granting_ticket_id"], :name => "index_casino_service_tickets_on_ticket_granting_ticket_id"
74
+
75
+ create_table "casino_ticket_granting_tickets", :force => true do |t|
76
+ t.string "ticket", :null => false
77
+ t.string "user_agent"
78
+ t.integer "user_id", :null => false
79
+ t.boolean "awaiting_two_factor_authentication", :default => false, :null => false
80
+ t.boolean "long_term", :default => false, :null => false
81
+ t.datetime "created_at", :null => false
82
+ t.datetime "updated_at", :null => false
83
+ end
84
+
85
+ add_index "casino_ticket_granting_tickets", ["ticket"], :name => "index_casino_ticket_granting_tickets_on_ticket", :unique => true
86
+
87
+ create_table "casino_two_factor_authenticators", :force => true do |t|
88
+ t.integer "user_id", :null => false
89
+ t.string "secret", :null => false
90
+ t.boolean "active", :default => false, :null => false
91
+ t.datetime "created_at", :null => false
92
+ t.datetime "updated_at", :null => false
93
+ end
94
+
95
+ add_index "casino_two_factor_authenticators", ["user_id"], :name => "index_casino_two_factor_authenticators_on_user_id"
96
+
97
+ create_table "casino_users", :force => true do |t|
98
+ t.string "authenticator", :null => false
99
+ t.string "username", :null => false
100
+ t.text "extra_attributes"
101
+ t.datetime "created_at", :null => false
102
+ t.datetime "updated_at", :null => false
103
+ end
104
+
105
+ add_index "casino_users", ["authenticator", "username"], :name => "index_casino_users_on_authenticator_and_username", :unique => true
106
+
107
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe CASino::LoginTicket do
4
+ describe '.cleanup' do
5
+ it 'deletes expired login tickets' do
6
+ ticket = described_class.new ticket: 'LT-12345'
7
+ ticket.save!
8
+ ticket.created_at = 10.hours.ago
9
+ ticket.save!
10
+ lambda do
11
+ described_class.cleanup
12
+ end.should change(described_class, :count).by(-1)
13
+ described_class.find_by_ticket('LT-12345').should be_false
14
+ end
15
+ end
16
+
17
+ describe '#to_s' do
18
+ it 'returns the ticket identifier' do
19
+ ticket = described_class.new ticket: 'LT-12345'
20
+ "#{ticket}".should == ticket.ticket
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe CASino::ProxyTicket do
4
+ let(:unconsumed_ticket) {
5
+ ticket = described_class.new ticket: 'PT-12345', service: 'any_string_is_valid'
6
+ ticket.proxy_granting_ticket_id = 1
7
+ ticket
8
+ }
9
+ let(:consumed_ticket) {
10
+ ticket = described_class.new ticket: 'PT-54321', service: 'any_string_is_valid'
11
+ ticket.proxy_granting_ticket_id = 1
12
+ ticket.consumed = true
13
+ ticket.save!
14
+ ticket
15
+ }
16
+
17
+ describe '#expired?' do
18
+ [:unconsumed, :consumed].each do |state|
19
+ context "with an #{state} ticket" do
20
+ let(:ticket) { send("#{state}_ticket") }
21
+
22
+ context 'with an expired ticket' do
23
+ before(:each) do
24
+ ticket.created_at = (CASino.config.service_ticket[:"lifetime_#{state}"].seconds + 1).ago
25
+ ticket.save!
26
+ end
27
+
28
+ it 'returns true' do
29
+ ticket.expired?.should == true
30
+ end
31
+ end
32
+
33
+ context 'with an unexpired ticket' do
34
+ it 'returns false' do
35
+ ticket.expired?.should == false
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '.cleanup_unconsumed' do
43
+ it 'deletes expired unconsumed service tickets' do
44
+ unconsumed_ticket.created_at = 10.hours.ago
45
+ unconsumed_ticket.save!
46
+ lambda do
47
+ described_class.cleanup_unconsumed
48
+ end.should change(described_class, :count).by(-1)
49
+ described_class.find_by_ticket('PT-12345').should be_false
50
+ end
51
+ end
52
+
53
+ describe '.cleanup_consumed' do
54
+ it 'deletes expired consumed service tickets' do
55
+ consumed_ticket.created_at = 10.days.ago
56
+ consumed_ticket.save!
57
+ lambda do
58
+ described_class.cleanup_consumed
59
+ end.should change(described_class, :count).by(-1)
60
+ described_class.find_by_ticket('PT-12345').should be_false
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe CASino::ServiceRule do
4
+ describe '.allowed?' do
5
+ context 'with an empty table' do
6
+ ['https://www.example.org/', 'http://www.google.com/'].each do |service_url|
7
+ it "allows access to #{service_url}" do
8
+ described_class.allowed?(service_url).should == true
9
+ end
10
+ end
11
+ end
12
+
13
+ context 'with a regex rule' do
14
+ before(:each) do
15
+ FactoryGirl.create :service_rule, :regex, url: '^https://.*'
16
+ end
17
+
18
+ ['https://www.example.org/', 'https://www.google.com/'].each do |service_url|
19
+ it "allows access to #{service_url}" do
20
+ described_class.allowed?(service_url).should == true
21
+ end
22
+ end
23
+
24
+ ['http://www.example.org/', 'http://www.google.com/'].each do |service_url|
25
+ it "does not allow access to #{service_url}" do
26
+ described_class.allowed?(service_url).should == false
27
+ end
28
+ end
29
+ end
30
+
31
+ context 'with many regex rules' do
32
+ before(:each) do
33
+ 100.times do |counter|
34
+ FactoryGirl.create :service_rule, :regex, url: "^https://www#{counter}.example.com"
35
+ end
36
+ end
37
+
38
+ let(:service_url) { 'https://www111.example.com/bla' }
39
+
40
+ it 'does not take too long to check a denied service' do
41
+ start = Time.now
42
+ described_class.allowed?(service_url).should == false
43
+ (Time.now - start).should < 0.1
44
+ end
45
+ end
46
+
47
+ context 'with a non-regex rule' do
48
+ before(:each) do
49
+ FactoryGirl.create :service_rule, url: 'https://www.google.com/foo'
50
+ end
51
+
52
+ ['https://www.google.com/foo'].each do |service_url|
53
+ it "allows access to #{service_url}" do
54
+ described_class.allowed?(service_url).should == true
55
+ end
56
+ end
57
+
58
+ ['https://www.example.org/', 'http://www.example.org/', 'https://www.google.com/test'].each do |service_url|
59
+ it "does not allow access to #{service_url}" do
60
+ described_class.allowed?(service_url).should == false
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end