Permalink
Browse files

Handle multiple values for cookie

  • Loading branch information...
duncanbeevers committed Feb 7, 2012
1 parent a129d49 commit 9f028bb826d54e8f67350b03f1665fc5061f0fb0
Showing with 14 additions and 2 deletions.
  1. +4 −2 lib/secure_escrow/middleware.rb
  2. +10 −0 spec/middleware_spec.rb
@@ -214,9 +214,11 @@ def routes
# TODO: Examine the performance implications of parsing the
# Cookie / Query payload this early in the stack
def escrow_id_and_nonce
- data = (homogenous_host_names? ?
+ data = Array((homogenous_host_names? ?
Rack::Utils.parse_query(env[HTTP_COOKIE], COOKIE_SEPARATOR) :
- Rack::Utils.parse_query(env[QUERY_STRING]))[DATA_KEY]
+ Rack::Utils.parse_query(env[QUERY_STRING]))[DATA_KEY]).find do |e|
+ e.match ESCROW_MATCH
+ end
return unless data
match = data.match ESCROW_MATCH
View
@@ -439,6 +439,16 @@
presenter.escrow_id.should eq 'id'
presenter.escrow_nonce.should eq 'nonce'
end
+
+ it 'should select first suitable escrow key from cookie' do
+ presenter.env[HTTP_COOKIE] = "%s=%s.%s; %s=%s.%s" % [
+ SecureEscrow::MiddlewareConstants::DATA_KEY, "A", "B",
+ SecureEscrow::MiddlewareConstants::DATA_KEY, "C", "D"
+ ]
+
+ presenter.escrow_id.should eq "A"
+ presenter.escrow_nonce.should eq "B"
+ end
end
end

0 comments on commit 9f028bb

Please sign in to comment.