casino_core 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data.tar.gz.sig +0 -0
  2. data/Gemfile.lock +7 -1
  3. data/UPGRADE.md +15 -3
  4. data/casino_core.gemspec +2 -0
  5. data/config/cas.yml +1 -7
  6. data/db/migrate/20130202210100_create_users.rb +0 -6
  7. data/db/migrate/20130203100015_create_two_factor_authenticators.rb +12 -0
  8. data/db/migrate/20130203101351_add_active_to_two_factor_authenticators.rb +5 -0
  9. data/db/migrate/20130203155008_add_awaiting_two_factor_authentication_to_ticket_granting_tickets.rb +5 -0
  10. data/db/schema.rb +16 -5
  11. data/lib/casino_core/helper.rb +1 -0
  12. data/lib/casino_core/helper/proxy_granting_tickets.rb +26 -31
  13. data/lib/casino_core/helper/proxy_tickets.rb +1 -5
  14. data/lib/casino_core/helper/ticket_granting_tickets.rb +3 -2
  15. data/lib/casino_core/helper/two_factor_authenticators.rb +22 -0
  16. data/lib/casino_core/model.rb +2 -0
  17. data/lib/casino_core/model/service_ticket/single_sign_out_notifier.rb +13 -30
  18. data/lib/casino_core/model/ticket_granting_ticket.rb +1 -1
  19. data/lib/casino_core/model/two_factor_authenticator.rb +19 -0
  20. data/lib/casino_core/model/user.rb +5 -0
  21. data/lib/casino_core/model/validation_result.rb +7 -0
  22. data/lib/casino_core/processor.rb +5 -0
  23. data/lib/casino_core/processor/login_credential_acceptor.rb +12 -7
  24. data/lib/casino_core/processor/second_factor_authentication_acceptor.rb +46 -0
  25. data/lib/casino_core/processor/session_overview.rb +1 -1
  26. data/lib/casino_core/processor/two_factor_authenticator_activator.rb +46 -0
  27. data/lib/casino_core/processor/two_factor_authenticator_destroyer.rb +38 -0
  28. data/lib/casino_core/processor/two_factor_authenticator_overview.rb +24 -0
  29. data/lib/casino_core/processor/two_factor_authenticator_registrator.rb +27 -0
  30. data/lib/casino_core/settings.rb +20 -2
  31. data/lib/casino_core/tasks/cleanup.rake +7 -1
  32. data/lib/casino_core/version.rb +1 -1
  33. data/spec/model/two_factor_authenticator_spec.rb +31 -0
  34. data/spec/processor/login_credential_acceptor_spec.rb +10 -0
  35. data/spec/processor/login_credential_requestor_spec.rb +9 -0
  36. data/spec/processor/second_factor_authenticaton_acceptor_spec.rb +83 -0
  37. data/spec/processor/ticket_validator_spec.rb +15 -0
  38. data/spec/processor/two_factor_authenticator_activator_spec.rb +122 -0
  39. data/spec/processor/two_factor_authenticator_destroyer_spec.rb +71 -0
  40. data/spec/processor/two_factor_authenticator_overview_spec.rb +56 -0
  41. data/spec/processor/two_factor_authenticator_registrator_spec.rb +48 -0
  42. data/spec/settings_spec.rb +9 -0
  43. data/spec/support/factories/ticket_granting_ticket_factory.rb +4 -0
  44. data/spec/support/factories/two_factor_authenticator_factory.rb +16 -0
  45. metadata +61 -4
  46. metadata.gz.sig +1 -3
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe CASinoCore::Processor::TwoFactorAuthenticatorDestroyer do
4
+ describe '#process' do
5
+ let(:listener) { Object.new }
6
+ let(:processor) { described_class.new(listener) }
7
+ let(:cookies) { { tgt: tgt } }
8
+
9
+ before(:each) do
10
+ listener.stub(:user_not_logged_in)
11
+ listener.stub(:two_factor_authenticator_destroyed)
12
+ listener.stub(:invalid_two_factor_authenticator)
13
+ end
14
+
15
+ context 'with an existing ticket-granting ticket' do
16
+ let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
17
+ let(:user) { ticket_granting_ticket.user }
18
+ let(:tgt) { ticket_granting_ticket.ticket }
19
+ let(:user_agent) { ticket_granting_ticket.user_agent }
20
+ let(:params) { { id: two_factor_authenticator.id } }
21
+
22
+ context 'with a valid two-factor authenticator' do
23
+ let!(:two_factor_authenticator) { FactoryGirl.create :two_factor_authenticator, user: user }
24
+
25
+ it 'calls the #two_factor_authenticator_destroyed method on the listener' do
26
+ listener.should_receive(:two_factor_authenticator_destroyed).with(no_args)
27
+ processor.process(params, cookies, user_agent)
28
+ end
29
+
30
+ it 'deletes the two-factor authenticator' do
31
+ processor.process(params, cookies, user_agent)
32
+ lambda do
33
+ two_factor_authenticator.reload
34
+ end.should raise_error(ActiveRecord::RecordNotFound)
35
+ end
36
+
37
+ it 'does not delete other two-factor authenticators' do
38
+ other = FactoryGirl.create :two_factor_authenticator
39
+ lambda do
40
+ processor.process(params, cookies, user_agent)
41
+ end.should change(CASinoCore::Model::TwoFactorAuthenticator, :count).by(-1)
42
+ end
43
+ end
44
+
45
+ context 'with a two-factor authenticator of another user' do
46
+ let!(:two_factor_authenticator) { FactoryGirl.create :two_factor_authenticator }
47
+
48
+ it 'calls the #invalid_two_factor_authenticator method on the listener' do
49
+ listener.should_receive(:invalid_two_factor_authenticator).with(no_args)
50
+ processor.process(params, cookies, user_agent)
51
+ end
52
+
53
+ it 'does not delete two-factor authenticators' do
54
+ lambda do
55
+ processor.process(params, cookies, user_agent)
56
+ end.should_not change(CASinoCore::Model::TwoFactorAuthenticator, :count)
57
+ end
58
+ end
59
+ end
60
+
61
+ context 'with an invalid ticket-granting ticket' do
62
+ let(:params) { {} }
63
+ let(:tgt) { 'TGT-lalala' }
64
+ let(:user_agent) { 'TestBrowser 1.0' }
65
+ it 'calls the #user_not_logged_in method on the listener' do
66
+ listener.should_receive(:user_not_logged_in).with(no_args)
67
+ processor.process(params, cookies, user_agent)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe CASinoCore::Processor::TwoFactorAuthenticatorOverview do
4
+ describe '#process' do
5
+ let(:listener) { Object.new }
6
+ let(:processor) { described_class.new(listener) }
7
+ let(:cookies) { { tgt: tgt } }
8
+
9
+ before(:each) do
10
+ listener.stub(:user_not_logged_in)
11
+ listener.stub(:two_factor_authenticators_found)
12
+ end
13
+
14
+ context 'with an existing ticket-granting ticket' do
15
+ let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
16
+ let(:user) { ticket_granting_ticket.user }
17
+ let(:tgt) { ticket_granting_ticket.ticket }
18
+ let(:user_agent) { ticket_granting_ticket.user_agent }
19
+
20
+ context 'without a two-factor authenticator registered' do
21
+ it 'calls the #two_factor_authenticators_found method on the listener' do
22
+ listener.should_receive(:two_factor_authenticators_found).with([])
23
+ processor.process(cookies, user_agent)
24
+ end
25
+ end
26
+
27
+ context 'with an inactive two-factor authenticator' do
28
+ let!(:two_factor_authenticator) { FactoryGirl.create :two_factor_authenticator, :inactive, user: user }
29
+
30
+ it 'does not include the inactive authenticator' do
31
+ listener.should_receive(:two_factor_authenticators_found).with([])
32
+ processor.process(cookies, user_agent)
33
+ end
34
+ end
35
+
36
+ context 'with a two-factor authenticator registered' do
37
+ let(:two_factor_authenticator) { FactoryGirl.create :two_factor_authenticator, user: user }
38
+ let!(:other_two_factor_authenticator) { FactoryGirl.create :two_factor_authenticator }
39
+
40
+ it 'calls the #two_factor_authenticators_found method on the listener' do
41
+ listener.should_receive(:two_factor_authenticators_found).with([two_factor_authenticator])
42
+ processor.process(cookies, user_agent)
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'with an invalid ticket-granting ticket' do
48
+ let(:tgt) { 'TGT-lalala' }
49
+ let(:user_agent) { 'TestBrowser 1.0' }
50
+ it 'calls the #user_not_logged_in method on the listener' do
51
+ listener.should_receive(:user_not_logged_in).with(no_args)
52
+ processor.process(cookies, user_agent)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe CASinoCore::Processor::TwoFactorAuthenticatorRegistrator do
4
+ describe '#process' do
5
+ let(:listener) { Object.new }
6
+ let(:processor) { described_class.new(listener) }
7
+ let(:cookies) { { tgt: tgt } }
8
+
9
+ before(:each) do
10
+ listener.stub(:user_not_logged_in)
11
+ listener.stub(:two_factor_authenticator_registered)
12
+ end
13
+
14
+ context 'with an existing ticket-granting ticket' do
15
+ let(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket }
16
+ let(:user) { ticket_granting_ticket.user }
17
+ let(:tgt) { ticket_granting_ticket.ticket }
18
+ let(:user_agent) { ticket_granting_ticket.user_agent }
19
+
20
+ it 'creates exactly one authenticator' do
21
+ lambda do
22
+ processor.process(cookies, user_agent)
23
+ end.should change(CASinoCore::Model::TwoFactorAuthenticator, :count).by(1)
24
+ end
25
+
26
+ it 'calls #two_factor_authenticator_created on the listener' do
27
+ listener.should_receive(:two_factor_authenticator_registered) do |authenticator|
28
+ authenticator.should == CASinoCore::Model::TwoFactorAuthenticator.last
29
+ end
30
+ processor.process(cookies, user_agent)
31
+ end
32
+
33
+ it 'creates an inactive two-factor authenticator' do
34
+ processor.process(cookies, user_agent)
35
+ CASinoCore::Model::TwoFactorAuthenticator.last.should_not be_active
36
+ end
37
+ end
38
+
39
+ context 'with an invalid ticket-granting ticket' do
40
+ let(:tgt) { 'TGT-lalala' }
41
+ let(:user_agent) { 'TestBrowser 1.0' }
42
+ it 'calls the #user_not_logged_in method on the listener' do
43
+ listener.should_receive(:user_not_logged_in).with(no_args)
44
+ processor.process(cookies, user_agent)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,6 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CASinoCore::Settings do
4
+ describe 'initializer' do
5
+ it 'loads default settings' do
6
+ described_class.service_ticket[:lifetime_consumed].should == 86400
7
+ end
8
+ it 'overwrites specific settings' do
9
+ described_class.service_ticket[:lifetime_unconsumed].should == 299
10
+ end
11
+ end
12
+
4
13
  describe '#authenticators=' do
