Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 317ef6a7f99ca912b221610216d6b8436f271998 1 parent 9912bd3
authored
9 lib/authentication.rb
@@ -64,8 +64,7 @@ class Server < Sinatra::Base
64 64 elsif @gateway
65 65 if @service_url
66 66 if ticket_granting_ticket
67   - st = ServiceTicket.new(@service, ticket_granting_ticket.username)
68   - st.save!(settings.redis)
  67 + st = ServiceTicket.create!(@service, ticket_granting_ticket.username, settings.redis)
69 68 redirect_url = @service_url.clone
70 69 if @service_url.query_values.nil?
71 70 redirect_url.query_values = @service_url.query_values = { :ticket => st.ticket }
@@ -83,8 +82,7 @@ class Server < Sinatra::Base
83 82 else
84 83 if ticket_granting_ticket
85 84 if @service_url
86   - st = ServiceTicket.new(@service, ticket_granting_ticket.username)
87   - st.save!(settings.redis)
  85 + st = ServiceTicket.create!(@service, ticket_granting_ticket.username, settings.redis)
88 86 redirect_url = @service_url.clone
89 87 if @service_url.query_values.nil?
90 88 redirect_url.query_values = @service_url.query_values = { :ticket => st.ticket }
@@ -117,8 +115,7 @@ class Server < Sinatra::Base
117 115 response.set_cookie(*cookie)
118 116
119 117 if service_url(service)
120   - st = ServiceTicket.new(service, username)
121   - st.save!(settings.redis)
  118 + st = ServiceTicket.create!(service, username, settings.redis)
122 119 redirect service_url(service).to_s + "?ticket=#{st.ticket}", 303
123 120 else
124 121 erb(:logged_in)
6 lib/models/service_ticket.rb
@@ -10,6 +10,12 @@ def find!(ticket, store)
10 10 end
11 11 end
12 12
  13 + def create!(service, username, store)
  14 + st = self.new(service, username)
  15 + st.save!(store)
  16 + st
  17 + end
  18 +
13 19 def expire_time
14 20 300
15 21 end
14 test/protocol/server_test.rb
@@ -12,8 +12,7 @@ def app
12 12 end
13 13
14 14 def sso_session_for(username)
15   - @tgt = TicketGrantingTicket.new("quentin")
16   - @tgt.save!(@redis)
  15 + @tgt = TicketGrantingTicket.create!("quentin", @redis)
17 16 cookie = @tgt.to_cookie("localhost", "/")
18 17
19 18 # 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)
343 342
344 343 context "optional url parameter" do
345 344 setup do
346   - get "/serviceLogout", { :url => "http://myreturn.app" },"HTTP_COOKIE" => @cookie
  345 + get "/serviceLogout", { :url => "http://myreturn.app" }, "HTTP_COOKIE" => @cookie
347 346 end
348 347
349 348 should "reditect a user to the provided URL"
@@ -360,8 +359,7 @@ def assert_invalid_service_json_response(last_response)
360 359
361 360 context "/serviceValidate" do
362 361 setup do
363   - @st = ServiceTicket.new(@test_service, "quentin")
364   - @st.save!(@redis)
  362 + @st = ServiceTicket.create!(@test_service, "quentin", @redis)
365 363 end
366 364
367 365 must "issue proxy granting tickets when requested."
@@ -453,8 +451,7 @@ def assert_invalid_service_json_response(last_response)
453 451 context "/proxyValidate" do
454 452 context "performing the same validation tasks as /serviceValidate" do
455 453 setup do
456   - @st = ServiceTicket.new(@test_service, "quentin")
457   - @st.save!(@redis)
  454 + @st = ServiceTicket.create!(@test_service, "quentin", @redis)
458 455 end
459 456
460 457 context "parameters" do
@@ -537,8 +534,7 @@ def assert_invalid_service_json_response(last_response)
537 534
538 535 context "service ticket" do
539 536 setup do
540   - @st = ServiceTicket.new(@test_service, "quentin")
541   - @st.save!(@redis)
  537 + @st = ServiceTicket.create!(@test_service, "quentin", @redis)
542 538 end
543 539
544 540 context "properties" do

0 comments on commit 317ef6a

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