diff --git a/app/models/casino/service_ticket.rb b/app/models/casino/service_ticket.rb index a4b74099..607bddc5 100644 --- a/app/models/casino/service_ticket.rb +++ b/app/models/casino/service_ticket.rb @@ -19,6 +19,13 @@ def self.cleanup_consumed_hard self.delete_all(['created_at < ? AND consumed = ?', (CASino.config.service_ticket[:lifetime_consumed].seconds * 2).ago, true]) end + + def service=(value) + value = Addressable::URI.encode(value) + super(value) + end + + def service_with_ticket_url service_uri = Addressable::URI.parse(self.service) service_uri.query_values = (service_uri.query_values(Array) || []) << ['ticket', self.ticket] diff --git a/spec/model/service_ticket_spec.rb b/spec/model/service_ticket_spec.rb index f6480be1..b5d1fe0a 100644 --- a/spec/model/service_ticket_spec.rb +++ b/spec/model/service_ticket_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + require 'spec_helper' describe CASino::ServiceTicket do @@ -116,9 +118,21 @@ end describe '#service_with_ticket_url' do - it 'does not escape the url from the database' do - unconsumed_ticket.service = 'https://host.example.org/test.php?t=other&other=testing' - unconsumed_ticket.service_with_ticket_url.should eq('https://host.example.org/test.php?t=other&other=testing&ticket=ST-12345') + it 'appends the service ticket id to the querystring' do + unconsumed_ticket.service = 'https://host.example.org/test.php?iam=testing' + unconsumed_ticket.service_with_ticket_url.should eq('https://host.example.org/test.php?iam=testing&ticket=ST-12345') + end + end + + describe '#service=' do + it 'encodes the url before writing to the database' do + unconsumed_ticket.service = 'https://example.org/this is a test/jö.png' + unconsumed_ticket.service.should eq('https://example.org/this%20is%20a%20test/j%C3%B6.png') + end + + it 'does not encode the querystring symbols (&?=) before writing to the database' do + unconsumed_ticket.service = 'https://example.org/test.php?t=other&other=testing' + unconsumed_ticket.service.should eq('https://example.org/test.php?t=other&other=testing') end end end diff --git a/spec/processor/processor_concern/service_tickets_spec.rb b/spec/processor/processor_concern/service_tickets_spec.rb index b6ad27da..301d6d94 100644 --- a/spec/processor/processor_concern/service_tickets_spec.rb +++ b/spec/processor/processor_concern/service_tickets_spec.rb @@ -46,4 +46,4 @@ end end end -end \ No newline at end of file +end