5
14
  context 'with an authenticator name' do
6
15
  let(:authenticator_name) { 'testing' }
@@ -7,5 +7,9 @@ FactoryGirl.define do
7
7
  "TGC-ticket#{n}"
8
8
  end
9
9
  user_agent 'TestBrowser 1.0'
10
+
11
+ trait :awaiting_two_factor_authentication do
12
+ awaiting_two_factor_authentication true
13
+ end
10
14
  end
11
15
  end
@@ -0,0 +1,16 @@
1
+ require 'factory_girl'
2
+ require 'rotp'
3
+
4
+ FactoryGirl.define do
5
+ factory :two_factor_authenticator, class: CASinoCore::Model::TwoFactorAuthenticator do
6
+ user
7
+ secret do
8
+ ROTP::Base32.random_base32
9
+ end
10
+ active true
11
+
12
+ trait :inactive do
13
+ active false
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casino_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -36,7 +36,7 @@ cert_chain:
36
36
  b1VSdnUwRzgvWXlIVUFtSVUvV0tyanIxYmdjZjFWUnYKUjRLRDFNblVWL3Y1
37
37
  MDJwaU1sWG1qeE9XZGJLOHl2UUVIa3N1L3pqYkNqU3UrTTJrd0ZtV0dzeDVu
38
38
  eCtWZHc9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
