rubycas-client 2.3.8 → 2.3.9.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: spec/test.sqlite3.db
4
+
5
+ testjruby:
6
+ adapter: jdbcsqlite3
7
+ database: spec/test.sqlite3.db
@@ -1,16 +1,39 @@
1
1
  require 'bundler'
2
-
3
- Bundler.setup(:default, :test)
2
+ Bundler.setup(:default, :development)
3
+ require 'simplecov' unless ENV['TRAVIS']
4
4
  Bundler.require
5
5
 
6
+ require 'rubycas-client'
7
+
8
+ SPEC_TMP_DIR="spec/tmp"
9
+
10
+ Dir["./spec/support/**/*.rb"].each do |f|
11
+ require f.gsub('.rb','') unless f.end_with? '_spec.rb'
12
+ end
13
+
14
+ require 'database_cleaner'
15
+
6
16
  RSpec.configure do |config|
7
- #config.include Rack::Test::Methods
8
- #config.include Webrat::Methods
9
- #config.include Webrat::Matchers
10
- #config.include TestHelpers
11
- #config.include Helpers
12
17
  config.mock_with :rspec
13
18
  config.mock_framework = :rspec
19
+ config.include ActionControllerHelpers
20
+
21
+ config.before(:suite) do
22
+ ActiveRecordHelpers.setup_active_record
23
+ DatabaseCleaner.strategy = :transaction
24
+ DatabaseCleaner.clean_with(:truncation)
25
+ end
26
+
27
+ config.after(:suite) do
28
+ ActiveRecordHelpers.teardown_active_record
29
+ end
30
+
31
+ config.before(:each) do
32
+ DatabaseCleaner.start
33
+ end
34
+
35
+ config.after(:each) do
36
+ DatabaseCleaner.clean
37
+ end
14
38
  end
15
39
 
