devise_cas_authenticatable 1.10.4 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +32 -0
  3. data/.gitignore +0 -1
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile +8 -0
  6. data/README.md +84 -88
  7. data/app/controllers/devise/cas_sessions_controller.rb +23 -67
  8. data/app/views/devise/cas_sessions/unregistered.html.erb +3 -3
  9. data/devise_cas_authenticatable.gemspec +19 -26
  10. data/lib/devise_cas_authenticatable.rb +15 -70
  11. data/lib/devise_cas_authenticatable/model.rb +21 -28
  12. data/lib/devise_cas_authenticatable/routes.rb +22 -44
  13. data/lib/devise_cas_authenticatable/strategy.rb +14 -24
  14. data/spec/model_spec.rb +29 -35
  15. data/spec/routes_spec.rb +26 -26
  16. data/spec/scenario/app/assets/config/manifest.js +0 -0
  17. data/spec/scenario/app/controllers/home_controller.rb +2 -2
  18. data/spec/scenario/app/views/layouts/application.html.erb +1 -3
  19. data/spec/scenario/config/application.rb +1 -27
  20. data/spec/scenario/config/initializers/backtrace_silencers.rb +1 -1
  21. data/spec/scenario/config/initializers/devise.rb +2 -2
  22. data/spec/scenario/config/routes.rb +0 -4
  23. data/spec/scenario/db/migrate/20100401102949_create_tables.rb +3 -3
  24. data/spec/scenario/db/migrate/20111002012903_add_sessions_table.rb +1 -1
  25. data/spec/scenario/db/migrate/20121009092400_add_deactivated_flag_to_users.rb +1 -1
  26. data/spec/spec_helper.rb +38 -8
  27. data/spec/strategy_spec.rb +43 -82
  28. data/spec/support/migrations.rb +1 -1
  29. metadata +18 -123
  30. data/.travis.yml +0 -45
  31. data/Gemfile.devise12 +0 -11
  32. data/Gemfile.devise13 +0 -11
  33. data/Gemfile.devise14 +0 -11
  34. data/Gemfile.devise15 +0 -11
  35. data/Gemfile.devise20 +0 -11
  36. data/Gemfile.devise21 +0 -13
  37. data/Gemfile.devise30 +0 -12
  38. data/Gemfile.devise42 +0 -13
  39. data/lib/devise_cas_authenticatable/exceptions.rb +0 -10
  40. data/lib/devise_cas_authenticatable/memcache_checker.rb +0 -42
  41. data/lib/devise_cas_authenticatable/railtie.rb +0 -14
  42. data/lib/devise_cas_authenticatable/schema.rb +0 -20
  43. data/lib/devise_cas_authenticatable/session_store_identifier.rb +0 -29
  44. data/lib/devise_cas_authenticatable/single_sign_out.rb +0 -69
  45. data/lib/devise_cas_authenticatable/single_sign_out/rack.rb +0 -39
  46. data/lib/devise_cas_authenticatable/single_sign_out/strategies.rb +0 -58
  47. data/lib/devise_cas_authenticatable/single_sign_out/strategies/base.rb +0 -11
  48. data/lib/devise_cas_authenticatable/single_sign_out/strategies/rails_cache.rb +0 -31
  49. data/lib/devise_cas_authenticatable/single_sign_out/strategies/redis_cache.rb +0 -38
  50. data/lib/devise_cas_authenticatable/single_sign_out/warden_failure_app.rb +0 -46
  51. data/lib/devise_cas_authenticatable/single_sign_out/with_conn.rb +0 -14
  52. data/spec/config_spec.rb +0 -27
  53. data/spec/memcache_checker_spec.rb +0 -49
  54. data/spec/scenario/config/castronaut.yml +0 -32
  55. data/spec/scenario/config/initializers/castronaut.rb +0 -1
  56. data/spec/scenario/config/initializers/session_store.rb +0 -8
  57. data/spec/single_sign_out_spec.rb +0 -51
  58. data/spec/support/urls.rb +0 -19
  59. data/spec/warden_failure_app_spec.rb +0 -53