39
- date: 2013-02-02 00:00:00.000000000 Z
39
+ date: 2013-02-08 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
@@ -246,6 +246,38 @@ dependencies:
246
246
  - - ~>
247
247
  - !ruby/object:Gem::Version
248
248
  version: '0.4'
249
+ - !ruby/object:Gem::Dependency
250
+ name: faraday
251
+ requirement: !ruby/object:Gem::Requirement
252
+ none: false
253
+ requirements:
254
+ - - ~>
255
+ - !ruby/object:Gem::Version
256
+ version: '0.8'
257
+ type: :runtime
258
+ prerelease: false
259
+ version_requirements: !ruby/object:Gem::Requirement
260
+ none: false
261
+ requirements:
262
+ - - ~>
263
+ - !ruby/object:Gem::Version
264
+ version: '0.8'
265
+ - !ruby/object:Gem::Dependency
266
+ name: rotp
267
+ requirement: !ruby/object:Gem::Requirement
268
+ none: false
269
+ requirements:
270
+ - - ~>
271
+ - !ruby/object:Gem::Version
272
+ version: '1.4'
273
+ type: :runtime
274
+ prerelease: false
275
+ version_requirements: !ruby/object:Gem::Requirement
276
+ none: false
277
+ requirements:
278
+ - - ~>
279
+ - !ruby/object:Gem::Version
280
+ version: '1.4'
249
281
  description: CASinoCore is a CAS server library. It can be used by other projects