16
- require 'rubycas-client'
@@ -0,0 +1,30 @@
1
+ require 'action_pack'
2
+
3
+ module ActionControllerHelpers
4
+
5
+ def mock_controller_with_session(request = nil, session={})
6
+
7
+ query_parameters = {:ticket => "bogusticket", :renew => false}
8
+ parameters = query_parameters.dup
9
+
10
+ #TODO this really need to be replaced with a "real" rails controller
11
+ request ||= mock_post_request
12
+ request.stub(:query_parameters) {query_parameters}
13
+ request.stub(:path_parameters) {{}}
14
+ controller = double("Controller")
15
+ controller.stub(:session) {session}
16
+ controller.stub(:request) {request}
17
+ controller.stub(:url_for) {"bogusurl"}
18
+ controller.stub(:query_parameters) {query_parameters}
19
+ controller.stub(:path_parameters) {{}}
20
+ controller.stub(:parameters) {parameters}
21
+ controller.stub(:params) {parameters}
22
+ controller
23
+ end
24
+
25
+ def mock_post_request
26
+ mock_request = ActionController::Request.new({})
27
+ mock_request.stub(:post?) {true}
28
+ mock_request
29
+ end
30
+ end
@@ -0,0 +1,48 @@
1
+ require 'active_record'
2
+
3
+ module ActiveRecordHelpers
4
+
5
+ class << self
6
+ def setup_active_record
7
+ config_file = File.open("spec/database.yml")
8
+ db_config = HashWithIndifferentAccess.new(YAML.load(config_file))
9
+ ActiveRecord::Base.establish_connection(db_config[(RUBY_PLATFORM == "java") ? :testjruby : :test])
10
+ ActiveRecord::Migration.verbose = false
11
+ RubyCasTables.migrate(:up)
12
+ end
13
+
14
+ def teardown_active_record
15
+ ActiveRecord::Migration.verbose = false
16
+ RubyCasTables.migrate(:down)
17
+ end
18
+ end
19
+
20
+ class RubyCasTables < ActiveRecord::Migration
21
+ def self.up
22
+ #default rails sessions table
23
+ create_table :sessions do |t|
24
+ t.string :session_id, :null => false
25
+ t.text :data
26
+ t.timestamps
27
+ end
28
+ add_index :sessions, :session_id
29
+ add_index :sessions, :updated_at
30
+
31
+ #column added to sessions table by rubycas-client
32
+ add_column :sessions, :service_ticket, :string
33
+ add_index :sessions, :service_ticket
34
+
35
+ # pgtious table
36
+ create_table :cas_pgtious do |t|
37
+ t.string :pgt_iou, :null => false
38
+ t.string :pgt_id, :null => false
39
+ t.timestamps
40
+ end
41
+ end
42
+
43
+ def self.down
44
+ drop_table :sessions
45
+ drop_table :cas_pgtious
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ require 'casclient/tickets/storage'
2
+
3
+ class LocalHashTicketStore < CASClient::Tickets::Storage::AbstractTicketStore
4
+
5
+ attr_accessor :st_hash
6
+ attr_accessor :pgt_hash
7
+
8
+ def store_service_session_lookup(st, controller)
9
+ raise CASClient::CASException, "No service_ticket specified." if st.nil?
10
+ raise CASClient::CASException, "No controller specified." if controller.nil?
11
+ session_id = session_id_from_controller(controller)
12
+ st = st.ticket if st.kind_of? CASClient::ServiceTicket
13
+ st_hash[st] = session_id
14
+ end
15
+
16
+ def read_service_session_lookup(st)
17
+ raise CASClient::CASException, "No service_ticket specified." if st.nil?
18
+ st = st.ticket if st.kind_of? CASClient::ServiceTicket
19
+ st_hash[st]
20
+ end
21
+
22
+ def cleanup_service_session_lookup(st)
23
+ raise CASClient::CASException, "No service_ticket specified." if st.nil?
24
+ st = st.ticket if st.kind_of? CASClient::ServiceTicket
25
+ st_hash.delete(st)
26
+ end
27
+
28
+ def save_pgt_iou(pgt_iou, pgt)
29
+ raise CASClient::CASException.new("Invalid pgt_iou") if pgt_iou.nil?
30
+ raise CASClient::CASException.new("Invalid pgt") if pgt.nil?
31
+ pgt_hash[pgt_iou] = pgt
32
+ end
33
+
34
+ def retrieve_pgt(pgt_iou)
35
+ pgt = pgt_hash.delete(pgt_iou)
36
+ raise CASClient::CASException.new("Invalid pgt_iou") if pgt.nil?
37
+ pgt
38
+ end
39
+
40
+ def pgt_hash
41
+ @pgt_hash ||= {}
42
+ end
43
+
44
+ def st_hash
45
+ @pgt_hash ||= {}
46
+ end
47
+
48
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe LocalHashTicketStore do
4
+ it_should_behave_like "a ticket store"
5
+ end
@@ -0,0 +1,137 @@
1
+ shared_examples "a ticket store interacting with sessions" do
2
+ describe "#store_service_session_lookup" do
3
+ it "should raise CASException if the Service Ticket is nil" do
4
+ expect { subject.store_service_session_lookup(nil, "controller") }.to raise_exception(CASClient::CASException, /No service_ticket specified/)
5
+ end
6
+ it "should raise CASException if the controller is nil" do
7
+ expect { subject.store_service_session_lookup("service_ticket", nil) }.to raise_exception(CASClient::CASException, /No controller specified/)
8
+ end
9
+ it "should store the ticket without any errors" do
10
+ expect { subject.store_service_session_lookup(service_ticket, mock_controller_with_session(nil, session)) }.to_not raise_exception
11
+ end
12
+ end
13
+
14
+ describe "#get_session_for_service_ticket" do
15
+ context "the service ticket is nil" do
16
+ it "should raise CASException" do
17
+ expect { subject.get_session_for_service_ticket(nil) }.to raise_exception(CASClient::CASException, /No service_ticket specified/)
18
+ end
19
+ end
20
+ context "the service ticket is associated with a session" do
21
+ before do
22
+ subject.store_service_session_lookup(service_ticket, mock_controller_with_session(nil, session))
23
+ session.save!
24
+ end
25
+ it "should return the session_id and session for the given service ticket" do
26
+ result_session_id, result_session = subject.get_session_for_service_ticket(service_ticket)
27
+ result_session_id.should == session.session_id
28
+ result_session.session_id.should == session.session_id
29
+ result_session.data.should == session.data
30
+ end
31
+ end
32
+ context "the service ticket is not associated with a session" do
33
+ it "should return nils if there is no session for the given service ticket" do
34
+ subject.get_session_for_service_ticket(service_ticket).should == [nil, nil]
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#process_single_sign_out" do
40
+ context "the service ticket is nil" do
41
+ it "should raise CASException" do
42
+ expect { subject.process_single_sign_out(nil) }.to raise_exception(CASClient::CASException, /No service_ticket specified/)
43
+ end
44
+ end
45
+ context "the service ticket is associated with a session" do
46
+ before do
47
+ subject.store_service_session_lookup(service_ticket, mock_controller_with_session(nil, session))
48
+ session.save!
49
+ subject.process_single_sign_out(service_ticket)
50
+ end
51
+ context "the session" do
52
+ it "should be destroyed" do
53
+ ActiveRecord::SessionStore.session_class.find_by_session_id(session.session_id).should be_nil
54
+ end
55
+ end
56
+ it "should destroy session for the given service ticket" do
57
+ subject.process_single_sign_out(service_ticket)
58
+ end
59
+ end
60
+ context "the service ticket is not associated with a session" do
61
+ it "should run without error if there is no session for the given service ticket" do
62
+ expect { subject.process_single_sign_out(service_ticket) }.to_not raise_error
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "#cleanup_service_session_lookup" do
68
+ context "the service ticket is nil" do
69
+ it "should raise CASException" do
70
+ expect { subject.cleanup_service_session_lookup(nil) }.to raise_exception(CASClient::CASException, /No service_ticket specified/)
71
+ end
72
+ end
73
+ it "should run without error" do
74
+ expect { subject.cleanup_service_session_lookup(service_ticket) }.to_not raise_exception
75
+ end
76
+ end
77
+ end
78
+
79
+ shared_examples "a ticket store" do
80
+ let(:ticket_store) { described_class.new }
81
+ let(:service_url) { "https://www.example.com/cas" }
82
+ let(:session) do
83
+ ActiveRecord::SessionStore::Session.create!(:session_id => "session#{rand(1000)}", :data => {})
84
+ end
85
+ subject { ticket_store }
86
+
87
+ context "when dealing with sessions, Service Tickets, and Single Sign Out" do
88
+ context "and the service ticket is a String" do
89
+ it_behaves_like "a ticket store interacting with sessions" do
90
+ let(:service_ticket) { "ST-ABC#{rand(1000)}" }
91
+ end
92
+ end
93
+ context "and the service ticket is a ServiceTicket" do
94
+ it_behaves_like "a ticket store interacting with sessions" do
95
+ let(:service_ticket) { CASClient::ServiceTicket.new("ST-ABC#{rand(1000)}", service_url) }
96
+ end
97
+ end
98
+ context "and the service ticket is a ProxyTicket" do
99
+ it_behaves_like "a ticket store interacting with sessions" do
100
+ let(:service_ticket) { CASClient::ProxyTicket.new("ST-ABC#{rand(1000)}", service_url) }
101
+ end
102
+ end
103
+ end
104
+
105
+ context "when dealing with Proxy Granting Tickets and their IOUs" do
106
+ let(:pgt) { "my_pgt_#{rand(1000)}" }
107
+ let(:pgt_iou) { "my_pgt_iou_#{rand(1000)}" }
108
+
109
+ describe "#save_pgt_iou" do
110
+ it "should raise CASClient::CASException if the pgt_iou is nil" do
111
+ expect { subject.save_pgt_iou(nil, pgt) }.to raise_exception(CASClient::CASException, /Invalid pgt_iou/)
112
+ end
113
+ it "should raise CASClient::CASException if the pgt is nil" do
114
+ expect { subject.save_pgt_iou(pgt_iou, nil) }.to raise_exception(CASClient::CASException, /Invalid pgt/)
115
+ end
116
+ end
117
+
118
+ describe "#retrieve_pgt" do
119
+ before do
120
+ subject.save_pgt_iou(pgt_iou, pgt)
121
+ end
122
+
123
+ it "should return the stored pgt" do
124
+ subject.retrieve_pgt(pgt_iou).should == pgt
125
+ end
126
+
127
+ it "should raise CASClient::CASException if the pgt_iou isn't in the store" do
128
+ expect { subject.retrieve_pgt("not_my"+pgt_iou) }.to raise_exception(CASClient::CASException, /Invalid pgt_iou/)
129
+ end
130
+
131
+ it "should not return the stored pgt a second time" do
132
+ subject.retrieve_pgt(pgt_iou).should == pgt
133
+ expect { subject.retrieve_pgt(pgt_iou) }.to raise_exception(CASClient::CASException, /Invalid pgt_iou/)
134
+ end
135
+ end
136
+ end
137
+ end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycas-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.8
5
- prerelease:
4
+ version: 2.3.9.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matt Zukowski
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-12-19 00:00:00.000000000Z
14
+ date: 2012-03-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &70206959748580 !ruby/object:Gem::Requirement
18
+ requirement: &70109785006580 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,32 +23,32 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70206959748580
26
+ version_requirements: *70109785006580
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
- requirement: &70206959747260 !ruby/object:Gem::Requirement
29
+ requirement: &70109785005920 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
- - - ~>
32
+ - - ! '>='
33
33
  - !ruby/object:Gem::Version
