From abfb0517d8d01ee3d6e0c12f2e07d79f7854bd96 Mon Sep 17 00:00:00 2001 From: Alexander Biriukov Date: Mon, 21 Feb 2011 15:00:41 +0300 Subject: [PATCH 1/2] Fix for CAS validation when response is compressed --- .../strategies/cas/service_ticket_validator.rb | 2 +- .../spec/omniauth/strategies/cas_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb b/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb index 45888d2ea..b4bcc5aea 100644 --- a/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb +++ b/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb @@ -68,7 +68,7 @@ def get_service_response_body http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = @uri.port == 443 || @uri.instance_of?(URI::HTTPS) http.start do |c| - response = c.get "#{@uri.path}?#{@uri.query}", VALIDATION_REQUEST_HEADERS + response = c.get "#{@uri.path}?#{@uri.query}", VALIDATION_REQUEST_HEADERS.dup result = response.body end result diff --git a/oa-enterprise/spec/omniauth/strategies/cas_spec.rb b/oa-enterprise/spec/omniauth/strategies/cas_spec.rb index 9c3383329..1f381bf5a 100644 --- a/oa-enterprise/spec/omniauth/strategies/cas_spec.rb +++ b/oa-enterprise/spec/omniauth/strategies/cas_spec.rb @@ -72,4 +72,21 @@ def strategy last_response.body.should == 'true' end end + + describe 'GET /auth/cas/callback with a valid ticket and gzipped response from the server' do + before do + zipped = StringIO.new + Zlib::GzipWriter.wrap zipped do |io| + io.write File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cas_success.xml')) + end + stub_request(:get, /^https:\/\/cas.example.org(:443)?\/serviceValidate\?([^&]+&)?ticket=593af/). + with { |request| @request_uri = request.uri.to_s }. + to_return(:body => zipped.string, :headers => { 'content-encoding' => 'gzip' }) + get '/auth/cas/callback?ticket=593af' + end + + it 'should call through to the master app when response is gzipped' do + last_response.body.should == 'true' + end + end end From 648e5d28bd3ae1c38037289a0a34fd0f0105ff34 Mon Sep 17 00:00:00 2001 From: Alexander Biriukov Date: Mon, 21 Feb 2011 17:51:55 +0300 Subject: [PATCH 2/2] Disabled gzip testing for ruby 1.8, since it's not implemented in Net::HTTP --- .../spec/omniauth/strategies/cas_spec.rb | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/oa-enterprise/spec/omniauth/strategies/cas_spec.rb b/oa-enterprise/spec/omniauth/strategies/cas_spec.rb index 1f381bf5a..b5f794891 100644 --- a/oa-enterprise/spec/omniauth/strategies/cas_spec.rb +++ b/oa-enterprise/spec/omniauth/strategies/cas_spec.rb @@ -73,20 +73,22 @@ def strategy end end - describe 'GET /auth/cas/callback with a valid ticket and gzipped response from the server' do - before do - zipped = StringIO.new - Zlib::GzipWriter.wrap zipped do |io| - io.write File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cas_success.xml')) + unless RUBY_VERSION =~ /^1\.8\.\d$/ + describe 'GET /auth/cas/callback with a valid ticket and gzipped response from the server on ruby >1.8' do + before do + zipped = StringIO.new + Zlib::GzipWriter.wrap zipped do |io| + io.write File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cas_success.xml')) + end + stub_request(:get, /^https:\/\/cas.example.org(:443)?\/serviceValidate\?([^&]+&)?ticket=593af/). + with { |request| @request_uri = request.uri.to_s }. + to_return(:body => zipped.string, :headers => { 'content-encoding' => 'gzip' }) + get '/auth/cas/callback?ticket=593af' end - stub_request(:get, /^https:\/\/cas.example.org(:443)?\/serviceValidate\?([^&]+&)?ticket=593af/). - with { |request| @request_uri = request.uri.to_s }. - to_return(:body => zipped.string, :headers => { 'content-encoding' => 'gzip' }) - get '/auth/cas/callback?ticket=593af' - end - it 'should call through to the master app when response is gzipped' do - last_response.body.should == 'true' + it 'should call through to the master app when response is gzipped' do + last_response.body.should == 'true' + end end end end