250
282
  to build a fully functional CAS server.
251
283
  email:
@@ -291,6 +323,9 @@ files:
291
323
  - db/migrate/20121231114141_add_authenticator_to_ticket_granting_tickets.rb
292
324
  - db/migrate/20130105152327_create_service_rules.rb
293
325
  - db/migrate/20130202210100_create_users.rb
326
+ - db/migrate/20130203100015_create_two_factor_authenticators.rb
327
+ - db/migrate/20130203101351_add_active_to_two_factor_authenticators.rb
328
+ - db/migrate/20130203155008_add_awaiting_two_factor_authentication_to_ticket_granting_tickets.rb
294
329
  - db/schema.rb
295
330
  - lib/casino_core.rb
296
331
  - lib/casino_core/authenticator.rb
@@ -307,6 +342,7 @@ files:
307
342
  - lib/casino_core/helper/service_tickets.rb
308
343
  - lib/casino_core/helper/ticket_granting_tickets.rb
309
344
  - lib/casino_core/helper/tickets.rb
345
+ - lib/casino_core/helper/two_factor_authenticators.rb
310
346
  - lib/casino_core/model.rb
311
347
  - lib/casino_core/model/login_ticket.rb
312
348
  - lib/casino_core/model/proxy_granting_ticket.rb
@@ -315,7 +351,9 @@ files:
315
351
  - lib/casino_core/model/service_ticket.rb
316
352
  - lib/casino_core/model/service_ticket/single_sign_out_notifier.rb
317
353
  - lib/casino_core/model/ticket_granting_ticket.rb
354
+ - lib/casino_core/model/two_factor_authenticator.rb
318
355
  - lib/casino_core/model/user.rb
356
+ - lib/casino_core/model/validation_result.rb
319
357
  - lib/casino_core/processor.rb
320
358
  - lib/casino_core/processor/api.rb
321
359
  - lib/casino_core/processor/api/login_credential_acceptor.rb
@@ -327,9 +365,14 @@ files:
327
365
  - lib/casino_core/processor/logout.rb
328
366
  - lib/casino_core/processor/proxy_ticket_provider.rb
329
367
  - lib/casino_core/processor/proxy_ticket_validator.rb
368
+ - lib/casino_core/processor/second_factor_authentication_acceptor.rb
330
369
  - lib/casino_core/processor/service_ticket_validator.rb
331
370
  - lib/casino_core/processor/session_destroyer.rb
332
371
  - lib/casino_core/processor/session_overview.rb
372
+ - lib/casino_core/processor/two_factor_authenticator_activator.rb
373
+ - lib/casino_core/processor/two_factor_authenticator_destroyer.rb
374
+ - lib/casino_core/processor/two_factor_authenticator_overview.rb
375
+ - lib/casino_core/processor/two_factor_authenticator_registrator.rb
333
376
  - lib/casino_core/railtie.rb
334
377
  - lib/casino_core/rake_tasks.rb
335
378
  - lib/casino_core/settings.rb
@@ -345,6 +388,7 @@ files:
345
388
  - spec/model/service_ticket/single_sign_out_notifier_spec.rb
346
389
  - spec/model/service_ticket_spec.rb
347
390
  - spec/model/ticket_granting_ticket_spec.rb
391
+ - spec/model/two_factor_authenticator_spec.rb
348
392
  - spec/processor/api/login_credential_acceptor_spec.rb
349
393
  - spec/processor/api/logout_spec.rb
350
394
  - spec/processor/api/service_ticket_provider_spec.rb
@@ -354,9 +398,14 @@ files:
354
398
  - spec/processor/logout_spec.rb
355
399
  - spec/processor/proxy_ticket_provider_spec.rb
356
400
  - spec/processor/proxy_ticket_validator_spec.rb
401
+ - spec/processor/second_factor_authenticaton_acceptor_spec.rb
357
402
  - spec/processor/session_destroyer_spec.rb
358
403
  - spec/processor/session_overview_spec.rb
359
404
  - spec/processor/ticket_validator_spec.rb