34
- version: 1.6.1
34
+ version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *70206959747260
37
+ version_requirements: *70109785005920
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &70206959746080 !ruby/object:Gem::Requirement
40
+ requirement: &70109785005200 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 2.7.0
45
+ version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70206959746080
48
+ version_requirements: *70109785005200
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: bundler
51
- requirement: &70206959745140 !ruby/object:Gem::Requirement
51
+ requirement: &70109785004560 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,21 +56,32 @@ dependencies:
56
56
  version: '1.0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70206959745140
59
+ version_requirements: *70109785004560
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: jeweler
62
- requirement: &70206959743740 !ruby/object:Gem::Requirement
62
+ requirement: &70109785003840 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
- - - ~>
65
+ - - ! '>='
66
66
  - !ruby/object:Gem::Version
67
- version: 1.6.2
67
+ version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70206959743740
70
+ version_requirements: *70109785003840
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: actionpack
73
- requirement: &70206959742080 !ruby/object:Gem::Requirement
73
+ requirement: &70109785002580 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *70109785002580
82
+ - !ruby/object:Gem::Dependency
83
+ name: activerecord
84
+ requirement: &70109785001820 !ruby/object:Gem::Requirement
74
85
  none: false
75
86
  requirements:
76
87
  - - ! '>='
@@ -78,10 +89,76 @@ dependencies:
78
89
  version: '0'
