casino 1.3.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gitignore +3 -0
- data/.travis.yml +1 -1
- data/README.md +1 -8
- data/Rakefile +0 -2
- data/app/assets/javascripts/casino/application.js +1 -0
- data/app/assets/javascripts/casino/index.js +0 -2
- data/app/assets/javascripts/casino/sessions.js +32 -0
- data/app/authenticators/casino/static_authenticator.rb +23 -0
- data/app/builders/casino/ticket_validation_response_builder.rb +84 -0
- data/app/controllers/casino/api/v1/tickets_controller.rb +7 -4
- data/app/controllers/casino/application_controller.rb +2 -3
- data/{lib/casino/listener/legacy_validator.rb → app/listeners/casino/legacy_validator_listener.rb} +2 -2
- data/app/listeners/casino/listener.rb +16 -0
- data/{lib/casino/listener/login_credential_acceptor.rb → app/listeners/casino/login_credential_acceptor_listener.rb} +2 -2
- data/{lib/casino/listener/login_credential_requestor.rb → app/listeners/casino/login_credential_requestor_listener.rb} +2 -2
- data/{lib/casino/listener/logout.rb → app/listeners/casino/logout_listener.rb} +2 -2
- data/{lib/casino/listener/other_sessions_destroyer.rb → app/listeners/casino/other_sessions_destroyer_listener.rb} +2 -2
- data/{lib/casino/listener/proxy_ticket_provider.rb → app/listeners/casino/proxy_ticket_provider_listener.rb} +2 -2
- data/{lib/casino/listener/second_factor_authentication_acceptor.rb → app/listeners/casino/second_factor_authentication_acceptor_listener.rb} +2 -2
- data/{lib/casino/listener/session_destroyer.rb → app/listeners/casino/session_destroyer_listener.rb} +2 -2
- data/{lib/casino/listener/session_overview.rb → app/listeners/casino/session_overview_listener.rb} +2 -2
- data/{lib/casino/listener/ticket_validator.rb → app/listeners/casino/ticket_validator_listener.rb} +2 -2
- data/{lib/casino/listener/two_factor_authenticator_activator.rb → app/listeners/casino/two_factor_authenticator_activator_listener.rb} +2 -2
- data/{lib/casino/listener/two_factor_authenticator_destroyer.rb → app/listeners/casino/two_factor_authenticator_destroyer_listener.rb} +2 -2
- data/{lib/casino/listener/two_factor_authenticator_overview.rb → app/listeners/casino/two_factor_authenticator_overview_listener.rb} +2 -2
- data/{lib/casino/listener/two_factor_authenticator_registrator.rb → app/listeners/casino/two_factor_authenticator_registrator_listener.rb} +2 -2
- data/app/models/casino/login_ticket.rb +12 -0
- data/app/models/casino/proxy_granting_ticket.rb +8 -0
- data/app/models/casino/proxy_ticket.rb +25 -0
- data/app/models/casino/service_rule.rb +27 -0
- data/app/models/casino/service_ticket.rb +43 -0
- data/app/models/casino/service_ticket/single_sign_out_notifier.rb +44 -0
- data/app/models/casino/ticket_granting_ticket.rb +57 -0
- data/app/models/casino/two_factor_authenticator.rb +18 -0
- data/app/models/casino/user.rb +12 -0
- data/app/models/casino/validation_result.rb +5 -0
- data/app/processors/casino/api/login_credential_acceptor_processor.rb +46 -0
- data/app/processors/casino/api/logout_processor.rb +17 -0
- data/app/processors/casino/api/service_ticket_provider_processor.rb +69 -0
- data/app/processors/casino/legacy_validator_processor.rb +19 -0
- data/app/processors/casino/login_credential_acceptor_processor.rb +63 -0
- data/app/processors/casino/login_credential_requestor_processor.rb +66 -0
- data/app/processors/casino/logout_processor.rb +23 -0
- data/app/processors/casino/other_sessions_destroyer_processor.rb +26 -0
- data/app/processors/casino/processor.rb +5 -0
- data/app/processors/casino/processor_concern/authentication.rb +87 -0
- data/app/processors/casino/processor_concern/browser.rb +14 -0
- data/app/processors/casino/processor_concern/login_tickets.rb +28 -0
- data/app/processors/casino/processor_concern/proxy_granting_tickets.rb +43 -0
- data/app/processors/casino/processor_concern/proxy_tickets.rb +56 -0
- data/app/processors/casino/processor_concern/service_tickets.rb +50 -0
- data/app/processors/casino/processor_concern/ticket_granting_tickets.rb +65 -0
- data/app/processors/casino/processor_concern/tickets.rb +17 -0
- data/app/processors/casino/processor_concern/two_factor_authenticators.rb +22 -0
- data/app/processors/casino/proxy_ticket_provider_processor.rb +41 -0
- data/app/processors/casino/proxy_ticket_validator_processor.rb +22 -0
- data/app/processors/casino/second_factor_authentication_acceptor_processor.rb +45 -0
- data/app/processors/casino/service_ticket_validator_processor.rb +46 -0
- data/app/processors/casino/session_destroyer_processor.rb +25 -0
- data/app/processors/casino/session_overview_processor.rb +21 -0
- data/app/processors/casino/two_factor_authenticator_activator_processor.rb +41 -0
- data/app/processors/casino/two_factor_authenticator_destroyer_processor.rb +33 -0
- data/app/processors/casino/two_factor_authenticator_overview_processor.rb +20 -0
- data/app/processors/casino/two_factor_authenticator_registrator_processor.rb +24 -0
- data/app/views/casino/application/_footer.html.erb +1 -1
- data/app/views/casino/sessions/new.html.erb +2 -1
- data/app/views/casino/sessions/validate_otp.html.erb +1 -1
- data/app/views/casino/two_factor_authenticators/new.html.erb +2 -2
- data/app/views/layouts/application.html.erb +1 -1
- data/casino.gemspec +9 -4
- data/db/migrate/20130809135400_create_core_schema.rb +117 -0
- data/db/migrate/20130809135401_rename_base_models.rb +101 -0
- data/db/migrate/20131022110146_cleanup_indexes.rb +27 -0
- data/db/migrate/20131022110246_fix_long_index_names.rb +12 -0
- data/db/migrate/20131022110346_change_service_to_text.rb +6 -0
- data/lib/casino.rb +47 -3
- data/lib/casino/authenticator.rb +9 -0
- data/lib/casino/engine.rb +26 -0
- data/lib/casino/inflections.rb +7 -0
- data/lib/casino/tasks.rb +1 -0
- data/lib/casino/tasks/cleanup.rake +59 -0
- data/lib/casino/tasks/service_rule.rake +49 -0
- data/lib/casino/version.rb +1 -1
- data/lib/generators/casino/install/USAGE +13 -0
- data/lib/generators/casino/install/install_generator.rb +47 -0
- data/lib/generators/casino/{templates → install/templates}/README +3 -4
- data/lib/generators/casino/{templates → install/templates}/cas.yml +2 -2
- data/lib/generators/casino/{templates → install/templates}/casino_and_overrides.scss +0 -0
- data/lib/generators/casino/templates/casino_core.rb +1 -1
- data/spec/authenticator/base_spec.rb +13 -0
- data/spec/authenticator/static_spec.rb +42 -0
- data/spec/controllers/api/v1/tickets_controller_spec.rb +15 -15
- data/spec/controllers/listener/legacy_validator_spec.rb +1 -1
- data/spec/controllers/listener/login_credential_acceptor_spec.rb +1 -1
- data/spec/controllers/listener/login_credential_requestor_spec.rb +1 -1
- data/spec/controllers/listener/logout_spec.rb +1 -1
- data/spec/controllers/listener/other_sessions_destroyer_spec.rb +1 -1
- data/spec/controllers/listener/proxy_ticket_provider_spec.rb +1 -1
- data/spec/controllers/listener/second_factor_authentication_acceptor_spec.rb +1 -1
- data/spec/controllers/listener/session_destroyer_spec.rb +1 -1
- data/spec/controllers/listener/session_overview_spec.rb +1 -1
- data/spec/controllers/listener/ticket_validator_spec.rb +1 -1
- data/spec/controllers/listener/two_factor_authenticator_activator_spec.rb +1 -1
- data/spec/controllers/listener/two_factor_authenticator_destroyer_spec.rb +1 -1
- data/spec/controllers/listener/two_factor_authenticator_overview_spec.rb +1 -1
- data/spec/controllers/listener/two_factor_authenticator_registrator_spec.rb +1 -1
- data/spec/controllers/proxy_tickets_controller_spec.rb +4 -4
- data/spec/controllers/service_tickets_controller_spec.rb +4 -4
- data/spec/controllers/sessions_controller_spec.rb +15 -15
- data/spec/controllers/two_factor_authenticators_controller_spec.rb +6 -6
- data/spec/dummy/app/assets/stylesheets/casino_and_overrides.scss +13 -0
- data/spec/dummy/config/cas.yml +11 -11
- data/spec/dummy/config/routes.rb +1 -2
- data/spec/dummy/db/migrate/20130910094259_create_base_models.casino.rb +95 -0
- data/spec/dummy/db/schema.rb +107 -0
- data/spec/model/login_ticket_spec.rb +23 -0
- data/spec/model/proxy_ticket_spec.rb +63 -0
- data/spec/model/service_rule_spec.rb +65 -0
- data/spec/model/service_ticket/single_sign_out_notifier_spec.rb +61 -0
- data/spec/model/service_ticket_spec.rb +124 -0
- data/spec/model/ticket_granting_ticket_spec.rb +204 -0
- data/spec/model/two_factor_authenticator_spec.rb +31 -0
- data/spec/processor/api/login_credential_acceptor_spec.rb +52 -0
- data/spec/processor/api/logout_spec.rb +34 -0
- data/spec/processor/api/service_ticket_provider_spec.rb +61 -0
- data/spec/processor/legacy_validator_spec.rb +78 -0
- data/spec/processor/login_credential_acceptor_spec.rb +164 -0
- data/spec/processor/login_credential_requestor_spec.rb +135 -0
- data/spec/processor/logout_other_sessions_spec.rb +53 -0
- data/spec/processor/logout_spec.rb +72 -0
- data/spec/processor/processor_concern/service_tickets_spec.rb +49 -0
- data/spec/processor/proxy_ticket_provider_spec.rb +66 -0
- data/spec/processor/proxy_ticket_validator_spec.rb +65 -0
- data/spec/processor/second_factor_authenticaton_acceptor_spec.rb +94 -0
- data/spec/processor/session_destroyer_spec.rb +75 -0
- data/spec/processor/session_overview_spec.rb +49 -0
- data/spec/processor/ticket_validator_spec.rb +199 -0
- data/spec/processor/two_factor_authenticator_activator_spec.rb +122 -0
- data/spec/processor/two_factor_authenticator_destroyer_spec.rb +71 -0
- data/spec/processor/two_factor_authenticator_overview_spec.rb +56 -0
- data/spec/processor/two_factor_authenticator_registrator_spec.rb +48 -0
- data/spec/spec_helper.rb +8 -19
- data/spec/support/casino.rb +12 -0
- data/spec/support/factories/login_ticket_factory.rb +16 -0
- data/spec/support/factories/proxy_granting_ticket_factory.rb +16 -0
- data/spec/support/factories/proxy_ticket_factory.rb +17 -0
- data/spec/support/factories/service_rule_factory.rb +16 -0
- data/spec/support/factories/service_ticket_factory.rb +17 -0
- data/spec/support/factories/ticket_granting_ticket_factory.rb +15 -0
- data/spec/support/factories/two_factor_authenticator_factory.rb +16 -0
- data/spec/support/factories/user_factory.rb +11 -0
- data/spec/support/rspec.rb +8 -0
- data/spec/support/sqlite3.rb +4 -0
- metadata +284 -48
- metadata.gz.sig +2 -0
- data/.powrc +0 -4
- data/Gemfile.lock +0 -149
- data/app/assets/javascripts/casino/application.js.coffee +0 -5
- data/app/assets/javascripts/casino/sessions.js.coffee +0 -15
- data/config/initializers/frontend_config.rb +0 -9
- data/config/initializers/inflections.rb +0 -19
- data/config/initializers/yaml.rb +0 -1
- data/lib/casino/listener.rb +0 -31
- data/lib/generators/casino/install_generator.rb +0 -35
- data/spec/dummy/config/initializers/casino_core.rb +0 -1
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CASino::OtherSessionsDestroyerProcessor do
|
4
|
+
describe '#process' do
|
5
|
+
let(:listener) { Object.new }
|
6
|
+
let(:processor) { described_class.new(listener) }
|
7
|
+
let(:cookies) { { tgt: tgt } }
|
8
|
+
let(:url) { nil }
|
9
|
+
let(:params) { { :service => url } unless url.nil? }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
listener.stub(:other_sessions_destroyed)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with an existing ticket-granting ticket' do
|
16
|
+
let(:user) { FactoryGirl.create :user }
|
17
|
+
let!(:other_users_ticket_granting_tickets) { FactoryGirl.create_list :ticket_granting_ticket, 3 }
|
18
|
+
let!(:other_ticket_granting_tickets) { FactoryGirl.create_list :ticket_granting_ticket, 3, user: user }
|
19
|
+
let!(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket, user: user }
|
20
|
+
let(:tgt) { ticket_granting_ticket.ticket }
|
21
|
+
let(:user_agent) { ticket_granting_ticket.user_agent }
|
22
|
+
|
23
|
+
it 'deletes all other ticket-granting tickets' do
|
24
|
+
lambda do
|
25
|
+
processor.process(params, cookies, user_agent)
|
26
|
+
end.should change(CASino::TicketGrantingTicket, :count).by(-3)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'calls the #user_logged_out method on the listener' do
|
30
|
+
listener.should_receive(:other_sessions_destroyed).with(nil)
|
31
|
+
processor.process(params, cookies, user_agent)
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with an URL' do
|
35
|
+
let(:url) { 'http://www.example.com' }
|
36
|
+
|
37
|
+
it 'calls the #user_logged_out method on the listener and passes the URL' do
|
38
|
+
listener.should_receive(:other_sessions_destroyed).with(url)
|
39
|
+
processor.process(params, cookies, user_agent)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with an invlaid ticket-granting ticket' do
|
45
|
+
let(:tgt) { 'TGT-lalala' }
|
46
|
+
|
47
|
+
it 'calls the #other_sessions_destroyed method on the listener' do
|
48
|
+
listener.should_receive(:other_sessions_destroyed).with(nil)
|
49
|
+
processor.process(params, cookies)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CASino::LogoutProcessor do
|
4
|
+
describe '#process' do
|
5
|
+
let(:listener) { Object.new }
|
6
|
+
let(:processor) { described_class.new(listener) }
|
7
|
+
let(:cookies) { { tgt: tgt } }
|
8
|
+
let(:url) { nil }
|
9
|
+
let(:params) { { :url => url } unless url.nil? }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
listener.stub(:user_logged_out)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with an existing ticket-granting ticket' do
|
16
|
+
let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
|
17
|
+
let(:tgt) { ticket_granting_ticket.ticket }
|
18
|
+
let(:user_agent) { ticket_granting_ticket.user_agent }
|
19
|
+
|
20
|
+
it 'deletes the ticket-granting ticket' do
|
21
|
+
processor.process(params, cookies, user_agent)
|
22
|
+
CASino::TicketGrantingTicket.where(id: ticket_granting_ticket.id).first.should == nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'calls the #user_logged_out method on the listener' do
|
26
|
+
listener.should_receive(:user_logged_out).with(nil)
|
27
|
+
processor.process(params, cookies, user_agent)
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with an URL' do
|
31
|
+
let(:url) { 'http://www.example.com' }
|
32
|
+
|
33
|
+
it 'calls the #user_logged_out method on the listener and passes the URL' do
|
34
|
+
listener.should_receive(:user_logged_out).with(url)
|
35
|
+
processor.process(params, cookies, user_agent)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with a service' do
|
40
|
+
let(:params) { { :service => url } }
|
41
|
+
let(:url) { 'http://www.example.org' }
|
42
|
+
|
43
|
+
context '(whitelisted)' do
|
44
|
+
it 'calls the #user_logged_out method on the listener and passes the URL and the redirect_immediate flag' do
|
45
|
+
listener.should_receive(:user_logged_out).with(url, true)
|
46
|
+
processor.process(params, cookies, user_agent)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '(not whitelisted)' do
|
51
|
+
before(:each) do
|
52
|
+
FactoryGirl.create :service_rule, :regex, url: '^https://.*'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'calls the #user_logged_out method on the listener and passes no URL' do
|
56
|
+
listener.should_receive(:user_logged_out).with(nil)
|
57
|
+
processor.process(params, cookies, user_agent)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with an invlaid ticket-granting ticket' do
|
64
|
+
let(:tgt) { 'TGT-lalala' }
|
65
|
+
|
66
|
+
it 'calls the #user_logged_out method on the listener' do
|
67
|
+
listener.should_receive(:user_logged_out).with(nil)
|
68
|
+
processor.process(params, cookies)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CASino::ProcessorConcern::ServiceTickets do
|
4
|
+
let(:class_with_mixin) {
|
5
|
+
Class.new do
|
6
|
+
include CASino::ProcessorConcern::ServiceTickets
|
7
|
+
end
|
8
|
+
}
|
9
|
+
subject {
|
10
|
+
class_with_mixin.new
|
11
|
+
}
|
12
|
+
|
13
|
+
describe '#acquire_service_ticket' do
|
14
|
+
let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
|
15
|
+
let(:service) { 'http://www.example.com/' }
|
16
|
+
|
17
|
+
context 'with a ticket-granting ticket with existing service tickets' do
|
18
|
+
let!(:service_ticket) { FactoryGirl.create :service_ticket, ticket_granting_ticket: ticket_granting_ticket, service: service }
|
19
|
+
let!(:other_service_ticket) { FactoryGirl.create :service_ticket, ticket_granting_ticket: ticket_granting_ticket }
|
20
|
+
|
21
|
+
it 'does not change the service tickets count' do
|
22
|
+
expect do
|
23
|
+
subject.acquire_service_ticket(ticket_granting_ticket, service)
|
24
|
+
end.to_not change(CASino::ServiceTicket, :count)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'deletes the old service ticket' do
|
28
|
+
subject.acquire_service_ticket(ticket_granting_ticket, service)
|
29
|
+
expect { service_ticket.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with a service url another ticket-granting ticket has a service ticket for' do
|
34
|
+
let!(:service_ticket) { FactoryGirl.create :service_ticket, ticket_granting_ticket: ticket_granting_ticket, service: service }
|
35
|
+
let!(:other_ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
|
36
|
+
|
37
|
+
it 'does change the service tickets count' do
|
38
|
+
expect do
|
39
|
+
subject.acquire_service_ticket(other_ticket_granting_ticket, service)
|
40
|
+
end.to change(CASino::ServiceTicket, :count).by(1)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'does not delete the other service ticket' do
|
44
|
+
subject.acquire_service_ticket(other_ticket_granting_ticket, service)
|
45
|
+
expect { service_ticket.reload }.not_to raise_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CASino::ProxyTicketProviderProcessor do
|
4
|
+
describe '#process' do
|
5
|
+
let(:listener) { Object.new }
|
6
|
+
let(:processor) { described_class.new(listener) }
|
7
|
+
let(:params) { { targetService: 'this_does_not_have_to_be_a_url' } }
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
listener.stub(:request_failed)
|
11
|
+
listener.stub(:request_succeeded)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'without proxy-granting ticket' do
|
15
|
+
it 'calls the #request_failed method on the listener' do
|
16
|
+
listener.should_receive(:request_failed)
|
17
|
+
processor.process(params)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'does not create a proxy ticket' do
|
21
|
+
lambda do
|
22
|
+
processor.process(params)
|
23
|
+
end.should_not change(CASino::ProxyTicket, :count)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with a not-existing proxy-granting ticket' do
|
28
|
+
let(:params_with_deleted_pgt) { params.merge(pgt: 'PGT-123453789') }
|
29
|
+
|
30
|
+
it 'calls the #request_failed method on the listener' do
|
31
|
+
listener.should_receive(:request_failed)
|
32
|
+
processor.process(params_with_deleted_pgt)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not create a proxy ticket' do
|
36
|
+
lambda do
|
37
|
+
processor.process(params_with_deleted_pgt)
|
38
|
+
end.should_not change(CASino::ProxyTicket, :count)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with a proxy-granting ticket' do
|
43
|
+
let(:proxy_granting_ticket) { FactoryGirl.create :proxy_granting_ticket }
|
44
|
+
let(:params_with_valid_pgt) { params.merge(pgt: proxy_granting_ticket.ticket) }
|
45
|
+
|
46
|
+
it 'calls the #request_succeeded method on the listener' do
|
47
|
+
listener.should_receive(:request_succeeded)
|
48
|
+
processor.process(params_with_valid_pgt)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'does not create a proxy ticket' do
|
52
|
+
lambda do
|
53
|
+
processor.process(params_with_valid_pgt)
|
54
|
+
end.should change(proxy_granting_ticket.proxy_tickets, :count).by(1)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'includes the proxy ticket in the response' do
|
58
|
+
listener.should_receive(:request_succeeded) do |response|
|
59
|
+
proxy_ticket = CASino::ProxyTicket.last
|
60
|
+
response.should =~ /<cas:proxyTicket>#{proxy_ticket.ticket}<\/cas:proxyTicket>/
|
61
|
+
end
|
62
|
+
processor.process(params_with_valid_pgt)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CASino::ProxyTicketValidatorProcessor do
|
4
|
+
let(:listener) { Object.new }
|
5
|
+
let(:processor) { described_class.new(listener) }
|
6
|
+
|
7
|
+
describe '#process' do
|
8
|
+
let(:regex_success) { /\A<cas:serviceResponse.*\n.*authenticationSuccess/ }
|
9
|
+
|
10
|
+
context 'with a login ticket' do
|
11
|
+
let(:login_ticket) { FactoryGirl.create :login_ticket }
|
12
|
+
let(:parameters) { { ticket: login_ticket.ticket, service: 'http://www.example.org/' } }
|
13
|
+
|
14
|
+
it 'calls the #validation_failed method on the listener' do
|
15
|
+
listener.should_receive(:validation_failed)
|
16
|
+
processor.process(parameters)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with an unconsumed proxy ticket' do
|
21
|
+
let(:proxy_ticket) { FactoryGirl.create :proxy_ticket }
|
22
|
+
let(:parameters) { { ticket: proxy_ticket.ticket, service: proxy_ticket.service } }
|
23
|
+
let(:regex_proxy) { /<cas:proxies>\s*<cas:proxy>#{proxy_ticket.proxy_granting_ticket.pgt_url}<\/cas:proxy>\s*<\/cas:proxies>/ }
|
24
|
+
|
25
|
+
it 'calls the #validation_succeeded method on the listener' do
|
26
|
+
listener.should_receive(:validation_succeeded).with(regex_success)
|
27
|
+
processor.process(parameters)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'includes the proxy in the response' do
|
31
|
+
listener.should_receive(:validation_succeeded).with(regex_proxy)
|
32
|
+
processor.process(parameters)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with an expired proxy ticket' do
|
36
|
+
before(:each) do
|
37
|
+
CASino::ProxyTicket.any_instance.stub(:expired?).and_return(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'calls the #validation_failed method on the listener' do
|
41
|
+
listener.should_receive(:validation_failed)
|
42
|
+
processor.process(parameters)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with an other service' do
|
47
|
+
let(:parameters_with_other_service) { parameters.merge(service: 'this_is_another_service') }
|
48
|
+
|
49
|
+
it 'calls the #validation_failed method on the listener' do
|
50
|
+
listener.should_receive(:validation_failed)
|
51
|
+
processor.process(parameters_with_other_service)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'without an existing ticket' do
|
56
|
+
let(:parameters_without_existing_ticket) { { ticket: 'PT-1234', service: 'https://www.example.com/' } }
|
57
|
+
|
58
|
+
it 'calls the #validation_failed method on the listener' do
|
59
|
+
listener.should_receive(:validation_failed)
|
60
|
+
processor.process(parameters_without_existing_ticket)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CASino::SecondFactorAuthenticationAcceptorProcessor do
|
4
|
+
describe '#process' do
|
5
|
+
let(:listener) { Object.new }
|
6
|
+
let(:processor) { described_class.new(listener) }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
listener.stub(:user_not_logged_in)
|
10
|
+
listener.stub(:invalid_one_time_password)
|
11
|
+
listener.stub(:user_logged_in)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with an existing ticket-granting ticket' do
|
15
|
+
let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket, :awaiting_two_factor_authentication }
|
16
|
+
let(:user) { ticket_granting_ticket.user }
|
17
|
+
let(:tgt) { ticket_granting_ticket.ticket }
|
18
|
+
let(:user_agent) { ticket_granting_ticket.user_agent }
|
19
|
+
let(:otp) { '123456' }
|
20
|
+
let(:service) { 'http://www.example.com/testing' }
|
21
|
+
let(:params) { { tgt: tgt, otp: otp, service: service }}
|
22
|
+
|
23
|
+
context 'with an active authenticator' do
|
24
|
+
let!(:two_factor_authenticator) { FactoryGirl.create :two_factor_authenticator, user: user }
|
25
|
+
|
26
|
+
context 'with a valid OTP' do
|
27
|
+
before(:each) do
|
28
|
+
ROTP::TOTP.any_instance.should_receive(:verify_with_drift).with(otp, 30).and_return(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'calls the `#user_logged_in` method an the listener' do
|
32
|
+
listener.should_receive(:user_logged_in).with(/^#{service}\?ticket=ST\-/, /^TGC\-/)
|
33
|
+
processor.process(params, user_agent)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'does activate the ticket-granting ticket' do
|
37
|
+
processor.process(params, user_agent)
|
38
|
+
ticket_granting_ticket.reload
|
39
|
+
ticket_granting_ticket.should_not be_awaiting_two_factor_authentication
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with a long-term ticket-granting ticket' do
|
43
|
+
before(:each) do
|
44
|
+
ticket_granting_ticket.update_attributes! long_term: true
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'calls the #user_logged_in method on the listener with an expiration date set' do
|
48
|
+
listener.should_receive(:user_logged_in).with(/^#{service}\?ticket=ST\-/, /^TGC\-/, kind_of(Time))
|
49
|
+
processor.process(params, user_agent)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with a not allowed service' do
|
54
|
+
before(:each) do
|
55
|
+
FactoryGirl.create :service_rule, :regex, url: '^https://.*'
|
56
|
+
end
|
57
|
+
let(:service) { 'http://www.example.org/' }
|
58
|
+
|
59
|
+
it 'calls the #service_not_allowed method on the listener' do
|
60
|
+
listener.should_receive(:service_not_allowed).with(service)
|
61
|
+
processor.process(params.merge(service: service), user_agent)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'with an invalid OTP' do
|
67
|
+
before(:each) do
|
68
|
+
ROTP::TOTP.any_instance.should_receive(:verify_with_drift).with(otp, 30).and_return(false)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'calls the `#invalid_one_time_password` method an the listener' do
|
72
|
+
listener.should_receive(:invalid_one_time_password).with(no_args)
|
73
|
+
processor.process(params, user_agent)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'does not activate the ticket-granting ticket' do
|
77
|
+
processor.process(params, user_agent)
|
78
|
+
ticket_granting_ticket.reload
|
79
|
+
ticket_granting_ticket.should be_awaiting_two_factor_authentication
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with an invalid ticket-granting ticket' do
|
86
|
+
let(:tgt) { 'TGT-lalala' }
|
87
|
+
let(:user_agent) { 'TestBrowser 1.0' }
|
88
|
+
it 'calls the #user_not_logged_in method on the listener' do
|
89
|
+
listener.should_receive(:user_not_logged_in).with(no_args)
|
90
|
+
processor.process({tgt: tgt}, user_agent)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CASino::SessionDestroyerProcessor do
|
4
|
+
describe '#process' do
|
5
|
+
let(:listener) { Object.new }
|
6
|
+
let(:processor) { described_class.new(listener) }
|
7
|
+
let(:owner_ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
|
8
|
+
let(:user) { owner_ticket_granting_ticket.user }
|
9
|
+
let(:user_agent) { owner_ticket_granting_ticket.user_agent }
|
10
|
+
let(:cookies) { { tgt: owner_ticket_granting_ticket.ticket } }
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
listener.stub(:ticket_deleted)
|
14
|
+
listener.stub(:ticket_not_found)
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with an existing ticket-granting ticket' do
|
18
|
+
let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket, user: user }
|
19
|
+
let(:service_ticket) { FactoryGirl.create :service_ticket, ticket_granting_ticket: ticket_granting_ticket }
|
20
|
+
let(:consumed_service_ticket) { FactoryGirl.create :service_ticket, :consumed, ticket_granting_ticket: ticket_granting_ticket }
|
21
|
+
let(:params) { { id: ticket_granting_ticket.id } }
|
22
|
+
|
23
|
+
it 'deletes exactly one ticket-granting ticket' do
|
24
|
+
ticket_granting_ticket
|
25
|
+
owner_ticket_granting_ticket
|
26
|
+
lambda do
|
27
|
+
processor.process(params, cookies, user_agent)
|
28
|
+
end.should change(CASino::TicketGrantingTicket, :count).by(-1)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'deletes the ticket-granting ticket' do
|
32
|
+
processor.process(params, cookies, user_agent)
|
33
|
+
CASino::TicketGrantingTicket.where(id: params[:id]).length.should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'calls the #ticket_deleted method on the listener' do
|
37
|
+
listener.should_receive(:ticket_deleted).with(no_args)
|
38
|
+
processor.process(params, cookies, user_agent)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with an invalid ticket-granting ticket' do
|
43
|
+
let(:params) { { id: 99999 } }
|
44
|
+
it 'does not delete a ticket-granting ticket' do
|
45
|
+
owner_ticket_granting_ticket
|
46
|
+
lambda do
|
47
|
+
processor.process(params, cookies, user_agent)
|
48
|
+
end.should_not change(CASino::TicketGrantingTicket, :count)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'calls the #ticket_not_found method on the listener' do
|
52
|
+
listener.should_receive(:ticket_not_found).with(no_args)
|
53
|
+
processor.process(params, cookies, user_agent)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when trying to delete ticket-granting ticket of another user' do
|
58
|
+
let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
|
59
|
+
let(:params) { { id: ticket_granting_ticket.id } }
|
60
|
+
|
61
|
+
it 'does not delete a ticket-granting ticket' do
|
62
|
+
owner_ticket_granting_ticket
|
63
|
+
ticket_granting_ticket
|
64
|
+
lambda do
|
65
|
+
processor.process(params, cookies, user_agent)
|
66
|
+
end.should change(CASino::TicketGrantingTicket, :count).by(0)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'calls the #ticket_not_found method on the listener' do
|
70
|
+
listener.should_receive(:ticket_not_found).with(no_args)
|
71
|
+
processor.process(params, cookies, user_agent)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|