Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3dc40fb
ignore DS_Store files
tpickett66 Nov 1, 2012
786f46a
add dummy rails app
tpickett66 Nov 1, 2012
b05fed7
make older versions of rails happy
tpickett66 Nov 1, 2012
a0e24cb
configure new 'app' for some jruby love
tpickett66 Nov 2, 2012
4de0b7a
add migrations to our dummy app
tpickett66 Nov 2, 2012
97deb98
run migrations before we attempt to test
tpickett66 Nov 2, 2012
530a5ac
ignore our new app's test logs and DB
tpickett66 Nov 2, 2012
e7cbb38
remove active_record_helpers
tpickett66 Nov 2, 2012
2d1d2bc
stop following our test logs in git...
tpickett66 Nov 2, 2012
40a2501
add a boot.rb for initing rails 2.3
tpickett66 Nov 2, 2012
c20f3a4
begin hacking our app's boot process
tpickett66 Nov 2, 2012
9029648
hack our app's test environment to work both ways
tpickett66 Nov 2, 2012
96e61dd
do our initialization both ways...
tpickett66 Nov 2, 2012
8c205e2
load up our app's test helpers correctly
tpickett66 Nov 2, 2012
99a4743
ewps, need to know if config can do that not Object
tpickett66 Nov 2, 2012
5d4e1ef
Filter.fake specs passing with 'real' controller
tpickett66 Nov 2, 2012
28eb7e7
implement controller instantiation helper
tpickett66 Nov 2, 2012
6c9485e
plug in new controller builder
tpickett66 Nov 2, 2012
b5e01a4
remove redundant require
tpickett66 Nov 2, 2012
42d1852
add a real controller and route
tpickett66 Nov 5, 2012
db852a3
remove focus from those specs
tpickett66 Nov 5, 2012
7cb3b8d
comment out controller mocking
tpickett66 Nov 5, 2012
5b189b9
plug in our real controller, not just the abstract
tpickett66 Nov 5, 2012
ecc8b3a
build and use rails' built in test requests
tpickett66 Nov 5, 2012
f76e578
DRY up rails version checking for setup
tpickett66 Nov 5, 2012
2656e8c
manually delegate rails 2.3 params to the request
tpickett66 Nov 5, 2012
5658245
set up our query parameters/string
tpickett66 Nov 5, 2012
5ef4bc0
setup rails 2's @url instance variable
tpickett66 Nov 5, 2012
93f9c24
valid ticket spec passing for all target versions of rails
tpickett66 Nov 5, 2012
0a77395
dun, dun, dun, another one passes now.
tpickett66 Nov 5, 2012
294d7db
allow customization of the Rack environment
tpickett66 Nov 5, 2012
9d15056
deal with the moronic way Rails 2.3 checks the query string
tpickett66 Nov 5, 2012
fce15d9
another group of filter specs passing
tpickett66 Nov 5, 2012
c4ef598
make request_uri match the default supplied by rails
tpickett66 Nov 5, 2012
e170822
add helper to build request urls w/o ticket
tpickett66 Nov 5, 2012
bdbbcdd
another round of passing specs
tpickett66 Nov 5, 2012
3d2ea2d
last filter spec passing all target versions of rails
tpickett66 Nov 5, 2012
5e97390
remove spec that doesn't assert anything
tpickett66 Nov 6, 2012
890ec86
build a real controller for these specs
tpickett66 Nov 6, 2012
ffed5e0
all active_record_ticket_store examples passing
tpickett66 Nov 6, 2012
af5b7cd
abstract session store specs passing
tpickett66 Nov 6, 2012
3ac70e1
FS Session store specs passing
tpickett66 Nov 6, 2012
24f8176
all specs passing without mocked controller, removing controller mock
tpickett66 Nov 6, 2012
93cc340
comment out mock_post_request to see what breaks
tpickett66 Nov 6, 2012
3eaffab
nothing broke, removing
tpickett66 Nov 6, 2012
7f886f3
unhide find_by_sesison_id
tpickett66 Nov 7, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ pkg
.rvmrc

.project

*.DS_Store
Gemfile.lock
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2012 YOURNAME

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions lib/casclient/tickets/storage/active_record_ticket_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def retrieve_pgt(pgt_iou)
class ServiceTicketAwareSession < ActiveRecord::SessionStore::Session
before_save :save_service_ticket

def self.find_by_session_id(session_id)
super
end

