casino 3.0.4 → 4.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +12 -3
- data/app/api/casino/api.rb +7 -0
- data/app/api/casino/api/entity/auth_token_ticket.rb +5 -0
- data/app/api/casino/api/resource/auth_token_tickets.rb +12 -0
- data/app/assets/javascripts/casino/{application.js → application.js.erb} +1 -1
- data/app/authenticators/casino/static_authenticator.rb +8 -2
- data/app/builders/casino/proxy_response_builder.rb +24 -0
- data/app/builders/casino/ticket_validation_response_builder.rb +9 -5
- data/app/controllers/casino/application_controller.rb +0 -22
- data/app/controllers/casino/auth_tokens_controller.rb +34 -0
- data/app/controllers/casino/controller_concern/ticket_validator.rb +30 -0
- data/app/controllers/casino/proxy_tickets_controller.rb +42 -2
- data/app/controllers/casino/service_tickets_controller.rb +15 -2
- data/app/controllers/casino/sessions_controller.rb +59 -8
- data/app/controllers/casino/two_factor_authenticators_controller.rb +28 -3
- data/app/helpers/casino/sessions_helper.rb +75 -0
- data/app/helpers/casino/two_factor_authenticators_helper.rb +12 -0
- data/app/models/casino/auth_token_ticket.rb +15 -0
- data/app/models/casino/login_ticket.rb +7 -4
- data/app/models/casino/model_concern/consumable_ticket.rb +20 -0
- data/app/models/casino/model_concern/ticket.rb +28 -0
- data/app/models/casino/proxy_granting_ticket.rb +12 -0
- data/app/models/casino/proxy_ticket.rb +4 -0
- data/app/models/casino/service_ticket.rb +5 -4
- data/app/models/casino/ticket_granting_ticket.rb +5 -1
- data/app/models/casino/two_factor_authenticator.rb +2 -0
- data/app/processors/casino/authentication_processor.rb +73 -0
- data/app/processors/casino/browser_processor.rb +12 -0
- data/app/processors/casino/proxy_granting_ticket_processor.rb +37 -0
- data/app/processors/casino/service_ticket_processor.rb +81 -0
- data/app/processors/casino/ticket_granting_ticket_processor.rb +56 -0
- data/app/processors/casino/two_factor_authenticator_processor.rb +18 -0
- data/app/services/casino/auth_token_validation_service.rb +66 -0
- data/app/views/casino/sessions/index.html.erb +2 -2
- data/app/views/casino/sessions/new.html.erb +1 -1
- data/app/views/casino/sessions/validate_otp.html.erb +1 -1
- data/app/views/casino/two_factor_authenticators/new.html.erb +6 -3
- data/app/views/layouts/application.html.erb +0 -1
- data/casino.gemspec +4 -2
- data/config/locales/en.yml +35 -0
- data/config/locales/zh-CN.yml +88 -0
- data/config/locales/zh-TW.yml +88 -0
- data/config/routes.rb +3 -10
- data/db/migrate/20140831205255_create_auth_token_tickets.rb +10 -0
- data/lib/casino.rb +4 -1
- data/lib/casino/tasks/cleanup.rake +13 -1
- data/lib/casino/version.rb +1 -1
- data/spec/controllers/auth_tokens_controller_spec.rb +75 -0
- data/spec/controllers/proxy_tickets_controller_spec.rb +120 -14
- data/spec/controllers/service_and_proxy_tickets_controller_spec.rb +224 -0
- data/spec/controllers/service_tickets_controller_spec.rb +62 -16
- data/spec/controllers/sessions_controller_spec.rb +622 -36
- data/spec/controllers/two_factor_authenticators_controller_spec.rb +217 -18
- data/spec/dummy/config/cas.yml +3 -0
- data/spec/dummy/config/environments/development.rb +0 -4
- data/spec/dummy/db/migrate/{20130910094259_create_base_models.casino.rb → 20140831214845_create_core_schema.casino.rb} +55 -32
- data/spec/dummy/db/migrate/20140831214846_rename_base_models.casino.rb +102 -0
- data/spec/dummy/db/migrate/20140831214847_cleanup_indexes.casino.rb +28 -0
- data/spec/dummy/db/migrate/20140831214848_fix_long_index_names.casino.rb +13 -0
- data/spec/dummy/db/migrate/20140831214849_change_service_to_text.casino.rb +7 -0
- data/spec/dummy/db/migrate/20140831214850_change_user_agent_to_text.casino.rb +6 -0
- data/spec/dummy/db/migrate/20140831214851_fix_length_of_text_fields.casino.rb +8 -0
- data/spec/dummy/db/migrate/20140831214852_create_auth_token_tickets.casino.rb +11 -0
- data/spec/dummy/db/schema.rb +79 -70
- data/spec/features/login_spec.rb +0 -9
- data/spec/model/auth_token_ticket_spec.rb +23 -0
- data/spec/services/auth_token_validation_service_spec.rb +83 -0
- data/spec/support/sign_in.rb +4 -0
- metadata +139 -210
- data/app/controllers/casino/api/v1/tickets_controller.rb +0 -55
- data/app/helpers/service_tickets_helper.rb +0 -2
- data/app/listeners/casino/legacy_validator_listener.rb +0 -11
- data/app/listeners/casino/listener.rb +0 -16
- data/app/listeners/casino/login_credential_acceptor_listener.rb +0 -38
- data/app/listeners/casino/login_credential_requestor_listener.rb +0 -21
- data/app/listeners/casino/logout_listener.rb +0 -12
- data/app/listeners/casino/other_sessions_destroyer_listener.rb +0 -7
- data/app/listeners/casino/proxy_ticket_provider_listener.rb +0 -11
- data/app/listeners/casino/second_factor_authentication_acceptor_listener.rb +0 -26
- data/app/listeners/casino/session_destroyer_listener.rb +0 -11
- data/app/listeners/casino/session_overview_listener.rb +0 -11
- data/app/listeners/casino/ticket_validator_listener.rb +0 -11
- data/app/listeners/casino/two_factor_authenticator_activator_listener.rb +0 -23
- data/app/listeners/casino/two_factor_authenticator_destroyer_listener.rb +0 -16
- data/app/listeners/casino/two_factor_authenticator_overview_listener.rb +0 -11
- data/app/listeners/casino/two_factor_authenticator_registrator_listener.rb +0 -11
- data/app/processors/casino/api/login_credential_acceptor_processor.rb +0 -46
- data/app/processors/casino/api/logout_processor.rb +0 -17
- data/app/processors/casino/api/service_ticket_provider_processor.rb +0 -69
- data/app/processors/casino/legacy_validator_processor.rb +0 -19
- data/app/processors/casino/login_credential_acceptor_processor.rb +0 -63
- data/app/processors/casino/login_credential_requestor_processor.rb +0 -70
- data/app/processors/casino/logout_processor.rb +0 -23
- data/app/processors/casino/other_sessions_destroyer_processor.rb +0 -26
- data/app/processors/casino/processor.rb +0 -5
- data/app/processors/casino/processor_concern/authentication.rb +0 -87
- data/app/processors/casino/processor_concern/browser.rb +0 -14
- data/app/processors/casino/processor_concern/login_tickets.rb +0 -28
- data/app/processors/casino/processor_concern/proxy_granting_tickets.rb +0 -43
- data/app/processors/casino/processor_concern/proxy_tickets.rb +0 -56
- data/app/processors/casino/processor_concern/service_tickets.rb +0 -50
- data/app/processors/casino/processor_concern/ticket_granting_tickets.rb +0 -65
- data/app/processors/casino/processor_concern/tickets.rb +0 -17
- data/app/processors/casino/processor_concern/two_factor_authenticators.rb +0 -23
- data/app/processors/casino/proxy_ticket_provider_processor.rb +0 -41
- data/app/processors/casino/proxy_ticket_validator_processor.rb +0 -22
- data/app/processors/casino/second_factor_authentication_acceptor_processor.rb +0 -45
- data/app/processors/casino/service_ticket_validator_processor.rb +0 -46
- data/app/processors/casino/session_destroyer_processor.rb +0 -25
- data/app/processors/casino/session_overview_processor.rb +0 -21
- data/app/processors/casino/two_factor_authenticator_activator_processor.rb +0 -41
- data/app/processors/casino/two_factor_authenticator_destroyer_processor.rb +0 -33
- data/app/processors/casino/two_factor_authenticator_overview_processor.rb +0 -20
- data/app/processors/casino/two_factor_authenticator_registrator_processor.rb +0 -24
- data/spec/controllers/api/v1/tickets_controller_spec.rb +0 -114
- data/spec/controllers/listener/legacy_validator_spec.rb +0 -22
- data/spec/controllers/listener/login_credential_acceptor_spec.rb +0 -108
- data/spec/controllers/listener/login_credential_requestor_spec.rb +0 -57
- data/spec/controllers/listener/logout_spec.rb +0 -38
- data/spec/controllers/listener/other_sessions_destroyer_spec.rb +0 -19
- data/spec/controllers/listener/proxy_ticket_provider_spec.rb +0 -22
- data/spec/controllers/listener/second_factor_authentication_acceptor_spec.rb +0 -74
- data/spec/controllers/listener/session_destroyer_spec.rb +0 -25
- data/spec/controllers/listener/session_overview_spec.rb +0 -26
- data/spec/controllers/listener/ticket_validator_spec.rb +0 -22
- data/spec/controllers/listener/two_factor_authenticator_activator_spec.rb +0 -64
- data/spec/controllers/listener/two_factor_authenticator_destroyer_spec.rb +0 -40
- data/spec/controllers/listener/two_factor_authenticator_overview_spec.rb +0 -16
- data/spec/controllers/listener/two_factor_authenticator_registrator_spec.rb +0 -27
- data/spec/processor/api/login_credential_acceptor_spec.rb +0 -52
- data/spec/processor/api/logout_spec.rb +0 -34
- data/spec/processor/api/service_ticket_provider_spec.rb +0 -61
- data/spec/processor/legacy_validator_spec.rb +0 -78
- data/spec/processor/login_credential_acceptor_spec.rb +0 -164
- data/spec/processor/login_credential_requestor_spec.rb +0 -145
- data/spec/processor/logout_other_sessions_spec.rb +0 -53
- data/spec/processor/logout_spec.rb +0 -72
- data/spec/processor/processor_concern/service_tickets_spec.rb +0 -49
- data/spec/processor/proxy_ticket_provider_spec.rb +0 -66
- data/spec/processor/proxy_ticket_validator_spec.rb +0 -65
- data/spec/processor/second_factor_authenticaton_acceptor_spec.rb +0 -94
- data/spec/processor/session_destroyer_spec.rb +0 -75
- data/spec/processor/session_overview_spec.rb +0 -49
- data/spec/processor/ticket_validator_spec.rb +0 -214
- data/spec/processor/two_factor_authenticator_activator_spec.rb +0 -122
- data/spec/processor/two_factor_authenticator_destroyer_spec.rb +0 -71
- data/spec/processor/two_factor_authenticator_overview_spec.rb +0 -56
- data/spec/processor/two_factor_authenticator_registrator_spec.rb +0 -48
@@ -1,66 +0,0 @@
|
|
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
|
@@ -1,65 +0,0 @@
|
|
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
|
@@ -1,94 +0,0 @@
|
|
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
|
@@ -1,75 +0,0 @@
|
|
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
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CASino::SessionOverviewProcessor do
|
4
|
-
describe '#process' do
|
5
|
-
let(:listener) { Object.new }
|
6
|
-
let(:processor) { described_class.new(listener) }
|
7
|
-
let(:other_ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
|
8
|
-
let(:user) { other_ticket_granting_ticket.user }
|
9
|
-
let(:user_agent) { other_ticket_granting_ticket.user_agent }
|
10
|
-
let(:cookies) { { tgt: tgt } }
|
11
|
-
|
12
|
-
before(:each) do
|
13
|
-
listener.stub(:user_not_logged_in)
|
14
|
-
listener.stub(:ticket_granting_tickets_found)
|
15
|
-
other_ticket_granting_ticket
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with an existing ticket-granting ticket' do
|
19
|
-
let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket, user: user }
|
20
|
-
let(:tgt) { ticket_granting_ticket.ticket }
|
21
|
-
it 'calls the #ticket_granting_tickets_found method on the listener' do
|
22
|
-
listener.should_receive(:ticket_granting_tickets_found) do |tickets|
|
23
|
-
tickets.length.should == 2
|
24
|
-
end
|
25
|
-
processor.process(cookies, user_agent)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with a ticket-granting ticket with same username but different authenticator' do
|
30
|
-
let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
|
31
|
-
let(:tgt) { ticket_granting_ticket.ticket }
|
32
|
-
|
33
|
-
it 'calls the #ticket_granting_tickets_found method on the listener' do
|
34
|
-
listener.should_receive(:ticket_granting_tickets_found) do |tickets|
|
35
|
-
tickets.length.should == 1
|
36
|
-
end
|
37
|
-
processor.process(cookies, user_agent)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'with an invalid ticket-granting ticket' do
|
42
|
-
let(:tgt) { 'TGT-lalala' }
|
43
|
-
it 'calls the #user_not_logged_in method on the listener' do
|
44
|
-
listener.should_receive(:user_not_logged_in).with(no_args)
|
45
|
-
processor.process(cookies, user_agent)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,214 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
[CASino::ServiceTicketValidatorProcessor, CASino::ProxyTicketValidatorProcessor].each do |class_under_test|
|
4
|
-
describe class_under_test do
|
5
|
-
describe '#process' do
|
6
|
-
let(:listener) { Object.new }
|
7
|
-
let(:processor) { described_class.new(listener) }
|
8
|
-
let(:service_ticket) { FactoryGirl.create :service_ticket }
|
9
|
-
let(:parameters) { { service: service_ticket.service, ticket: service_ticket.ticket }}
|
10
|
-
let(:regex_failure) { /\A\<cas\:serviceResponse.*\n.*authenticationFailure/ }
|
11
|
-
let(:regex_success) { /\A\<cas\:serviceResponse.*\n.*authenticationSuccess/ }
|
12
|
-
|
13
|
-
before(:each) do
|
14
|
-
listener.stub(:validation_failed)
|
15
|
-
listener.stub(:validation_succeeded)
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'without all required parameters' do
|
19
|
-
[:ticket, :service].each do |missing_parameter|
|
20
|
-
let(:invalid_parameters) { parameters.except(missing_parameter) }
|
21
|
-
|
22
|
-
context "without '#{missing_parameter}'" do
|
23
|
-
it 'calls the #validation_failed method on the listener' do
|
24
|
-
listener.should_receive(:validation_failed).with(regex_failure)
|
25
|
-
processor.process(invalid_parameters)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with an unconsumed service ticket' do
|
32
|
-
context 'with extra attributes using strings as keys' do
|
33
|
-
before(:each) do
|
34
|
-
CASino::User.any_instance.stub(:extra_attributes).and_return({ "id" => 1234 })
|
35
|
-
end
|
36
|
-
|
37
|
-
after(:each) do
|
38
|
-
CASino::User.any_instance.unstub(:extra_attributes)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'includes the extra attributes' do
|
42
|
-
listener.should_receive(:validation_succeeded).with(/<cas\:id>1234<\/cas\:id\>/)
|
43
|
-
processor.process(parameters)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'issued from a long_term ticket-granting ticket' do
|
48
|
-
before(:each) do
|
49
|
-
tgt = service_ticket.ticket_granting_ticket
|
50
|
-
tgt.long_term = true
|
51
|
-
tgt.save!
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'calls the #validation_succeeded method on the listener' do
|
55
|
-
listener.should_receive(:validation_succeeded).with(
|
56
|
-
/<cas\:longTermAuthenticationRequestTokenUsed>true<\/cas\:longTermAuthenticationRequestTokenUsed>/
|
57
|
-
)
|
58
|
-
processor.process(parameters)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'without renew flag' do
|
63
|
-
it 'consumes the service ticket' do
|
64
|
-
processor.process(parameters)
|
65
|
-
service_ticket.reload
|
66
|
-
service_ticket.consumed.should == true
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'calls the #validation_succeeded method on the listener' do
|
70
|
-
listener.should_receive(:validation_succeeded).with(regex_success)
|
71
|
-
processor.process(parameters)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'with empty query values' do
|
76
|
-
it 'calls the #validation_succeeded method on the listener' do
|
77
|
-
listener.should_receive(:validation_succeeded).with(regex_success)
|
78
|
-
processor.process(parameters.merge(service: "#{service_ticket.service}/?"))
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'with renew flag' do
|
83
|
-
let(:parameters_with_renew) { parameters.merge renew: 'true' }
|
84
|
-
|
85
|
-
context 'with a service ticket without issued_from_credentials flag' do
|
86
|
-
it 'consumes the service ticket' do
|
87
|
-
processor.process(parameters_with_renew)
|
88
|
-
service_ticket.reload
|
89
|
-
service_ticket.consumed.should == true
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'calls the #validation_failed method on the listener' do
|
93
|
-
listener.should_receive(:validation_failed).with(regex_failure)
|
94
|
-
processor.process(parameters_with_renew)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'with a service ticket with issued_from_credentials flag' do
|
99
|
-
before(:each) do
|
100
|
-
service_ticket.issued_from_credentials = true
|
101
|
-
service_ticket.save!
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'consumes the service ticket' do
|
105
|
-
processor.process(parameters_with_renew)
|
106
|
-
service_ticket.reload
|
107
|
-
service_ticket.consumed.should == true
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'calls the #validation_succeeded method on the listener' do
|
111
|
-
listener.should_receive(:validation_succeeded).with(regex_success)
|
112
|
-
processor.process(parameters_with_renew)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'with proxy-granting ticket callback server' do
|
118
|
-
let(:pgt_url) { 'https://www.example.org' }
|
119
|
-
let(:parameters_with_pgt_url) { parameters.merge pgtUrl: pgt_url }
|
120
|
-
|
121
|
-
before(:each) do
|
122
|
-
stub_request(:get, /#{pgt_url}\/\?pgtId=[^&]+&pgtIou=[^&]+/)
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'not using https' do
|
126
|
-
let(:pgt_url) { 'http://www.example.org' }
|
127
|
-
|
128
|
-
it 'calls the #validation_succeeded method on the listener' do
|
129
|
-
listener.should_receive(:validation_succeeded).with(regex_success)
|
130
|
-
processor.process(parameters_with_pgt_url)
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'does not create a proxy-granting ticket' do
|
134
|
-
lambda do
|
135
|
-
processor.process(parameters_with_pgt_url)
|
136
|
-
end.should_not change(service_ticket.proxy_granting_tickets, :count)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'calls the #validation_succeeded method on the listener' do
|
141
|
-
listener.should_receive(:validation_succeeded).with(regex_success)
|
142
|
-
processor.process(parameters_with_pgt_url)
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'includes the PGTIOU in the response' do
|
146
|
-
listener.should_receive(:validation_succeeded).with(/\<cas\:proxyGrantingTicket\>\n?\s*PGTIOU-.+/)
|
147
|
-
processor.process(parameters_with_pgt_url)
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'creates a proxy-granting ticket' do
|
151
|
-
lambda do
|
152
|
-
processor.process(parameters_with_pgt_url)
|
153
|
-
end.should change(service_ticket.proxy_granting_tickets, :count).by(1)
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'contacts the callback server' do
|
157
|
-
processor.process(parameters_with_pgt_url)
|
158
|
-
proxy_granting_ticket = CASino::ProxyGrantingTicket.last
|
159
|
-
WebMock.should have_requested(:get, 'https://www.example.org').with(query: {
|
160
|
-
pgtId: proxy_granting_ticket.ticket,
|
161
|
-
pgtIou: proxy_granting_ticket.iou
|
162
|
-
})
|
163
|
-
end
|
164
|
-
|
165
|
-
context 'when callback server gives an error' do
|
166
|
-
before(:each) do
|
167
|
-
stub_request(:get, /#{pgt_url}.*/).to_return status: 404
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'calls the #validation_succeeded method on the listener' do
|
171
|
-
listener.should_receive(:validation_succeeded).with(regex_success)
|
172
|
-
processor.process(parameters_with_pgt_url)
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'does not create a proxy-granting ticket' do
|
176
|
-
lambda do
|
177
|
-
processor.process(parameters_with_pgt_url)
|
178
|
-
end.should_not change(service_ticket.proxy_granting_tickets, :count)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
context 'when callback server is unreachable' do
|
183
|
-
before(:each) do
|
184
|
-
stub_request(:get, /#{pgt_url}.*/).to_raise(Timeout::Error)
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'calls the #validation_succeeded method on the listener' do
|
188
|
-
listener.should_receive(:validation_succeeded).with(regex_success)
|
189
|
-
processor.process(parameters_with_pgt_url)
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'does not create a proxy-granting ticket' do
|
193
|
-
lambda do
|
194
|
-
processor.process(parameters_with_pgt_url)
|
195
|
-
end.should_not change(service_ticket.proxy_granting_tickets, :count)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'with a consumed service ticket' do
|
202
|
-
before(:each) do
|
203
|
-
service_ticket.consumed = true
|
204
|
-
service_ticket.save!
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'calls the #validation_failed method on the listener' do
|
208
|
-
listener.should_receive(:validation_failed).with(regex_failure)
|
209
|
-
processor.process(parameters)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|