pact_broker 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -2
- data/CHANGELOG.md +9 -0
- data/CONTRIBUTING.md +15 -0
- data/config/database.travis.yml +13 -0
- data/config/database.yml +25 -13
- data/db/migrations/32_create_latest_verifications.rb +6 -5
- data/db/migrations/33_create_config_table.rb +1 -1
- data/db/migrations/34_create_index_on_consumer_version_order.rb +10 -0
- data/db/migrations/35_create_index_on_names.rb +11 -0
- data/db/migrations/36_create_webhook_execution.rb +16 -0
- data/example/pact_broker_database.sqlite3 +0 -0
- data/lib/db.rb +6 -1
- data/lib/pact_broker/api/contracts/put_pact_params_contract.rb +1 -0
- data/lib/pact_broker/app.rb +1 -0
- data/lib/pact_broker/domain/order_versions.rb +37 -15
- data/lib/pact_broker/domain/relationship.rb +11 -5
- data/lib/pact_broker/domain/tag.rb +4 -0
- data/lib/pact_broker/domain/version.rb +6 -1
- data/lib/pact_broker/domain/webhook_execution_result.rb +7 -2
- data/lib/pact_broker/domain/webhook_request.rb +24 -2
- data/lib/pact_broker/pacticipants/service.rb +4 -2
- data/lib/pact_broker/pacts/all_pact_publications.rb +1 -1
- data/lib/pact_broker/pacts/repository.rb +3 -3
- data/lib/pact_broker/repositories/helpers.rb +16 -0
- data/lib/pact_broker/ui/view_models/relationship.rb +9 -0
- data/lib/pact_broker/ui/views/relationships/show.haml +9 -0
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/webhooks/execution.rb +17 -0
- data/lib/pact_broker/webhooks/repository.rb +20 -2
- data/lib/pact_broker/webhooks/service.rb +4 -1
- data/public/stylesheets/relationships.css +1 -0
- data/script/publish-2.sh +1 -0
- data/script/publish-new.sh +1 -0
- data/script/publish-not-a-pact.sh +1 -0
- data/script/publish.sh +1 -0
- data/script/record_verification.sh +1 -0
- data/script/recreate-pg-db.sh +2 -0
- data/spec/lib/pact_broker/api/contracts/put_pact_params_contract_spec.rb +20 -0
- data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +2 -1
- data/spec/lib/pact_broker/domain/order_versions_spec.rb +37 -15
- data/spec/lib/pact_broker/domain/version_spec.rb +14 -0
- data/spec/lib/pact_broker/domain/webhook_request_spec.rb +49 -6
- data/spec/lib/pact_broker/domain/webhook_spec.rb +1 -0
- data/spec/lib/pact_broker/pacticipants/service_spec.rb +28 -4
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +1 -1
- data/spec/lib/pact_broker/pacts/repository_spec.rb +10 -10
- data/spec/lib/pact_broker/tags/repository_spec.rb +2 -2
- data/spec/lib/pact_broker/ui/controllers/relationships_spec.rb +7 -7
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +52 -4
- data/spec/lib/pact_broker/webhooks/service_spec.rb +6 -1
- data/spec/migrations/23_pact_versions_spec.rb +1 -1
- data/spec/support/database_cleaner.rb +5 -1
- data/spec/support/provider_state_builder.rb +8 -0
- data/spec/support/rspec_matchers.rb +9 -0
- data/tasks/database.rb +3 -2
- data/tasks/db.rake +41 -3
- metadata +10 -3
- data/lib/pact_broker/api/contracts/consumer_version_number_validation.rb +0 -27
@@ -58,7 +58,8 @@ module PactBroker
|
|
58
58
|
pact_repository.find_latest_pacts
|
59
59
|
.collect do | pact|
|
60
60
|
latest_verification = verification_service.find_latest_verification_for(pact.consumer, pact.provider)
|
61
|
-
|
61
|
+
webhooks = webhook_service.find_by_consumer_and_provider pact.consumer, pact.provider
|
62
|
+
PactBroker::Domain::Relationship.create pact.consumer, pact.provider, pact, latest_verification, webhooks
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
@@ -75,9 +76,10 @@ module PactBroker
|
|
75
76
|
def self.delete name
|
76
77
|
pacticipant = find_pacticipant_by_name name
|
77
78
|
connection = PactBroker::Domain::Pacticipant.new.db
|
78
|
-
version_ids = PactBroker::Domain::Version.where(pacticipant_id: pacticipant.id).
|
79
|
+
version_ids = PactBroker::Domain::Version.where(pacticipant_id: pacticipant.id).select_for_subquery(:id) #stupid mysql doesn't allow subqueries
|
79
80
|
select_pacticipant = "select id from pacticipants where name = '#{name}'"
|
80
81
|
tag_repository.delete_by_version_id version_ids
|
82
|
+
webhook_repository.delete_executions_by_pacticipant pacticipant
|
81
83
|
pact_repository.delete_by_version_id version_ids
|
82
84
|
connection.run("delete from pact_publications where provider_id = #{pacticipant.id}")
|
83
85
|
connection.run("delete from verifications where pact_version_id IN (select id from pact_versions where provider_id = #{pacticipant.id})")
|
@@ -44,7 +44,7 @@ module PactBroker
|
|
44
44
|
.consumer(params.consumer_name)
|
45
45
|
.provider(params.provider_name)
|
46
46
|
.consumer_version_number(params.consumer_version_number)
|
47
|
-
.
|
47
|
+
.select_for_subquery(:id)
|
48
48
|
PactPublication.where(id: id).delete
|
49
49
|
end
|
50
50
|
|
@@ -64,9 +64,9 @@ module PactBroker
|
|
64
64
|
|
65
65
|
def find_latest_pact_versions_for_provider provider_name, tag = nil
|
66
66
|
if tag
|
67
|
-
LatestTaggedPactPublications.provider(provider_name).
|
67
|
+
LatestTaggedPactPublications.provider(provider_name).order_ignore_case(:consumer_name).where(tag_name: tag).collect(&:to_domain)
|
68
68
|
else
|
69
|
-
LatestPactPublications.provider(provider_name).
|
69
|
+
LatestPactPublications.provider(provider_name).order_ignore_case(:consumer_name).collect(&:to_domain)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -11,6 +11,22 @@ module PactBroker
|
|
11
11
|
def case_sensitivity_options
|
12
12
|
{case_insensitive: !PactBroker.configuration.use_case_sensitive_resource_names}
|
13
13
|
end
|
14
|
+
|
15
|
+
def order_ignore_case column_name = :name
|
16
|
+
order(Sequel.function(:lower, column_name))
|
17
|
+
end
|
18
|
+
|
19
|
+
def mysql?
|
20
|
+
Sequel::Model.db.adapter_scheme.to_s =~ /mysql/
|
21
|
+
end
|
22
|
+
|
23
|
+
def select_for_subquery column
|
24
|
+
if mysql? #stoopid mysql doesn't allow subqueries
|
25
|
+
select(column).collect{ | it | it[column] }
|
26
|
+
else
|
27
|
+
select(column)
|
28
|
+
end
|
29
|
+
end
|
14
30
|
end
|
15
31
|
end
|
16
32
|
end
|
@@ -33,6 +33,15 @@ module PactBroker
|
|
33
33
|
"#{pactigration_base_url('', @relationship)}/latest"
|
34
34
|
end
|
35
35
|
|
36
|
+
def any_webhooks?
|
37
|
+
@relationship.any_webhooks?
|
38
|
+
end
|
39
|
+
|
40
|
+
def webhooks_url
|
41
|
+
url = PactBroker::Api::PactBrokerUrls.webhooks_for_pact_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider, ''
|
42
|
+
"/hal-browser/browser.html##{url}"
|
43
|
+
end
|
44
|
+
|
36
45
|
def last_verified_date
|
37
46
|
if @relationship.ever_verified?
|
38
47
|
date = @relationship.latest_verification.execution_date
|
@@ -30,6 +30,8 @@
|
|
30
30
|
%th
|
31
31
|
%th
|
32
32
|
Latest pact published
|
33
|
+
%th
|
34
|
+
Webhooks
|
33
35
|
%th
|
34
36
|
Last verified
|
35
37
|
%tbody
|
@@ -49,6 +51,13 @@
|
|
49
51
|
%td
|
50
52
|
%td
|
51
53
|
= relationship.publication_date_of_latest_pact
|
54
|
+
%td
|
55
|
+
- if relationship.any_webhooks?
|
56
|
+
%a{:href => relationship.webhooks_url}
|
57
|
+
Edit
|
58
|
+
- else
|
59
|
+
%a{:href => relationship.webhooks_url}
|
60
|
+
Create
|
52
61
|
%td{class: relationship.verification_status, title: relationship.verification_tooltip, "data-toggle": "tooltip", "data-placement": "left"}
|
53
62
|
%div
|
54
63
|
= relationship.last_verified_date
|
data/lib/pact_broker/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Webhooks
|
5
|
+
class Execution < Sequel::Model(:webhook_executions)
|
6
|
+
|
7
|
+
associate(:many_to_one, :webhook, :class => "PactBroker::Webhooks::Webhook", :key => :webhook_id, :primary_key => :id)
|
8
|
+
associate(:many_to_one, :pact_publication, :class => "PactBroker::Pacts::PactPublication", :key => :pact_publication_id, :primary_key => :id)
|
9
|
+
associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id)
|
10
|
+
associate(:many_to_one, :consumer, :class => "PactBroker::Domain::Pacticipant", :key => :consumer_id, :primary_key => :id)
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
Execution.plugin :timestamps
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -3,7 +3,7 @@ require 'pact_broker/domain/webhook'
|
|
3
3
|
require 'pact_broker/domain/pacticipant'
|
4
4
|
require 'pact_broker/db'
|
5
5
|
require 'pact_broker/webhooks/webhook'
|
6
|
-
|
6
|
+
require 'pact_broker/webhooks/execution'
|
7
7
|
|
8
8
|
module PactBroker
|
9
9
|
module Webhooks
|
@@ -43,6 +43,24 @@ module PactBroker
|
|
43
43
|
Webhook.where(consumer_id: consumer.id, provider_id: provider.id).collect(&:to_domain)
|
44
44
|
end
|
45
45
|
|
46
|
+
def create_execution webhook, webhook_execution_result
|
47
|
+
db_webhook = Webhook.where(uuid: webhook.uuid).single_record
|
48
|
+
execution = Execution.create(
|
49
|
+
webhook: db_webhook,
|
50
|
+
consumer: db_webhook.consumer,
|
51
|
+
provider: db_webhook.provider,
|
52
|
+
success: webhook_execution_result.success?,
|
53
|
+
logs: webhook_execution_result.logs)
|
54
|
+
end
|
55
|
+
|
56
|
+
def delete_executions_by_pacticipant pacticipant
|
57
|
+
Execution.where(consumer: pacticipant).delete
|
58
|
+
Execution.where(provider: pacticipant).delete
|
59
|
+
end
|
60
|
+
|
61
|
+
def unlink_executions_by_webhook_uuid uuid
|
62
|
+
Execution.where(webhook: Webhook.where(uuid: uuid)).update(webhook_id: nil)
|
63
|
+
end
|
46
64
|
end
|
47
65
|
end
|
48
|
-
end
|
66
|
+
end
|
@@ -31,6 +31,7 @@ module PactBroker
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.delete_by_uuid uuid
|
34
|
+
webhook_repository.delete_executions_by_webhook_uuid uuid
|
34
35
|
webhook_repository.delete_by_uuid uuid
|
35
36
|
end
|
36
37
|
|
@@ -43,7 +44,9 @@ module PactBroker
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def self.execute_webhook_now webhook
|
46
|
-
webhook.execute
|
47
|
+
webhook_execution_result = webhook.execute
|
48
|
+
webhook_repository.create_execution webhook, webhook_execution_result
|
49
|
+
webhook_execution_result
|
47
50
|
end
|
48
51
|
|
49
52
|
def self.find_by_consumer_and_provider consumer, provider
|
data/script/publish-2.sh
CHANGED
data/script/publish-new.sh
CHANGED
data/script/publish.sh
CHANGED
data/script/recreate-pg-db.sh
CHANGED
@@ -9,3 +9,5 @@ echo "export PACT_BROKER_DATABASE_USERNAME=pact_broker"
|
|
9
9
|
echo "export PACT_BROKER_DATABASE_PASSWORD=pact_broker"
|
10
10
|
echo "export PACT_BROKER_DATABASE_NAME=pact_broker"
|
11
11
|
echo "export PACT_BROKER_DATABASE_HOST=${ip}"
|
12
|
+
echo "To test:"
|
13
|
+
echo "psql -h \$PACT_BROKER_DATABASE_HOST -d \$PACT_BROKER_DATABASE_NAME -U \$PACT_BROKER_DATABASE_USERNAME"
|
@@ -5,8 +5,13 @@ module PactBroker
|
|
5
5
|
module Api
|
6
6
|
module Contracts
|
7
7
|
describe PutPactParamsContract do
|
8
|
+
before do
|
9
|
+
allow(PactBroker.configuration).to receive(:order_versions_by_date).and_return(order_versions_by_date)
|
10
|
+
end
|
11
|
+
|
8
12
|
let(:json_content) { {'some' => 'json' }.to_json }
|
9
13
|
let(:pact_params) { Pacts::PactParams.new(attributes) }
|
14
|
+
let(:order_versions_by_date) { false }
|
10
15
|
|
11
16
|
let(:valid_attributes) do
|
12
17
|
{
|
@@ -65,6 +70,21 @@ module PactBroker
|
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
73
|
+
context "when order_versions_by_date is true" do
|
74
|
+
let(:order_versions_by_date) { true }
|
75
|
+
|
76
|
+
context "with an invalid version number" do
|
77
|
+
let(:attributes) do
|
78
|
+
valid_attributes.merge(consumer_version_number: 'blah')
|
79
|
+
end
|
80
|
+
|
81
|
+
it "does not return an error" do
|
82
|
+
expect(subject.errors[:consumer_version_number]).to be_empty
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
68
88
|
context "with a consumer name in the pact that does not match the consumer name in the path" do
|
69
89
|
let(:attributes) do
|
70
90
|
valid_attributes.merge(consumer_name: "another consumer")
|
@@ -8,7 +8,8 @@ module PactBroker
|
|
8
8
|
|
9
9
|
describe "to_json" do
|
10
10
|
|
11
|
-
let(:webhook_execution_result) { PactBroker::Domain::WebhookExecutionResult.new(response, error)}
|
11
|
+
let(:webhook_execution_result) { PactBroker::Domain::WebhookExecutionResult.new(response, logs, error)}
|
12
|
+
let(:logs) { "logs" }
|
12
13
|
let(:headers) { { "Something" => ["blah", "thing"]} }
|
13
14
|
let(:response) { double('http_response', code: '200', body: response_body, to_hash: headers) }
|
14
15
|
let(:response_body) { 'body' }
|
@@ -4,20 +4,22 @@ require 'pact_broker/domain/order_versions.rb'
|
|
4
4
|
|
5
5
|
describe PactBroker::Domain::OrderVersions do
|
6
6
|
|
7
|
+
before do
|
8
|
+
allow(PactBroker.configuration).to receive(:order_versions_by_date).and_return(false)
|
9
|
+
end
|
7
10
|
context "when order_versions_by_date is false (the default)" do
|
8
11
|
before do
|
9
12
|
ProviderStateBuilder.new
|
10
13
|
.create_condor
|
11
|
-
.create_condor_version('1.3.0')
|
12
14
|
.create_condor_version('1.5.0')
|
13
15
|
.create_condor_version('1.4.0')
|
16
|
+
.create_condor_version('1.3.0')
|
14
17
|
.create_condor_version('1.6.0')
|
15
18
|
end
|
16
19
|
|
17
20
|
let(:ordered_versions) { PactBroker::Domain::Version.order(:order).all.collect(&:number) }
|
18
|
-
let(:condor) { PactBroker::Domain::Pacticipant.where(name: 'Condor').single_record }
|
19
21
|
|
20
|
-
it "orders the versions
|
22
|
+
it "orders the versions semantically" do
|
21
23
|
expect(ordered_versions).to eq(['1.3.0', '1.4.0', '1.5.0', '1.6.0'])
|
22
24
|
end
|
23
25
|
end
|
@@ -27,15 +29,15 @@ describe PactBroker::Domain::OrderVersions do
|
|
27
29
|
allow(PactBroker.configuration).to receive(:order_versions_by_date).and_return(true)
|
28
30
|
end
|
29
31
|
let(:consumer) { ProviderStateBuilder.new.create_consumer.and_return(:consumer) }
|
30
|
-
let!(:version_1) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '2'
|
31
|
-
let!(:version_2) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '1'
|
32
|
-
let!(:version_3) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '3'
|
33
|
-
let!(:version_4) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '4'
|
32
|
+
let!(:version_1) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '2') }
|
33
|
+
let!(:version_2) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '1') }
|
34
|
+
let!(:version_3) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '3') }
|
35
|
+
let!(:version_4) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '4') }
|
34
36
|
|
35
37
|
let(:ordered_versions) { PactBroker::Domain::Version.order(:order).all.collect(&:number) }
|
36
38
|
|
37
|
-
it "orders by
|
38
|
-
expect(ordered_versions).to eq(['
|
39
|
+
it "orders by insertion order" do
|
40
|
+
expect(ordered_versions).to eq(['2', '1', '3', '4'])
|
39
41
|
end
|
40
42
|
|
41
43
|
end
|
@@ -53,12 +55,32 @@ describe PactBroker::Domain::OrderVersions do
|
|
53
55
|
|
54
56
|
let(:ordered_versions) { PactBroker::Domain::Version.order(:order).all.collect(&:number) }
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
context "when the new version is considered to be the latest" do
|
59
|
+
before do
|
60
|
+
Sequel::Model.db[:versions].where(number: '1').update(number: 'z')
|
61
|
+
Sequel::Model.db[:versions].where(number: '2').update(number: 'a')
|
62
|
+
Sequel::Model.db[:versions].where(number: '4').update(number: 'h')
|
63
|
+
end
|
64
|
+
|
65
|
+
it "just uses the next order number for the new version" do
|
66
|
+
PactBroker::Domain::Version.create(number: '5', pacticipant_id: consumer.id)
|
67
|
+
expect(ordered_versions).to eq(['z', 'a', '3', 'h', '5'])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when the new version is considered to be earlier than the previous latest version" do
|
72
|
+
|
73
|
+
before do
|
74
|
+
Sequel::Model.db[:versions].where(number: '2').update(number: 'z')
|
75
|
+
Sequel::Model.db[:versions].where(number: '3').update(number: 'a')
|
76
|
+
end
|
77
|
+
|
78
|
+
it "inserts the new version in the right place" do
|
79
|
+
# 1 z a 4
|
80
|
+
PactBroker::Domain::Version.create(number: '2', pacticipant_id: consumer.id)
|
81
|
+
expect(ordered_versions).to eq(['1', 'z', 'a', '2', '4'])
|
82
|
+
end
|
83
|
+
|
62
84
|
end
|
63
85
|
end
|
64
86
|
|
@@ -21,6 +21,20 @@ module PactBroker
|
|
21
21
|
expect(version.latest_pact_publication.id).to eq pact.id
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
describe "uq_ver_ppt_ord" do
|
26
|
+
let(:consumer) do
|
27
|
+
ProviderStateBuilder.new
|
28
|
+
.create_consumer
|
29
|
+
.and_return(:consumer)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "does not allow two versions with the same pacticipant and order" do
|
33
|
+
Sequel::Model.db[:versions].insert(number: '1', order: 0, pacticipant_id: consumer.id, created_at: DateTime.new(2017), updated_at: DateTime.new(2017))
|
34
|
+
expect { Sequel::Model.db[:versions].insert(number: '2', order: 0, pacticipant_id: consumer.id, created_at: DateTime.new(2017), updated_at: DateTime.new(2017)) }
|
35
|
+
.to raise_error(Sequel::UniqueConstraintViolation)
|
36
|
+
end
|
37
|
+
end
|
24
38
|
end
|
25
39
|
end
|
26
40
|
end
|
@@ -12,12 +12,14 @@ module PactBroker
|
|
12
12
|
let(:password) { nil }
|
13
13
|
let(:url) { 'http://example.org/hook' }
|
14
14
|
let(:body) { 'body' }
|
15
|
+
let(:logs) { StringIO.new }
|
16
|
+
let(:execution_logger) { Logger.new(logs) }
|
15
17
|
|
16
18
|
subject do
|
17
19
|
WebhookRequest.new(
|
18
20
|
method: 'post',
|
19
21
|
url: url,
|
20
|
-
headers: {'Content-
|
22
|
+
headers: {'Content-Type' => 'text/plain'},
|
21
23
|
username: username,
|
22
24
|
password: password,
|
23
25
|
body: body)
|
@@ -48,7 +50,7 @@ module PactBroker
|
|
48
50
|
let!(:http_request) do
|
49
51
|
stub_request(:post, "http://example.org/hook").
|
50
52
|
with(:headers => {'Content-Type'=>'text/plain'}, :body => 'body').
|
51
|
-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/
|
53
|
+
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
52
54
|
end
|
53
55
|
|
54
56
|
it "executes the configured request" do
|
@@ -70,6 +72,47 @@ module PactBroker
|
|
70
72
|
subject.execute
|
71
73
|
end
|
72
74
|
|
75
|
+
describe "execution logs" do
|
76
|
+
before do
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:logs) { subject.execute.logs }
|
81
|
+
|
82
|
+
it "logs the request method and path" do
|
83
|
+
expect(logs).to include "POST http://example.org/hook"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "logs the request headers" do
|
87
|
+
expect(logs).to include "Content-Type: text/plain"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "logs the request body" do
|
91
|
+
expect(logs).to include body
|
92
|
+
end
|
93
|
+
|
94
|
+
it "logs the response status" do
|
95
|
+
expect(logs).to include "HTTP/1.0 302"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "logs the response headers" do
|
99
|
+
expect(logs).to include "Content-Type: text/foo, blah"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "logs the response body" do
|
103
|
+
expect(logs).to include "respbod"
|
104
|
+
end
|
105
|
+
|
106
|
+
context "with basic auth" do
|
107
|
+
let(:username) { 'username' }
|
108
|
+
let(:password) { 'password' }
|
109
|
+
|
110
|
+
it "logs the username and a starred password" do
|
111
|
+
expect(logs).to include "POST http://username:**********@example.org/hook"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
73
116
|
context "when a username and password are specified" do
|
74
117
|
|
75
118
|
let(:username) { 'username' }
|
@@ -81,7 +124,7 @@ module PactBroker
|
|
81
124
|
basic_auth: [username, password],
|
82
125
|
:headers => {'Content-Type'=>'text/plain'},
|
83
126
|
:body => 'body').
|
84
|
-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/
|
127
|
+
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
85
128
|
end
|
86
129
|
|
87
130
|
it "uses the credentials" do
|
@@ -97,7 +140,7 @@ module PactBroker
|
|
97
140
|
# webmock will set the request signature scheme to 'https' _only_ if the use_ssl option is set
|
98
141
|
stub_request(:post, "https://example.org/hook").
|
99
142
|
with(:headers => {'Content-Type'=>'text/plain'}, :body => 'body').
|
100
|
-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/
|
143
|
+
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
101
144
|
end
|
102
145
|
|
103
146
|
it "uses SSL" do
|
@@ -112,7 +155,7 @@ module PactBroker
|
|
112
155
|
let!(:http_request) do
|
113
156
|
stub_request(:post, "http://example.org/hook").
|
114
157
|
with(:headers => {'Content-Type'=>'text/plain'}, :body => body.to_json).
|
115
|
-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/
|
158
|
+
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
116
159
|
end
|
117
160
|
|
118
161
|
it "converts the body to JSON before submitting the request" do
|
@@ -127,7 +170,7 @@ module PactBroker
|
|
127
170
|
let!(:http_request) do
|
128
171
|
stub_request(:post, "http://example.org/hook").
|
129
172
|
with(:headers => {'Content-Type'=>'text/plain'}, :body => nil).
|
130
|
-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/
|
173
|
+
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
|
131
174
|
end
|
132
175
|
|
133
176
|
it "executes the request without a body" do
|