Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use #create! instead of #new + #save.

  • Loading branch information...
commit 317ef6a7f99ca912b221610216d6b8436f271998 1 parent 9912bd3
beawesomeinstead authored
View
9 lib/authentication.rb
@@ -64,8 +64,7 @@ class Server < Sinatra::Base
elsif @gateway
if @service_url
if ticket_granting_ticket
- st = ServiceTicket.new(@service, ticket_granting_ticket.username)
- st.save!(settings.redis)
+ st = ServiceTicket.create!(@service, ticket_granting_ticket.username, settings.redis)
redirect_url = @service_url.clone
if @service_url.query_values.nil?
redirect_url.query_values = @service_url.query_values = { :ticket => st.ticket }
@@ -83,8 +82,7 @@ class Server < Sinatra::Base
else
if ticket_granting_ticket
if @service_url
- st = ServiceTicket.new(@service, ticket_granting_ticket.username)
- st.save!(settings.redis)
+ st = ServiceTicket.create!(@service, ticket_granting_ticket.username, settings.redis)
redirect_url = @service_url.clone
if @service_url.query_values.nil?
redirect_url.query_values = @service_url.query_values = { :ticket => st.ticket }
@@ -117,8 +115,7 @@ class Server < Sinatra::Base
response.set_cookie(*cookie)
if service_url(service)
- st = ServiceTicket.new(service, username)
- st.save!(settings.redis)
+ st = ServiceTicket.create!(service, username, settings.redis)
redirect service_url(service).to_s + "?ticket=#{st.ticket}", 303
else
erb(:logged_in)
View
6 lib/models/service_ticket.rb
@@ -10,6 +10,12 @@ def find!(ticket, store)
end
end
+ def create!(service, username, store)
+ st = self.new(service, username)
+ st.save!(store)
+ st
+ end
+
def expire_time
300
end
View
14 test/protocol/server_test.rb
@@ -12,8 +12,7 @@ def app
end
def sso_session_for(username)
- @tgt = TicketGrantingTicket.new("quentin")
- @tgt.save!(@redis)
+ @tgt = TicketGrantingTicket.create!("quentin", @redis)
cookie = @tgt.to_cookie("localhost", "/")
# Rack's set_cookie appears to be worse than useless, unless I'm mistaken
@@ -343,7 +342,7 @@ def assert_invalid_service_json_response(last_response)
context "optional url parameter" do
setup do
- get "/serviceLogout", { :url => "http://myreturn.app" },"HTTP_COOKIE" => @cookie
+ get "/serviceLogout", { :url => "http://myreturn.app" }, "HTTP_COOKIE" => @cookie
end
should "reditect a user to the provided URL"
@@ -360,8 +359,7 @@ def assert_invalid_service_json_response(last_response)
context "/serviceValidate" do
setup do
- @st = ServiceTicket.new(@test_service, "quentin")
- @st.save!(@redis)
+ @st = ServiceTicket.create!(@test_service, "quentin", @redis)
end
must "issue proxy granting tickets when requested."
@@ -453,8 +451,7 @@ def assert_invalid_service_json_response(last_response)
context "/proxyValidate" do
context "performing the same validation tasks as /serviceValidate" do
setup do
- @st = ServiceTicket.new(@test_service, "quentin")
- @st.save!(@redis)
+ @st = ServiceTicket.create!(@test_service, "quentin", @redis)
end
context "parameters" do
@@ -537,8 +534,7 @@ def assert_invalid_service_json_response(last_response)
context "service ticket" do
setup do
- @st = ServiceTicket.new(@test_service, "quentin")
- @st.save!(@redis)
+ @st = ServiceTicket.create!(@test_service, "quentin", @redis)
end
context "properties" do

0 comments on commit 317ef6a

Please sign in to comment.
Something went wrong with that request. Please try again.