@@ -1,11 +0,0 @@
1
- module DeviseCasAuthenticatable
2
- module SingleSignOut
3
- module Strategies
4
- class Base
5
- def logger
6
- @logger ||= Rails.logger
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,31 +0,0 @@
1
- module DeviseCasAuthenticatable
2
- module SingleSignOut
3
- module Strategies
4
- class RailsCache < Base
5
- def store_session_id_for_index(session_index, session_id)
6
- logger.debug("Storing #{session_id} for index #{session_index}")
7
- Rails.cache.write(cache_key(session_index), session_id)
8
- end
9
-
10
- def find_session_id_by_index(session_index)
11
- sid = Rails.cache.read(cache_key(session_index))
12
- logger.debug("Found session id #{sid} for index #{session_index}")
13
- sid
14
- end
15
-
16
- def delete_session_index(session_index)
17
- logger.debug("Deleting index #{session_index}")
18
- Rails.cache.delete(cache_key(session_index))
19
- end
20
-
21
- private
22
-
23
- def cache_key(session_index)
24
- "devise_cas_authenticatable:#{session_index}"
25
- end
26
- end
27
- end
28
- end
29
- end
30
-
31
- ::DeviseCasAuthenticatable::SingleSignOut::Strategies.add( :rails_cache, DeviseCasAuthenticatable::SingleSignOut::Strategies::RailsCache )
@@ -1,38 +0,0 @@
1
- require 'devise_cas_authenticatable/single_sign_out/with_conn'
2
-
3
- module DeviseCasAuthenticatable
4
- module SingleSignOut
5
- module Strategies
6
- class RedisCache < Base
7
- include ::DeviseCasAuthenticatable::SingleSignOut::DestroySession
8
- include ::DeviseCasAuthenticatable::SingleSignOut::WithConn
9
-
10
- def store_session_id_for_index(session_index, session_id)
11
- logger.debug("Storing #{session_id} for index #{session_index}")
12
- with_conn do |conn|
13
- conn.set(
14
- cache_key(session_index),
15
- session_id
16
- )
17
- end
18
- end
19
- def find_session_id_by_index(session_index)
20
- sid = with_conn { |conn| conn.get(cache_key(session_index)) }
21
- logger.debug("Found session id #{sid} for index #{session_index}") if sid
22
- sid
23
- end
24
- def delete_session_index(session_index)
25
- logger.debug("Deleting index #{session_index}")
26
- destroy_session_by_id(session_index)
27
- end
28
-
29
- private
30
- def cache_key(session_index)
31
- "devise_cas_authenticatable:#{session_index}"
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
38
- ::DeviseCasAuthenticatable::SingleSignOut::Strategies.add(:redis_cache, DeviseCasAuthenticatable::SingleSignOut::Strategies::RedisCache )
@@ -1,46 +0,0 @@
1
- # Redirect to the logout url when :warden is thrown,
2
- # so that a single_sign_out request can be initiated
3
- class DeviseCasAuthenticatable::SingleSignOut::WardenFailureApp < Devise::FailureApp
4
-
5
- # You need to override respond to eliminate recall
6
- def respond
7
- if http_auth?
8
- http_auth
9
- else
10
- redirect
11
- end
12
- end
13
-
14
- def redirect
15
- store_location!
16
- if flash[:timedout] && flash[:alert]
17
- flash.keep(:timedout)
18
- flash.keep(:alert)
19
- else
20
- flash[:alert] = i18n_message
21
- end
22
- redirect_to redirect_url
23
- end
24
-
25
- protected
26
-
27
- def redirect_url
28
- if [:timeout, :inactive].include? warden_message
29
- flash[:timedout] = true if warden_message == :timeout
30
- Devise.cas_client.logout_url
31
- else
32
- if respond_to?(:scope_path)
33
- scope_path
34
- else
35
- super
36
- end
37
- end
38
- end
39
-
40
- # Devise < 2.0 doesn't have this method, which we want to use
41
- unless instance_methods.include?(:warden_message)
42
- define_method :warden_message do
43
- @message ||= warden.message || warden_options[:message]
44
- end
45
- end
46
- end
@@ -1,14 +0,0 @@
1
- module DeviseCasAuthenticatable
2
- module SingleSignOut
3
- module WithConn
4
- def with_conn(&block)
5
- if old_style_conn = current_session_store.instance_variable_get(:@pool)
6
- yield old_style_conn
7
- else
8
- current_session_store.instance_variable_get(:@conn)
9
- .instance_variable_get(:@pool).with &block
10
- end
11
- end
12
- end
13
- end
14
- end
data/spec/config_spec.rb DELETED
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Devise
4
- def self.reset_cas_client!
5
- @@cas_client = nil
6
- end
7
- end
8
-
9
- describe Devise do
10
- before do
11
- Devise.cas_base_url = "http://www.example.com/cas_server"
12
- end
13
-
14
- after { Devise.reset_cas_client! }
15
-
16
- it "should figure out the base URL correctly" do
17
- Devise.cas_client.cas_base_url.should == "http://www.example.com/cas_server"
18
- end
19
-
20
- it 'should accept extra options for the CAS client object' do
21
- Devise.cas_client_config_options = { :encode_extra_attributes_as => :json }
22
-
23
- conf_options = Devise.cas_client.instance_variable_get(:@conf_options)
24
- conf_options.should_not be_nil
25
- conf_options[:encode_extra_attributes_as].should == :json
26
- end
27
- end
@@ -1,49 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DeviseCasAuthenticatable::MemcacheChecker do
4
- let(:conf_double) { stub(session_options: {}) }
5
-
6
- describe '#session_store_memcache?' do
7
- subject(:session_store_memcache?) { described_class.new(conf_double).session_store_memcache? }
8
-
9
- before do
10
- DeviseCasAuthenticatable::SessionStoreIdentifier.any_instance
11
- .stubs(:session_store_class).returns(session_store_class)
12
- end
13
-
14
- context "when session store is memcache" do
15
- let(:session_store_class) { FakeMemcacheStore }
16
-
17
- it { expect(session_store_memcache?).to eq true }
18
- end
19
-
20
- context "when session store is NOT memcache" do
21
- let(:session_store_class) { String }
22
-
23
- it { expect(session_store_memcache?).to eq false }
24
- end
25
- end
26
-
27
- describe 'alive?' do
28
- context "when memcache is down" do
29
- let(:conf_double) { stub(session_options: {memcache_server: ['127.0.0.1:11223']}) }
30
- subject(:alive?) { described_class.new(conf_double).alive? }
31
-
32
- it { expect(alive?).to eq false }
33
- end
34
-
35
- context "when memcache is running" do
36
- let(:conf_double) { stub(session_options: {memcache_server: ['127.0.0.1:11214']}) }
37
- subject(:alive?) { described_class.new(conf_double).alive? }
38
-
39
- before do
40
- DeviseCasAuthenticatable::MemcacheChecker.any_instance.stubs(:try_connect)
41
- end
42
-
43
- it { expect(alive?).to eq true }
44
- end
45
- end
46
- end
47
-
48
- class FakeMemcacheStore
49
- end
@@ -1,32 +0,0 @@
1
- organization_name: Foo Bar Baz Industries, LLC Inc. A division of Holdings Co.
2
-
3
- environment: development
4
- # The port the CAS webserver will start on
5
- server_port: 4567
6
-
7
- log_directory: log
8
-
9
- log_level: Logger::DEBUG
10
-
11
- ssl_enabled: false
12
-
13
- cas_database:
14
- adapter: sqlite3
15
- database: db/cas.sqlite3
16
- timeout: 5000
17
-
18
- cas_adapter:
19
- adapter: test_adapter
20
-
21
- # Use this example if you are using LDAP as your authentication source
22
- # cas_adapter:
23
- # adapter: ldap
24
- # host: localhost
25
- # port: 389
26
- # prefix: cn=
27
- # base: dc=example, dc=com
28
-
29
- # Uncomment these to enable authentication callbacks
30
- # callbacks:
31
- # on_authentication_success: http://example.com/authentication/success
32
- # on_authentication_failed: http://example.com/authentication/failed
@@ -1 +0,0 @@
1
- Castronaut.config.connect_activerecord
@@ -1,8 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Scenario::Application.config.session_store :cookie_store, :key => '_scenario_session'
4
-
5
- # Use the database for sessions instead of the cookie-based default,
6
- # which shouldn't be used to store highly confidential information
7
- # (create the session table with "rake db:sessions:create")
8
- Scenario::Application.config.session_store :active_record_store
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DeviseCasAuthenticatable::SingleSignOut::WardenFailureApp do
4
- include RSpec::Rails::RequestExampleGroup
5
- include Capybara::DSL
6
-
7
- describe "A logged in user with a timed out session" do
8
-
9
- before do
10
- Devise.cas_base_url = "http://www.example.com/cas_server"
11
- User.delete_all
12
- @user = User.create!(:username => "joeuser")
13
- end
14
-
15
- describe "using the default warden failure app" do
16
-
17
- before do
18
- sign_into_cas "joeuser", "joepassword"
19
- end
20
-
21
- it "redirects to cas_login_url when warden is thrown" do
22
- Devise::FailureApp.any_instance.expects(:redirect_url).returns(cas_login_url)
23
- Timecop.travel(Devise.timeout_in) do
24
- visit root_url
25
- end
26
- current_url.should == root_url
27
- end
28
-
29
- end
30
-
31
- describe "using the custom WardenFailureApp" do
32
-
33
- before do
34
-
35
- Devise.warden_config[:failure_app] = DeviseCasAuthenticatable::SingleSignOut::WardenFailureApp
36
- sign_into_cas "joeuser", "joepassword"
37
- end
38
-
39
- it "uses the redirect_url from the custom failure class" do
40
- DeviseCasAuthenticatable::SingleSignOut::WardenFailureApp.any_instance.expects(:redirect_url).returns(destroy_user_session_url)
41
- Timecop.travel(Devise.timeout_in) do
42
- visit root_url
43
- end
44
- current_url.should match(/#{cas_logout_url}/)
45
- end
46
-
47
- end
48
-
49
- end
50
-
51
- end
data/spec/support/urls.rb DELETED
@@ -1,19 +0,0 @@
1
- def cas_login_url
2
- @cas_login_url ||= begin
3
- uri = URI.parse(Devise.cas_base_url + "/login")
4
- uri.query = Rack::Utils.build_nested_query(:service => user_service_url)
5
- uri.to_s
6
- end
7
- end
8
-
9
- def cas_logout_url
10
- @cas_logout_url ||= Devise.cas_base_url + "/logout"
11
- end
12
-
13
- def sign_into_cas(username, password)
14
- visit cas_login_url
15
- fill_in "Username", :with => username
16
- fill_in "Password", :with => password
17
- click_on "Login"
18
- current_url.should == root_url
19
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DeviseCasAuthenticatable::SingleSignOut::WardenFailureApp do
4
-
5
- describe "#redirect_url" do
6
-
7
- before do
8
- Devise.cas_base_url = "http://www.example.com/cas_server"
9
- @failure_app = DeviseCasAuthenticatable::SingleSignOut::WardenFailureApp.new
10
- @failure_app.stubs(:flash).returns({})
11
- end
12
-
13
- describe "resulting from a timeout" do
14
-
15
- before do
16
- @failure_app.stubs(:warden_message).returns(:timeout)
17
- end
18
-
19
- it "returns the logout url" do
20
- @failure_app.send(:redirect_url).should match(/#{cas_logout_url}/)
21
- end
22
-
23
- end
24
-
25
- describe "resulting from an inactive" do
26
-
27
- before do
28
- @failure_app.stubs(:warden_message).returns(:inactive)
29
- end
30
-
31
- it "returns the logout url" do
32
- @failure_app.send(:redirect_url).should match(/#{cas_logout_url}/)
33
- end
34
-
35
- end
36
-
37
- describe "resulting from a generic warden :throw error" do
38
-
39
- before do
40
- @failure_app.stubs(:warden_message).returns(nil)
41
- @failure_app.stubs(:flash).returns({})
42
- end
43
-
44
- it "calls the scope_path method to retrieve the standard redirect_url" do
45
- @failure_app.expects(:scope_path)
46
- @failure_app.send(:redirect_url)
47
- end
48
-
49
- end
50
-
51
- end
52
-
53
- end