rubycas-client 2.3.8 → 2.3.9.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,21 +5,23 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rubycas-client"
8
- s.version = "2.3.8"
8
+ s.version = "2.3.9.rc1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Zukowski", "Matt Walker", "Matt Campbell"]
12
- s.date = "2011-12-19"
12
+ s.date = "2012-03-24"
13
13
  s.extra_rdoc_files = [
14
14
  "LICENSE.txt",
15
15
  "README.rdoc"
16
16
  ]
17
17
  s.files = [
18
18
  ".rspec",
19
+ ".simplecov",
19
20
  ".travis.yml",
20
21
  "CHANGELOG.txt",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
24
+ "Guardfile",
23
25
  "History.txt",
24
26
  "LICENSE.txt",
25
27
  "README.rdoc",
@@ -63,15 +65,25 @@ Gem::Specification.new do |s|
63
65
  "rails_generators/active_record_ticket_store/templates/README",
64
66
  "rails_generators/active_record_ticket_store/templates/migration.rb",
65
67
  "rubycas-client.gemspec",
68
+ "spec/.gitignore",
69
+ "spec/casclient/client_spec.rb",
66
70
  "spec/casclient/frameworks/rails/filter_spec.rb",
71
+ "spec/casclient/tickets/storage/active_record_ticket_store_spec.rb",
72
+ "spec/casclient/tickets/storage_spec.rb",
67
73
  "spec/casclient/validation_response_spec.rb",
68
- "spec/spec_helper.rb"
74
+ "spec/database.yml",
75
+ "spec/spec_helper.rb",
76
+ "spec/support/action_controller_helpers.rb",
77
+ "spec/support/active_record_helpers.rb",
78
+ "spec/support/local_hash_ticket_store.rb",
79
+ "spec/support/local_hash_ticket_store_spec.rb",
80
+ "spec/support/shared_examples_for_ticket_stores.rb"
69
81
  ]
70
82
  s.homepage = "http://github.com/rubycas/rubycas-client"
71
83
  s.licenses = ["MIT"]
72
84
  s.rdoc_options = ["--main", "README.rdoc"]
73
85
  s.require_paths = ["lib"]
74
- s.rubygems_version = "1.8.10"
86
+ s.rubygems_version = "1.8.11"
75
87
  s.summary = "Client library for the Central Authentication Service (CAS) protocol."
76
88
 
77
89
  if s.respond_to? :specification_version then
@@ -79,32 +91,53 @@ Gem::Specification.new do |s|
79
91
 
80
92
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
81
93
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
82
- s.add_development_dependency(%q<json>, ["~> 1.6.1"])
83
- s.add_development_dependency(%q<rspec>, ["~> 2.7.0"])
94
+ s.add_development_dependency(%q<json>, [">= 0"])
95
+ s.add_development_dependency(%q<rspec>, [">= 0"])
84
96
  s.add_development_dependency(%q<bundler>, [">= 1.0"])
85
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
97
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
86
98
  s.add_development_dependency(%q<actionpack>, [">= 0"])
99
+ s.add_development_dependency(%q<activerecord>, [">= 0"])
87
100
  s.add_development_dependency(%q<rake>, [">= 0"])
88
- s.add_development_dependency(%q<rcov>, [">= 0"])
101
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
102
+ s.add_development_dependency(%q<guard>, [">= 0"])
103
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
104
+ s.add_development_dependency(%q<database_cleaner>, [">= 0"])
105
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
106
+ s.add_development_dependency(%q<jruby-openssl>, [">= 0"])
107
+ s.add_development_dependency(%q<activerecord-jdbcsqlite3-adapter>, [">= 0"])
89
108
  else
90
109
  s.add_dependency(%q<activesupport>, [">= 0"])
91
- s.add_dependency(%q<json>, ["~> 1.6.1"])
92
- s.add_dependency(%q<rspec>, ["~> 2.7.0"])
110
+ s.add_dependency(%q<json>, [">= 0"])
111
+ s.add_dependency(%q<rspec>, [">= 0"])
93
112
  s.add_dependency(%q<bundler>, [">= 1.0"])
94
- s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
113
+ s.add_dependency(%q<jeweler>, [">= 0"])
95
114
  s.add_dependency(%q<actionpack>, [">= 0"])
