diff --git a/lib/secure_escrow/middleware.rb b/lib/secure_escrow/middleware.rb index 5d5a3c4..1b0f1c7 100644 --- a/lib/secure_escrow/middleware.rb +++ b/lib/secure_escrow/middleware.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 diff --git a/spec/middleware_spec.rb b/spec/middleware_spec.rb index 63bb475..c2a9f41 100644 --- a/spec/middleware_spec.rb +++ b/spec/middleware_spec.rb @@ -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