From edb2e3ff9d2639b635a466f96bd6a175b86c320a Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Tue, 25 Oct 2022 16:39:13 -0700 Subject: [PATCH] Add unit testing --- .../tracing/contrib/rack/middlewares_spec.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/datadog/tracing/contrib/rack/middlewares_spec.rb b/spec/datadog/tracing/contrib/rack/middlewares_spec.rb index caf3284ef14..ea5b4276150 100644 --- a/spec/datadog/tracing/contrib/rack/middlewares_spec.rb +++ b/spec/datadog/tracing/contrib/rack/middlewares_spec.rb @@ -44,4 +44,27 @@ end end end + + # Non-ASCII URLs cannot be tested with `rack-test` as of v2.0.2. + # It would be ideal if that was possible, as we could create integration tests + # for such cases. + # + # As an alternative, we test the parsing method directly. + describe '#parse_url' do + subject(:parse_url) { middleware.send(:parse_url, env, original_env) } + let(:env) { { 'REQUEST_URI' => uri, 'HTTP_HOST' => 'localhost:443', 'rack.url_scheme' => 'https' } } + let(:original_env) { {} } + + context 'with Unicode characters' do + let(:uri) { 'https://localhost/success/?繋がってて' } + + it { is_expected.to eq(uri) } + end + + context 'with unencoded ASCII characters' do + let(:uri) { 'https://localhost/success/|' } + + it { is_expected.to eq(uri) } + end + end end