115
+ s.add_dependency(%q<activerecord>, [">= 0"])
96
116
  s.add_dependency(%q<rake>, [">= 0"])
97
- s.add_dependency(%q<rcov>, [">= 0"])
117
+ s.add_dependency(%q<simplecov>, [">= 0"])
118
+ s.add_dependency(%q<guard>, [">= 0"])
119
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
120
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
121
+ s.add_dependency(%q<sqlite3>, [">= 0"])
122
+ s.add_dependency(%q<jruby-openssl>, [">= 0"])
123
+ s.add_dependency(%q<activerecord-jdbcsqlite3-adapter>, [">= 0"])
98
124
  end
99
125
  else
100
126
  s.add_dependency(%q<activesupport>, [">= 0"])
101
- s.add_dependency(%q<json>, ["~> 1.6.1"])
102
- s.add_dependency(%q<rspec>, ["~> 2.7.0"])
127
+ s.add_dependency(%q<json>, [">= 0"])
128
+ s.add_dependency(%q<rspec>, [">= 0"])
103
129
  s.add_dependency(%q<bundler>, [">= 1.0"])
104
- s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
130
+ s.add_dependency(%q<jeweler>, [">= 0"])
105
131
  s.add_dependency(%q<actionpack>, [">= 0"])
132
+ s.add_dependency(%q<activerecord>, [">= 0"])
106
133
  s.add_dependency(%q<rake>, [">= 0"])
107
- s.add_dependency(%q<rcov>, [">= 0"])
134
+ s.add_dependency(%q<simplecov>, [">= 0"])
135
+ s.add_dependency(%q<guard>, [">= 0"])
136
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
137
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
138
+ s.add_dependency(%q<sqlite3>, [">= 0"])
139
+ s.add_dependency(%q<jruby-openssl>, [">= 0"])
140
+ s.add_dependency(%q<activerecord-jdbcsqlite3-adapter>, [">= 0"])
108
141
  end
109
142
  end
110
143
 
@@ -0,0 +1 @@
1
+ test.*.db
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe CASClient::Client do
4
+ let(:client) { CASClient::Client.new(:login_url => login_url, :cas_base_url => '')}
5
+ let(:login_url) { "http://localhost:3443/"}
6
+ let(:uri) { URI.parse(login_url) }
7
+ let(:session) { double('session', :use_ssl= => true, :verify_mode= => true) }
8
+
9
+ context "https connection" do
10
+ let(:proxy) { double('proxy', :new => session) }
11
+
12
+ before :each do
13
+ Net::HTTP.stub :Proxy => proxy
14
+ end
15
+
16
+ it "sets up the session with the login url host and port" do
17
+ proxy.should_receive(:new).with('localhost', 3443).and_return(session)
18
+ client.send(:https_connection, uri)
19
+ end
20
+
21
+ it "sets up the proxy with the known proxy host and port" do
22
+ client = CASClient::Client.new(:login_url => login_url, :cas_base_url => '', :proxy_host => 'foo', :proxy_port => 1234)
23
+ Net::HTTP.should_receive(:Proxy).with('foo', 1234).and_return(proxy)
24
+ client.send(:https_connection, uri)
25
+ end
26
+ end
27
+
28
+ context "cas server requests" do
29
+ let(:response) { double('response', :body => 'HTTP BODY', :code => '200') }
30
+ let(:connection) { double('connection', :get => response, :post => response, :request => response) }
31
+
32
+ before :each do
33
+ client.stub(:https_connection).and_return(session)
34
+ session.stub(:start).and_yield(connection)
35
+ end
36
+
37
+ context "cas server is up" do
38
+ it "returns false if the server cannot be connected to" do
39
+ connection.stub(:get).and_raise(Errno::ECONNREFUSED)
40
+ client.cas_server_is_up?.should be_false
41
+ end
42
+
43
+ it "returns false if the request was not a success" do
44
+ response.stub :kind_of? => false
45
+ client.cas_server_is_up?.should be_false
46
+ end
47
+
48
+ it "returns true when the server is running" do
49
+ response.stub :kind_of? => true
50
+ client.cas_server_is_up?.should be_true
51
+ end
52
+ end
53
+
54
+ context "request login ticket" do
55
+ it "raises an exception when the request was not a success" do
56
+ session.stub(:post).with("/Ticket", ";").and_return(response)
57
+ response.stub :kind_of? => false
58
+ lambda {
59
+ client.request_login_ticket
60
+ }.should raise_error(CASClient::CASException)
61
+ end
62
+
63
+ it "returns the response body when the request is a success" do
64
+ session.stub(:post).with("/Ticket", ";").and_return(response)
65
+ response.stub :kind_of? => true
66
+ client.request_login_ticket.should == "HTTP BODY"
67
+ end
68
+ end
69
+
70
+ context "request cas response" do
71
+ let(:validation_response) { double('validation_response') }
72
+
73
+ it "should raise an exception when the request is not a success or 422" do
74
+ response.stub :kind_of? => false
75
+ lambda {
76
+ client.send(:request_cas_response, uri, CASClient::ValidationResponse)
77
+ }.should raise_error(RuntimeError)
78
+ end
79
+
80
+ it "should return a ValidationResponse object when the request is a success or 422" do
81
+ CASClient::ValidationResponse.stub(:new).and_return(validation_response)
82
+ response.stub :kind_of? => true
83
+ client.send(:request_cas_response, uri, CASClient::ValidationResponse).should == validation_response
84
+ end
85
+ end
86
+
87
+ context "submit data to cas" do
88
+ it "should return an HTTPResponse" do
89
+ client.send(:submit_data_to_cas, uri, {}).should == response
90
+ end
91
+ end
92
+ end
93
+ end
@@ -4,32 +4,6 @@ require 'casclient/frameworks/rails/filter'
4
4
 
