Skip to content

Commit

Permalink
Handle multiple values for cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanbeevers committed Feb 7, 2012
1 parent a129d49 commit 9f028bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/secure_escrow/middleware.rb
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/middleware_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 9f028bb

Please sign in to comment.