79
90
  type: :development
80
91
  prerelease: false
81
- version_requirements: *70206959742080
92
+ version_requirements: *70109785001820
82
93
  - !ruby/object:Gem::Dependency
83
94
  name: rake
84
- requirement: &70206959740920 !ruby/object:Gem::Requirement
95
+ requirement: &70109785001120 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *70109785001120
104
+ - !ruby/object:Gem::Dependency
105
+ name: simplecov
106
+ requirement: &70109785000440 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *70109785000440
115
+ - !ruby/object:Gem::Dependency
116
+ name: guard
117
+ requirement: &70109784999740 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: *70109784999740
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-rspec
128
+ requirement: &70109784998920 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: *70109784998920
137
+ - !ruby/object:Gem::Dependency
138
+ name: database_cleaner
139
+ requirement: &70109784995060 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: *70109784995060
148
+ - !ruby/object:Gem::Dependency
149
+ name: sqlite3
150
+ requirement: &70109784992260 !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ type: :development
157
+ prerelease: false
158
+ version_requirements: *70109784992260
159
+ - !ruby/object:Gem::Dependency
160
+ name: jruby-openssl
161
+ requirement: &70109784990620 !ruby/object:Gem::Requirement
85
162
  none: false
86
163
  requirements:
87
164
  - - ! '>='