5
5
  describe CASClient::Frameworks::Rails::Filter do
6
6
 
7
- def controller_with_session(request = nil, session={})
8
-
9
- query_parameters = {:ticket => "bogusticket", :renew => false}
10
- parameters = query_parameters.dup
11
-
12
- #TODO this really need to be replaced with a "real" rails controller
13
- request ||= mock_post_request
14
- request.stub(:query_parameters) {query_parameters}
15
- request.stub(:path_parameters) {{}}
16
- controller = double("Controller")
17
- controller.stub(:session) {session}
18
- controller.stub(:request) {request}
19
- controller.stub(:url_for) {"bogusurl"}
20
- controller.stub(:query_parameters) {query_parameters}
21
- controller.stub(:path_parameters) {{}}
22
- controller.stub(:parameters) {parameters}
23
- controller.stub(:params) {parameters}
24
- controller
25
- end
26
-
27
- def mock_post_request
28
- mock_request = ActionController::Request.new({})
29
- mock_request.stub(:post?) {true}
30
- mock_request
31
- end
32
-
33
7
  before(:each) do
34
8
  CASClient::Frameworks::Rails::Filter.configure(
35
9
  :cas_base_url => 'http://test.local/',
@@ -42,7 +16,7 @@ describe CASClient::Frameworks::Rails::Filter do
42
16
  context "faking user without attributes" do
43
17
  before { CASClient::Frameworks::Rails::Filter.fake('tester@test.com') }
44
18
  it 'should set the session user' do
45
- CASClient::Frameworks::Rails::Filter.filter(controller_with_session(nil, subject))
19
+ CASClient::Frameworks::Rails::Filter.filter(mock_controller_with_session(nil, subject))
46
20
  subject.should eq({:cas_user => 'tester@test.com', :casfilteruser => 'tester@test.com'})
47
21
  end
48
22
  after { CASClient::Frameworks::Rails::Filter.fake(nil,nil) }
@@ -51,7 +25,7 @@ describe CASClient::Frameworks::Rails::Filter do
51
25
  context "faking user with attributes" do
52
26
  before { CASClient::Frameworks::Rails::Filter.fake('tester@test.com', {:test => 'stuff', :this => 'that'}) }
53
27
  it 'should set the session user and attributes' do
54
- CASClient::Frameworks::Rails::Filter.filter(controller_with_session(nil, subject))
28
+ CASClient::Frameworks::Rails::Filter.filter(mock_controller_with_session(nil, subject))
55
29
  subject.should eq({ :cas_user => 'tester@test.com', :casfilteruser => 'tester@test.com', :cas_extra_attributes => {:test => 'stuff', :this => 'that' }})
56
30
  end
57
31
  after { CASClient::Frameworks::Rails::Filter.fake(nil,nil) }
@@ -76,7 +50,7 @@ describe CASClient::Frameworks::Rails::Filter do
76
50
  CASClient::Client.any_instance.stub(:request_cas_response).and_return(response)
77
51
  CASClient::Client.any_instance.stub(:retrieve_proxy_granting_ticket).and_return(pgt)
78
52
 
79
- controller = controller_with_session()
53
+ controller = mock_controller_with_session()
80
54
  CASClient::Frameworks::Rails::Filter.filter(controller).should eq(true)
81
55
  end
82
56
  end
@@ -92,7 +66,7 @@ describe CASClient::Frameworks::Rails::Filter do
92
66
  CASClient::Client.any_instance.stub(:request_cas_response).and_return(response)
93
67
  CASClient::Frameworks::Rails::Filter.stub(:unauthorized!) {"bogusresponse"}
94
68
 
95
- controller = controller_with_session()
69
+ controller = mock_controller_with_session()
96
70
  CASClient::Frameworks::Rails::Filter.filter(controller).should eq(false)
97
71
  end
98
72
  end
@@ -103,7 +77,7 @@ describe CASClient::Frameworks::Rails::Filter do
103
77
 
104
78
  CASClient::Frameworks::Rails::Filter.stub(:unauthorized!) {"bogusresponse"}
105
79
 
106
- controller = controller_with_session()
80
+ controller = mock_controller_with_session()
107
81
  controller.stub(:params) {{}}
108
82
  CASClient::Frameworks::Rails::Filter.filter(controller).should eq(false)
109
83
  end
@@ -116,7 +90,7 @@ describe CASClient::Frameworks::Rails::Filter do
116
90
  CASClient::Frameworks::Rails::Filter.stub(:unauthorized!) {"bogusresponse"}
117
91
 
118
92
  CASClient::Frameworks::Rails::Filter.config[:use_gatewaying] = false
119
- controller = controller_with_session()
93
+ controller = mock_controller_with_session()
120
94
  controller.session[:cas_sent_to_gateway] = true
121
95
  controller.stub(:params) {{}}
122
96
  CASClient::Frameworks::Rails::Filter.filter(controller).should eq(false)
@@ -127,7 +101,7 @@ describe CASClient::Frameworks::Rails::Filter do
127
101
  it "should return failure from filter" do
128
102
 
129
103
  CASClient::Frameworks::Rails::Filter.config[:use_gatewaying] = true
130
- controller = controller_with_session()
104
+ controller = mock_controller_with_session()
131
105
  controller.session[:cas_sent_to_gateway] = true
132
106
  controller.stub(:params) {{}}
133
107
  CASClient::Frameworks::Rails::Filter.filter(controller).should eq(true)
@@ -151,7 +125,7 @@ describe CASClient::Frameworks::Rails::Filter do
151
125
  CASClient::Client.any_instance.stub(:request_cas_response).and_return(response)
152
126
  CASClient::Client.any_instance.stub(:retrieve_proxy_granting_ticket).and_raise CASClient::CASException
153
127
 
154
- controller = controller_with_session()
128
+ controller = mock_controller_with_session()
155
129
  expect { CASClient::Frameworks::Rails::Filter.filter(controller) }.to raise_error(CASClient::CASException)
156
130
  end
157
131
  end
@@ -161,7 +135,7 @@ describe CASClient::Frameworks::Rails::Filter do
161
135
 
162
136
  CASClient::Client.any_instance.stub(:request_cas_response).and_raise "Some exception"
163
137
 
164
- controller = controller_with_session()
138
+ controller = mock_controller_with_session()
165
139
  expect { CASClient::Frameworks::Rails::Filter.filter(controller) }.to raise_error(RuntimeError)
166
140
  end
167
141
  end
@@ -177,9 +151,26 @@ describe CASClient::Frameworks::Rails::Filter do
177
151
 
178
152
  subject[:cas_last_valid_ticket] = 'bogusticket'
179
153
  subject[:cas_last_valid_ticket_service] = 'bogusurl'
180
- controller = controller_with_session(mock_post_request(), subject)
154
+ controller = mock_controller_with_session(mock_post_request(), subject)
181
155
  CASClient::Frameworks::Rails::Filter.filter(controller).should eq(true)
182
156
  end
183
157
  end
184
158
  end
159
+
160
+ context "controller request is missing format" do
161
+ context "#unauthorized!" do
162
+ it 'should not crash' do
163
+ request = double('mock request')
164
+ request.stub(:format).and_return(nil)
165
+
166
+ controller = mock_controller_with_session(request)
167
+
168
+ CASClient::Frameworks::Rails::Filter.
169
+ should_receive(:redirect_to_cas_for_authentication).
170
+ with(controller)
171
+
172
+ CASClient::Frameworks::Rails::Filter.unauthorized!(controller)
173
+ end
174
+ end
175
+ end
185
176
  end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+ require 'casclient/tickets/storage/active_record_ticket_store'
3
+
4
+ describe CASClient::Tickets::Storage::ActiveRecordTicketStore do
5
+ it_should_behave_like "a ticket store"
6
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'support/local_hash_ticket_store'
3
+ require 'fileutils'
4
+
5
+ describe CASClient::Tickets::Storage::AbstractTicketStore do
6
+ describe "#store_service_session_lookup" do
7
+ it "should raise an exception" do
8
+ expect { subject.store_service_session_lookup("service_ticket", mock_controller_with_session) }.to raise_exception 'Implement this in a subclass!'
9
+ end
10
+ end
11
+ describe "#cleanup_service_session_lookup" do
12
+ it "should raise an exception" do
13
+ expect { subject.cleanup_service_session_lookup("service_ticket") }.to raise_exception 'Implement this in a subclass!'
14
+ end
15
+ end
16
+ describe "#save_pgt_iou" do
17
+ it "should raise an exception" do
18
+ expect { subject.save_pgt_iou("pgt_iou", "pgt") }.to raise_exception 'Implement this in a subclass!'
19
+ end
20
+ end
21
+ describe "#retrieve_pgt" do
22
+ it "should raise an exception" do
23
+ expect { subject.retrieve_pgt("pgt_iou") }.to raise_exception 'Implement this in a subclass!'
24
+ end
25
+ end
26
+ describe "#get_session_for_service_ticket" do
27
+ it "should raise an exception" do
28
+ expect { subject.get_session_for_service_ticket("service_ticket") }.to raise_exception 'Implement this in a subclass!'
29
+ end
30
+ end
31
+ end
32
+
33
+ describe CASClient::Tickets::Storage::LocalDirTicketStore do
34
+ let(:dir) {File.join(SPEC_TMP_DIR, "local_dir_ticket_store")}
35
+ before do
36
+ FileUtils.mkdir_p(File.join(dir, "sessions"))
37
+ end
38
+ after do
39
+ FileUtils.remove_dir(dir)
40
+ end
41
+ it_should_behave_like "a ticket store" do
42
+ let(:ticket_store) {described_class.new(:storage_dir => dir)}
43
+ end
44
+ end
@@ -2,6 +2,72 @@ require 'spec_helper'
2
2
  require 'casclient/responses.rb'
3
3
 
4
4
  describe CASClient::ValidationResponse do
5
+ context "when parsing extra attributes as raw" do
6
+ let(:response_text) do
7
+ <<RESPONSE_TEXT
8
+ <cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
9
+ <cas:authenticationSuccess>
10
+ <cas:attributes>
11
+ <cas:name>Jimmy Bob</cas:name>
12
+ <cas:status><![CDATA[stuff
13
+ ]]></cas:status>
14
+ <cas:yaml><![CDATA[--- true
15
+ ]]></cas:yaml>
16
+ <cas:json><![CDATA[{"id":10529}]]></cas:json>
17
+ </cas:attributes>
18
+ </cas:authenticationSuccess>
19
+ </cas:serviceResponse>
20
+ RESPONSE_TEXT
21
+ end
22
+
23
+ subject { CASClient::ValidationResponse.new response_text, :encode_extra_attributes_as => :raw }
24
+
25
+ it "sets text attributes to their string value" do
26
+ subject.extra_attributes["name"].should == "Jimmy Bob"
27
+ end
28
+
29
+ it "preserves whitespace for CDATA" do
30
+ subject.extra_attributes["status"].should == "stuff\n"
31
+ end
32
+
33
+ it "passes yaml through as is" do
34
+ subject.extra_attributes["yaml"].should == "--- true\n"
35
+ end
36
+ it "passes json through as is" do
37
+ subject.extra_attributes["json"].should == "{\"id\":10529}"
38
+ end
39
+ end
40
+
41
+ context "when parsing extra attributes as yaml" do
42
+ let(:response_text) do
43
+ <<RESPONSE_TEXT
44
+ <cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
45
+ <cas:authenticationSuccess>
46
+ <cas:attributes>
47
+ <cas:name>Jimmy Bob</cas:name>
48
+ <cas:status><![CDATA[stuff
49
+ ]]></cas:status>
50
+ <cas:truthy><![CDATA[--- true
51
+ ]]></cas:truthy>
52
+ <cas:falsy><![CDATA[#{false.to_yaml}]]></cas:falsy>
53
+ </cas:attributes>
54
+ </cas:authenticationSuccess>
55
+ </cas:serviceResponse>
56
+ RESPONSE_TEXT
57
+ end
58
+
59
+ subject { CASClient::ValidationResponse.new response_text, :encode_extra_attributes_as => :yaml }
60
+
61
+ it "sets text attributes to their string value" do
62
+ subject.extra_attributes["name"].should == "Jimmy Bob"
63
+ end
64
+
65
+ it "sets the value of boolean attributes to their boolean value" do
66
+ subject.extra_attributes["falsy"].should == false
67
+ subject.extra_attributes["truthy"].should == true
68
+ end
69
+ end
70
+
5
71
  context "when parsing extra attributes as JSON" do
6
72
  let(:response_text) do
7
73
  <<RESPONSE_TEXT
@@ -12,16 +78,20 @@ describe CASClient::ValidationResponse do
12
78
  <cas:last_name>92.5</cas:last_name>
13
79
  <cas:mobile_phone></cas:mobile_phone>
14
80
  <cas:global_roles><![CDATA[]]></cas:global_roles>
15
- <cas:foo_data> <![CDATA[[{"id":10529}]]]></cas:foo_data>
16
- <cas:food_data> <![CDATA[{"id":10529}]]></cas:food_data>
81
+ <cas:foo_data><![CDATA[[{"id":10529}]]]></cas:foo_data>
82
+ <cas:food_data><![CDATA[{"id":10529}]]></cas:food_data>
17
83
  <cas:allegedly_yaml>- 10</cas:allegedly_yaml>
84
+ <cas:truthy><![CDATA[--- true
85
+ ]]></cas:truthy>
86
+ <cas:falsy><![CDATA[--- false
87
+ ]]></cas:falsy>
18
88
  </cas:attributes>
19
89
  </cas:authenticationSuccess>
20
90
  </cas:serviceResponse>
21
91
  RESPONSE_TEXT
22
92
  end
23
93
 
24
- let(:subject) { CASClient::ValidationResponse.new response_text, :encode_extra_attributes_as => :json }
94
+ subject { CASClient::ValidationResponse.new response_text, :encode_extra_attributes_as => :json }
25
95
 
26
96
  it "sets the value of non-CDATA escaped empty attribute to nil" do
27
97
  subject.extra_attributes["mobile_phone"].should be_nil
@@ -51,4 +121,28 @@ RESPONSE_TEXT
51
121
  subject.extra_attributes["allegedly_yaml"].should == '- 10'
52
122
  end
53
123
  end
124
+
125
+ context "When parsing extra attributes from xml attributes" do
126
+ let(:response_text) do
127
+ <<RESPONSE_TEXT
128
+ <?xml version="1.0" encoding="UTF-8"?>
129
+ <cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
130
+ <cas:authenticationSuccess>
131
+ <cas:user>myuser</cas:user>
132
+ <cas:attribute name="username" value="myuser"/>
133
+ <cas:attribute name="name" value="My User"/>
134
+ <cas:attribute name="email" value="myuser@mail.example.com"/>
135
+ </cas:authenticationSuccess>
136
+ </cas:serviceResponse>
137
+ RESPONSE_TEXT
138
+ end
139
+
140
+ subject { CASClient::ValidationResponse.new response_text }
141
+
142
+ it "sets attributes for other type of format" do
143
+ expected = {"username" => "myuser", "name" => 'My User', "email" => 'myuser@mail.example.com'}
144
+ subject.user.should == 'myuser'
145
+ subject.extra_attributes.should == expected
146
+ end
147
+ end
54
148
  end