Skip to content

Commit

Permalink
fix: URL encode consumer version number in pact URL
Browse files Browse the repository at this point in the history
Fixes: #253
  • Loading branch information
bethesque committed Nov 22, 2018
1 parent ae5dd1d commit b58f4fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def version_url_from_params params, base_url = ''
end

def pact_url base_url, pact
"#{pactigration_base_url(base_url, pact)}/version/#{pact.consumer_version_number}"
"#{pactigration_base_url(base_url, pact)}/version/#{url_encode(pact.consumer_version_number)}"
end

def pact_version_url pact, base_url = ''
Expand Down
28 changes: 18 additions & 10 deletions spec/lib/pact_broker/api/pact_broker_urls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,47 @@ module Api
# \/\{[^\}\s\[\(\.]+\}

let(:base_url) { "http://example.org" }
let(:pact) { double('pact', consumer: consumer, provider: provider, consumer_version_number: "123", pact_version_sha: "5hbfu") }
let(:consumer) { double('pacticipant', name: "Foo") }
let(:provider) { double('pacticipant', name: "Bar") }
let(:consumer_name) { "Foo/Foo" }
let(:provider_name) { "Bar/Bar" }
let(:pact) { double('pact', consumer: consumer, provider: provider, consumer_version_number: "123/456", pact_version_sha: "5hbfu") }
let(:consumer) { double('pacticipant', name: consumer_name) }
let(:provider) { double('pacticipant', name: provider_name) }
let(:verification) do
instance_double(PactBroker::Domain::Verification,
consumer_name: "Foo",
provider_name: "Bar",
consumer_name: consumer_name,
provider_name: provider_name,
pact_version_sha: "1234",
number: "1")
end

describe "pact_url" do
subject { PactBrokerUrls.pact_url(base_url, pact) }

it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/version/123%2F456" }
end

describe "templated_tag_url_for_pacticipant" do
subject { PactBrokerUrls.templated_tag_url_for_pacticipant("Bar", base_url) }
subject { PactBrokerUrls.templated_tag_url_for_pacticipant(provider_name, base_url) }

it { is_expected.to eq "http://example.org/pacticipants/Bar/versions/{version}/tags/{tag}" }
it { is_expected.to eq "http://example.org/pacticipants/Bar%2FBar/versions/{version}/tags/{tag}" }
end

describe "pact_triggered_webhooks_url" do
subject { PactBrokerUrls.pact_triggered_webhooks_url(pact, base_url) }

it { is_expected.to eq "http://example.org/pacts/provider/Bar/consumer/Foo/version/123/triggered-webhooks" }
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/version/123%2F456/triggered-webhooks" }
end

describe "verification_triggered_webhooks_url" do
subject { PactBrokerUrls.verification_triggered_webhooks_url(verification, base_url) }

it { is_expected.to eq "http://example.org/pacts/provider/Bar/consumer/Foo/pact-version/1234/verification-results/1/triggered-webhooks" }
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/pact-version/1234/verification-results/1/triggered-webhooks" }
end

describe "templated_diff_url" do
subject { PactBrokerUrls.templated_diff_url(pact, base_url) }

it { is_expected.to eq "http://example.org/pacts/provider/Bar/consumer/Foo/pact-version/5hbfu/diff/pact-version/{pactVersion}" }
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/pact-version/5hbfu/diff/pact-version/{pactVersion}" }
end
end
end
Expand Down

0 comments on commit b58f4fb

Please sign in to comment.