@@ -89,10 +166,10 @@ dependencies:
89
166
  version: '0'
90
167
  type: :development
91
168
  prerelease: false
92
- version_requirements: *70206959740920
169
+ version_requirements: *70109784990620
93
170
  - !ruby/object:Gem::Dependency
94
- name: rcov
95
- requirement: &70206959740000 !ruby/object:Gem::Requirement
171
+ name: activerecord-jdbcsqlite3-adapter
172
+ requirement: &70109784753060 !ruby/object:Gem::Requirement
96
173
  none: false
97
174
  requirements:
98
175
  - - ! '>='
@@ -100,7 +177,7 @@ dependencies:
100
177
  version: '0'
101
178
  type: :development
102
179
  prerelease: false
103
- version_requirements: *70206959740000
180
+ version_requirements: *70109784753060
104
181
  description:
105
182
  email:
106
183
  executables: []
@@ -110,10 +187,12 @@ extra_rdoc_files:
110
187
  - README.rdoc
111
188
  files:
112
189
  - .rspec
190
+ - .simplecov
113
191
  - .travis.yml
114
192
  - CHANGELOG.txt
115
193
  - Gemfile
116
194
  - Gemfile.lock
195
+ - Guardfile
117
196
  - History.txt
118
197
  - LICENSE.txt
119
198
  - README.rdoc
@@ -157,9 +236,19 @@ files:
157
236
  - rails_generators/active_record_ticket_store/templates/README
158
237
  - rails_generators/active_record_ticket_store/templates/migration.rb
159
238
  - rubycas-client.gemspec
239
+ - spec/.gitignore
240
+ - spec/casclient/client_spec.rb
160
241
  - spec/casclient/frameworks/rails/filter_spec.rb
242
+ - spec/casclient/tickets/storage/active_record_ticket_store_spec.rb
243
+ - spec/casclient/tickets/storage_spec.rb
161
244
  - spec/casclient/validation_response_spec.rb
245
+ - spec/database.yml
162
246
  - spec/spec_helper.rb
247
+ - spec/support/action_controller_helpers.rb
248
+ - spec/support/active_record_helpers.rb
249
+ - spec/support/local_hash_ticket_store.rb
250
+ - spec/support/local_hash_ticket_store_spec.rb
251
+ - spec/support/shared_examples_for_ticket_stores.rb
163
252
  homepage: http://github.com/rubycas/rubycas-client
164
253
  licenses:
165
254
  - MIT
@@ -177,16 +266,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
266
  version: '0'
178
267
  segments:
179
268
  - 0
180
- hash: -2445786591382746754
269
+ hash: -1272570906276872327
181
270
  required_rubygems_version: !ruby/object:Gem::Requirement
182
271
  none: false
183
272
  requirements:
184
- - - ! '>='
273
+ - - ! '>'
185
274
  - !ruby/object:Gem::Version
186
- version: '0'
275
+ version: 1.3.1
187
276
  requirements: []
188
277
  rubyforge_project:
189
- rubygems_version: 1.8.10
278
+ rubygems_version: 1.8.11
190
279
  signing_key:
191
280
  specification_version: 3
192
281
  summary: Client library for the Central Authentication Service (CAS) protocol.