405
+ - spec/processor/two_factor_authenticator_activator_spec.rb
406
+ - spec/processor/two_factor_authenticator_destroyer_spec.rb
407
+ - spec/processor/two_factor_authenticator_overview_spec.rb
408
+ - spec/processor/two_factor_authenticator_registrator_spec.rb
360
409
  - spec/settings_spec.rb
361
410
  - spec/spec_helper.rb
362
411
  - spec/support/factories/login_ticket_factory.rb
@@ -365,6 +414,7 @@ files:
365
414
  - spec/support/factories/service_rule_factory.rb
366
415
  - spec/support/factories/service_ticket_factory.rb
367
416
  - spec/support/factories/ticket_granting_ticket_factory.rb
417
+ - spec/support/factories/two_factor_authenticator_factory.rb
368
418
  - spec/support/factories/user_factory.rb
369
419
  homepage: http://rbcas.org/
370
420
  licenses:
@@ -381,7 +431,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
381
431
  version: '0'
382
432
  segments:
383
433
  - 0
384
- hash: -2617767929690973862
434
+ hash: 1075447066647602137
385
435
  required_rubygems_version: !ruby/object:Gem::Requirement
386
436
  none: false
387
437
  requirements:
@@ -390,7 +440,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
390
440
  version: '0'
391
441
  segments:
392
442
  - 0
393
- hash: -2617767929690973862
443
+ hash: 1075447066647602137
394
444
  requirements: []
395
445
  rubyforge_project:
396
446
  rubygems_version: 1.8.24
@@ -406,6 +456,7 @@ test_files:
406
456
  - spec/model/service_ticket/single_sign_out_notifier_spec.rb
407
457
  - spec/model/service_ticket_spec.rb
408
458
  - spec/model/ticket_granting_ticket_spec.rb
459
+ - spec/model/two_factor_authenticator_spec.rb
409
460
  - spec/processor/api/login_credential_acceptor_spec.rb
410
461
  - spec/processor/api/logout_spec.rb
411
462
  - spec/processor/api/service_ticket_provider_spec.rb
@@ -415,9 +466,14 @@ test_files:
415
466
  - spec/processor/logout_spec.rb
416
467
  - spec/processor/proxy_ticket_provider_spec.rb
417
468
  - spec/processor/proxy_ticket_validator_spec.rb
469
+ - spec/processor/second_factor_authenticaton_acceptor_spec.rb
418
470
  - spec/processor/session_destroyer_spec.rb
419
471
  - spec/processor/session_overview_spec.rb
420
472
  - spec/processor/ticket_validator_spec.rb
473
+ - spec/processor/two_factor_authenticator_activator_spec.rb
474
+ - spec/processor/two_factor_authenticator_destroyer_spec.rb
475
+ - spec/processor/two_factor_authenticator_overview_spec.rb
476
+ - spec/processor/two_factor_authenticator_registrator_spec.rb
421
477
  - spec/settings_spec.rb
422
478
  - spec/spec_helper.rb
423
479
  - spec/support/factories/login_ticket_factory.rb
@@ -426,5 +482,6 @@ test_files:
426
482
  - spec/support/factories/service_rule_factory.rb
427
483
  - spec/support/factories/service_ticket_factory.rb
428
484
  - spec/support/factories/ticket_granting_ticket_factory.rb
485
+ - spec/support/factories/two_factor_authenticator_factory.rb
429
486
  - spec/support/factories/user_factory.rb
430
487
  has_rdoc:
metadata.gz.sig CHANGED
@@ -1,3 +1 @@
1
- n�̢���csxh]?u��8)��dg-��'��ɏ�q�G d:�p)[�e���zK�"���t��Qs��HC{��AwPw���K��8�*.<��"c}}���@�2$RЎ�`������$��\(N�7J�ђ�O��W�Ϥ
2
- �Do�^�L��P+r�m�>�橿c��1 ���87O�(��_�>^�
3
- �D�^�d]�_�M`b��IS^/���i�%���!�]&���J�֣���� B�0�yP�-l��;
1
+ ���þ�icʞ|� ⦏m4��~����V��o\�d��93�2ҹ�ǰd@�(yy�謵��[�k�����!u�"��L(�+�z�\��� ���r)���lN�ߌ{c�+�����S7�� ��z}'��o ���R���ħl�̆����� ����[ jq���'F`��7qm���p�R�l-�:XB² B��%k��T&�Bᣔ#�__�k�Yf�_�]*M�]mk��Q�B