Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow same URLs when HTTP auth not the same #46

Merged
merged 2 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/webvalve/fake_service_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ def explicitly_disabled?
value_from_env.present? && WebValve::DISABLED_VALUES.include?(value_from_env.to_s)
end

def full_url
@full_url ||= custom_service_url || default_service_url
end

def service_url
@service_url ||= begin
url = custom_service_url || default_service_url
raise missing_url_message if url.blank?
strip_basic_auth url
raise missing_url_message if full_url.blank?
strip_basic_auth full_url
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/webvalve/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def url_to_regexp(url)
end

def ensure_non_duplicate_stub(config)
raise "Invalid config for #{config.service_class_name}. Already stubbed url #{config.service_url}" if stubbed_urls.include?(config.service_url)
stubbed_urls << config.service_url
raise "Invalid config for #{config.service_class_name}. Already stubbed url #{config.full_url}" if stubbed_urls.include?(config.full_url)
stubbed_urls << config.full_url
end

def load_configs!
Expand Down
15 changes: 15 additions & 0 deletions spec/webvalve/manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@
expect { subject.setup }.to raise_error('Invalid config for FakeOtherThing. Already stubbed url http://something.dev')
end
end

it 'does not raise with different HTTP auth patterns' do
disabled_service = class_double(WebValve::FakeService, name: 'FakeSomething')
other_disabled_service = class_double(WebValve::FakeService, name: 'FakeOtherThing')
web_mock_stubble = double(to_rack: true)
allow(WebMock).to receive(:stub_request).and_return(web_mock_stubble)

with_env 'SOMETHING_API_URL' => 'http://user1@something.dev', 'OTHER_THING_API_URL' => 'http://user2@something.dev' do
subject.register disabled_service.name
subject.register other_disabled_service.name

expect { subject.setup }.to_not raise_error
expect(WebMock).to have_received(:stub_request).with(:any, %r{\Ahttp://something\.dev}).twice
end
end
end

context 'when WebValve is on and allowing traffic' do
Expand Down