def save_service_ticket
if data[:service_ticket]
self.service_ticket = data[:service_ticket]
Expand Down
2 changes: 2 additions & 0 deletions spec/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
test.*.db
dummy/log/*
dummy/db/*.sqlite3
76 changes: 36 additions & 40 deletions spec/casclient/frameworks/rails/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
require 'spec_helper'
require 'action_controller'
require 'casclient/frameworks/rails/filter'

describe CASClient::Frameworks::Rails::Filter do

before(:each) do
@controller = build_controller_instance
CASClient::Frameworks::Rails::Filter.configure(
:cas_base_url => 'http://test.local/',
:cas_base_url => 'http://test.local',
:logger => double("Logger")
)
end

describe "#fake" do
subject { Hash.new }
subject { @controller.session }

context "faking user without attributes" do
before { CASClient::Frameworks::Rails::Filter.fake('tester@test.com') }

it 'should set the session user' do
CASClient::Frameworks::Rails::Filter.filter(mock_controller_with_session(nil, subject))
CASClient::Frameworks::Rails::Filter.filter(@controller)
subject.should eq({:cas_user => 'tester@test.com', :casfilteruser => 'tester@test.com'})
end

after { CASClient::Frameworks::Rails::Filter.fake(nil,nil) }
end

context "faking user with attributes" do
before { CASClient::Frameworks::Rails::Filter.fake('tester@test.com', {:test => 'stuff', :this => 'that'}) }

it 'should set the session user and attributes' do
CASClient::Frameworks::Rails::Filter.filter(mock_controller_with_session(nil, subject))
CASClient::Frameworks::Rails::Filter.filter(@controller)
subject.should eq({ :cas_user => 'tester@test.com', :casfilteruser => 'tester@test.com', :cas_extra_attributes => {:test => 'stuff', :this => 'that' }})
end

after { CASClient::Frameworks::Rails::Filter.fake(nil,nil) }
end
end

context "new valid service ticket" do
it "should return successfully from filter" do
it "should return successfully from filter" do

pgt = CASClient::ProxyGrantingTicket.new(
"PGT-1308586001r9573FAD5A8C62E134A4AA93273F226BD3F0C3A983DCCCD176",
Expand All @@ -50,13 +55,12 @@
CASClient::Client.any_instance.stub(:request_cas_response).and_return(response)
CASClient::Client.any_instance.stub(:retrieve_proxy_granting_ticket).and_return(pgt)

controller = mock_controller_with_session()
CASClient::Frameworks::Rails::Filter.filter(controller).should eq(true)
CASClient::Frameworks::Rails::Filter.filter(@controller).should eq(true)
end
end

context "new invalid service ticket" do
it "should return failure from filter" do
it "should return failure from filter" do

raw_text = "<cas:serviceResponse xmlns:cas=\"http://www.yale.edu/tp/cas\">
<cas:authenticationFailure>Some Error Text</cas:authenticationFailure>
Expand All @@ -66,21 +70,22 @@
CASClient::Client.any_instance.stub(:request_cas_response).and_return(response)
CASClient::Frameworks::Rails::Filter.stub(:unauthorized!) {"bogusresponse"}

controller = mock_controller_with_session()
CASClient::Frameworks::Rails::Filter.filter(controller).should eq(false)
end
CASClient::Frameworks::Rails::Filter.filter(@controller).should eq(false)
end
end

context "does not have new input service ticket" do
before do
@controller = build_controller_instance({:params=>''})
end

context "with last service ticket" do
it "should return failure from filter" do
it "should return failure from filter" do

CASClient::Frameworks::Rails::Filter.stub(:unauthorized!) {"bogusresponse"}

controller = mock_controller_with_session()
controller.stub(:params) {{}}
CASClient::Frameworks::Rails::Filter.filter(controller).should eq(false)
end
CASClient::Frameworks::Rails::Filter.filter(@controller).should eq(false)
end
end

context "sent through gateway" do
Expand All @@ -90,21 +95,17 @@
CASClient::Frameworks::Rails::Filter.stub(:unauthorized!) {"bogusresponse"}

CASClient::Frameworks::Rails::Filter.config[:use_gatewaying] = false
controller = mock_controller_with_session()
controller.session[:cas_sent_to_gateway] = true
controller.stub(:params) {{}}
CASClient::Frameworks::Rails::Filter.filter(controller).should eq(false)
@controller.session[:cas_sent_to_gateway] = true
CASClient::Frameworks::Rails::Filter.filter(@controller).should eq(false)
end
end

context "gatewaying on" do
it "should return failure from filter" do

CASClient::Frameworks::Rails::Filter.config[:use_gatewaying] = true
controller = mock_controller_with_session()
controller.session[:cas_sent_to_gateway] = true
controller.stub(:params) {{}}
CASClient::Frameworks::Rails::Filter.filter(controller).should eq(true)
@controller.session[:cas_sent_to_gateway] = true
CASClient::Frameworks::Rails::Filter.filter(@controller).should eq(true)
end
end
end
Expand All @@ -125,8 +126,7 @@
CASClient::Client.any_instance.stub(:request_cas_response).and_return(response)
CASClient::Client.any_instance.stub(:retrieve_proxy_granting_ticket).and_raise CASClient::CASException

controller = mock_controller_with_session()
expect { CASClient::Frameworks::Rails::Filter.filter(controller) }.to raise_error(CASClient::CASException)
expect { CASClient::Frameworks::Rails::Filter.filter(@controller) }.to raise_error(CASClient::CASException)
end
end

Expand All @@ -135,41 +135,37 @@

CASClient::Client.any_instance.stub(:request_cas_response).and_raise "Some exception"

controller = mock_controller_with_session()
expect { CASClient::Frameworks::Rails::Filter.filter(controller) }.to raise_error(RuntimeError)
expect { CASClient::Frameworks::Rails::Filter.filter(@controller) }.to raise_error(RuntimeError)
end
end

context "matches existing service ticket" do
subject { Hash.new }
subject { @controller.session }
it "should return successfully from filter" do

mock_client = CASClient::Client.new()
mock_client.should_receive(:request_cas_response).at_most(0).times
mock_client.should_receive(:retrieve_proxy_granting_ticket).at_most(0).times
CASClient::Frameworks::Rails::Filter.send(:class_variable_set, :@@client, mock_client)

subject[:cas_last_valid_ticket] = 'bogusticket'
subject[:cas_last_valid_ticket_service] = 'bogusurl'
controller = mock_controller_with_session(mock_post_request(), subject)
CASClient::Frameworks::Rails::Filter.filter(controller).should eq(true)
subject[:cas_last_valid_ticket] = @controller.params[:ticket]
subject[:cas_last_valid_ticket_service] = ticketless_url(@controller)

CASClient::Frameworks::Rails::Filter.filter(@controller).should eq(true)
end
end
end

context "controller request is missing format" do
context "#unauthorized!" do
it 'should not crash' do
request = double('mock request')
request.stub(:format).and_return(nil)

controller = mock_controller_with_session(request)
@controller.request.stub(:format).and_return(nil)

CASClient::Frameworks::Rails::Filter.
should_receive(:redirect_to_cas_for_authentication).
with(controller)
with(@controller)

CASClient::Frameworks::Rails::Filter.unauthorized!(controller)
CASClient::Frameworks::Rails::Filter.unauthorized!(@controller)
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion spec/casclient/tickets/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,35 @@

describe CASClient::Tickets::Storage::AbstractTicketStore do
describe "#store_service_session_lookup" do
before do
@controller = build_controller_instance
end

it "should raise an exception" do
expect { subject.store_service_session_lookup("service_ticket", mock_controller_with_session) }.to raise_exception 'Implement this in a subclass!'
expect {
subject.store_service_session_lookup("service_ticket", @controller)
}.to raise_exception 'Implement this in a subclass!'
end
end

describe "#cleanup_service_session_lookup" do
it "should raise an exception" do
expect { subject.cleanup_service_session_lookup("service_ticket") }.to raise_exception 'Implement this in a subclass!'
end
end

describe "#save_pgt_iou" do
it "should raise an exception" do
expect { subject.save_pgt_iou("pgt_iou", "pgt") }.to raise_exception 'Implement this in a subclass!'
end
end

describe "#retrieve_pgt" do
it "should raise an exception" do
expect { subject.retrieve_pgt("pgt_iou") }.to raise_exception 'Implement this in a subclass!'
end
end

describe "#get_session_for_service_ticket" do
it "should raise an exception" do
expect { subject.get_session_for_service_ticket("service_ticket") }.to raise_exception 'Implement this in a subclass!'
Expand Down
Loading