pact_broker 2.31.0 → 2.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/db/migrations/20190509_create_version_sequence.rb +8 -0
- data/db/migrations/20190510_set_version_sequence.rb +9 -0
- data/db/migrations/20190511_create_integrations_view.rb +19 -0
- data/db/migrations/20190523_add_enabled_column_to_webhooks.rb +5 -0
- data/db/migrations/20190524_set_webhooks_enabled.rb +10 -0
- data/db/migrations/20190525_add_description_column_to_webhooks.rb +5 -0
- data/lib/pact_broker/api.rb +3 -0
- data/lib/pact_broker/api/decorators/base_decorator.rb +0 -3
- data/lib/pact_broker/api/decorators/integration_decorator.rb +40 -0
- data/lib/pact_broker/api/decorators/integrations_decorator.rb +19 -0
- data/lib/pact_broker/api/decorators/pact_decorator.rb +1 -1
- data/lib/pact_broker/api/decorators/pact_details_decorator.rb +1 -6
- data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +12 -0
- data/lib/pact_broker/api/decorators/verifiable_pacts_decorator.rb +20 -0
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +5 -1
- data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/webhooks_decorator.rb +2 -2
- data/lib/pact_broker/api/pact_broker_urls.rb +37 -3
- data/lib/pact_broker/api/resources/base_resource.rb +4 -0
- data/lib/pact_broker/api/resources/dashboard.rb +1 -1
- data/lib/pact_broker/api/resources/integrations.rb +10 -2
- data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +8 -14
- data/lib/pact_broker/api/resources/pact.rb +15 -3
- data/lib/pact_broker/api/resources/verification.rb +0 -2
- data/lib/pact_broker/api/resources/verifications.rb +18 -1
- data/lib/pact_broker/api/resources/webhook.rb +1 -1
- data/lib/pact_broker/api/resources/webhook_execution.rb +18 -9
- data/lib/pact_broker/app.rb +10 -11
- data/lib/pact_broker/db.rb +2 -2
- data/lib/pact_broker/db/data_migrations/helpers.rb +11 -0
- data/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb +29 -0
- data/lib/pact_broker/db/data_migrations/set_webhooks_enabled.rb +17 -0
- data/lib/pact_broker/db/migrate_data.rb +2 -0
- data/lib/pact_broker/db/seed_example_data.rb +6 -3
- data/lib/pact_broker/domain/order_versions.rb +14 -1
- data/lib/pact_broker/domain/verification.rb +4 -0
- data/lib/pact_broker/domain/webhook.rb +13 -3
- data/lib/pact_broker/domain/webhook_request.rb +3 -2
- data/lib/pact_broker/index/service.rb +3 -0
- data/lib/pact_broker/integrations/integration.rb +10 -0
- data/lib/pact_broker/integrations/service.rb +5 -0
- data/lib/pact_broker/matrix/parse_query.rb +2 -0
- data/lib/pact_broker/matrix/row.rb +8 -0
- data/lib/pact_broker/matrix/service.rb +1 -2
- data/lib/pact_broker/pacts/service.rb +16 -9
- data/lib/pact_broker/test/test_data_builder.rb +6 -2
- data/lib/pact_broker/verifications/sequence.rb +0 -2
- data/lib/pact_broker/verifications/service.rb +10 -2
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/sequence.rb +38 -0
- data/lib/pact_broker/webhooks/job.rb +19 -7
- data/lib/pact_broker/webhooks/render.rb +30 -13
- data/lib/pact_broker/webhooks/repository.rb +3 -4
- data/lib/pact_broker/webhooks/service.rb +60 -34
- data/lib/pact_broker/webhooks/trigger_service.rb +6 -6
- data/lib/pact_broker/webhooks/webhook.rb +9 -1
- data/lib/pact_broker/webhooks/webhook_request_template.rb +11 -7
- data/lib/rack/pact_broker/database_transaction.rb +6 -2
- data/script/publish-new.sh +23 -1
- data/script/publish.sh +13 -4
- data/script/seed.rb +53 -52
- data/spec/features/create_webhook_spec.rb +2 -0
- data/spec/features/execute_webhook_spec.rb +4 -3
- data/spec/features/get_integrations_spec.rb +17 -0
- data/spec/features/get_pacts_to_verify_spec.rb +7 -3
- data/spec/features/publish_verification_spec.rb +8 -1
- data/spec/features/update_webhook_spec.rb +47 -0
- data/spec/integration/webhooks/certificate_spec.rb +1 -1
- data/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +12 -0
- data/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb +82 -0
- data/spec/lib/pact_broker/api/decorators/integrations_decorator_spec.rb +29 -0
- data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +12 -4
- data/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb +30 -0
- data/spec/lib/pact_broker/api/decorators/verifiable_pacts_decorator_spec.rb +29 -0
- data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +20 -1
- data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +0 -4
- data/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb +5 -4
- data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +64 -1
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +0 -3
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +40 -10
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +13 -3
- data/spec/lib/pact_broker/app_spec.rb +28 -4
- data/spec/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value_spec.rb +68 -0
- data/spec/lib/pact_broker/domain/order_versions_spec.rb +1 -4
- data/spec/lib/pact_broker/domain/webhook_spec.rb +10 -6
- data/spec/lib/pact_broker/matrix/parse_query_spec.rb +15 -7
- data/spec/lib/pact_broker/pacts/service_spec.rb +13 -5
- data/spec/lib/pact_broker/verifications/service_spec.rb +15 -3
- data/spec/lib/pact_broker/versions/repository_spec.rb +1 -1
- data/spec/lib/pact_broker/webhooks/job_spec.rb +52 -15
- data/spec/lib/pact_broker/webhooks/render_spec.rb +28 -7
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +23 -32
- data/spec/lib/pact_broker/webhooks/service_spec.rb +186 -62
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +6 -5
- data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +12 -5
- data/spec/lib/rack/pact_broker/database_transaction_spec.rb +10 -0
- data/spec/lib/rack/pact_broker/ui_request_filter_spec.rb +9 -0
- data/spec/migrations/23_pact_versions_spec.rb +7 -1
- data/spec/support/database_cleaner.rb +11 -1
- data/spec/support/metadata_test_server.rb +40 -0
- data/spec/support/verification_job.rb +34 -0
- data/spec/support/webhook_endpoint_middleware.rb +22 -0
- metadata +37 -2
@@ -18,9 +18,16 @@ module PactBroker
|
|
18
18
|
allow(PactBroker::Webhooks::Service).to receive(:trigger_webhooks)
|
19
19
|
end
|
20
20
|
|
21
|
+
let(:options) { { webhook_context: {} } }
|
22
|
+
let(:expected_options) { { webhook_context: { provider_version_tags: %w[dev] } } }
|
21
23
|
let(:params) { {'success' => true, 'providerApplicationVersion' => '4.5.6'} }
|
22
|
-
let(:pact)
|
23
|
-
|
24
|
+
let(:pact) do
|
25
|
+
td.create_pact_with_hierarchy
|
26
|
+
.create_provider_version('4.5.6')
|
27
|
+
.create_provider_version_tag('dev')
|
28
|
+
.and_return(:pact)
|
29
|
+
end
|
30
|
+
let(:create_verification) { subject.create 3, params, pact, options }
|
24
31
|
|
25
32
|
it "logs the creation" do
|
26
33
|
expect(logger).to receive(:info).with(/.*verification.*3.*success/)
|
@@ -47,7 +54,12 @@ module PactBroker
|
|
47
54
|
|
48
55
|
it "invokes the webhooks for the verification" do
|
49
56
|
verification = create_verification
|
50
|
-
expect(PactBroker::Webhooks::Service).to have_received(:trigger_webhooks).with(
|
57
|
+
expect(PactBroker::Webhooks::Service).to have_received(:trigger_webhooks).with(
|
58
|
+
pact,
|
59
|
+
verification,
|
60
|
+
PactBroker::Webhooks::WebhookEvent::VERIFICATION_PUBLISHED,
|
61
|
+
expected_options
|
62
|
+
)
|
51
63
|
end
|
52
64
|
end
|
53
65
|
|
@@ -93,7 +93,7 @@ module PactBroker
|
|
93
93
|
expect(subject.number).to eq version_number
|
94
94
|
expect(subject.pacticipant.name).to eq pacticipant_name
|
95
95
|
expect(subject.tags.first.name).to eq "prod"
|
96
|
-
expect(subject.order).
|
96
|
+
expect(subject.order).to_not be nil
|
97
97
|
end
|
98
98
|
|
99
99
|
context "when case sensitivity is turned off and names with different cases are used" do
|
@@ -17,8 +17,17 @@ module PactBroker
|
|
17
17
|
let(:success) { true }
|
18
18
|
let(:logger) { double('logger').as_null_object }
|
19
19
|
let(:database_connector) { ->(&block) { block.call } }
|
20
|
+
let(:webhook_context) { { the: "context" } }
|
21
|
+
let(:job_params) do
|
22
|
+
{
|
23
|
+
triggered_webhook: triggered_webhook,
|
24
|
+
database_connector: database_connector,
|
25
|
+
webhook_context: webhook_context,
|
26
|
+
execution_options: { the: 'options' }
|
27
|
+
}
|
28
|
+
end
|
20
29
|
|
21
|
-
subject { Job.new.perform(
|
30
|
+
subject { Job.new.perform(job_params) }
|
22
31
|
|
23
32
|
it "reloads the TriggeredWebhook object to make sure it has a fresh copy" do
|
24
33
|
expect(PactBroker::Webhooks::TriggeredWebhook).to receive(:find).with(id: 1)
|
@@ -26,7 +35,6 @@ module PactBroker
|
|
26
35
|
end
|
27
36
|
|
28
37
|
context "when the job succeeds" do
|
29
|
-
|
30
38
|
it "does not reschedule the job" do
|
31
39
|
expect(Job).to_not receive(:perform_in)
|
32
40
|
subject
|
@@ -45,7 +53,16 @@ module PactBroker
|
|
45
53
|
end
|
46
54
|
|
47
55
|
it "reschedules the job in 10 seconds" do
|
48
|
-
expect(Job).to receive(:perform_in).with(10,
|
56
|
+
expect(Job).to receive(:perform_in).with(10, hash_including(error_count: 1))
|
57
|
+
subject
|
58
|
+
end
|
59
|
+
|
60
|
+
it "reschedules the job with the passed in data" do
|
61
|
+
expect(Job).to receive(:perform_in).with(10, hash_including(
|
62
|
+
webhook_context: webhook_context,
|
63
|
+
database_connector: database_connector,
|
64
|
+
triggered_webhook: triggered_webhook
|
65
|
+
))
|
49
66
|
subject
|
50
67
|
end
|
51
68
|
|
@@ -60,16 +77,19 @@ module PactBroker
|
|
60
77
|
let(:success) { false }
|
61
78
|
|
62
79
|
it "reschedules the job in 10 seconds" do
|
63
|
-
expect(Job).to receive(:perform_in).with(10,
|
80
|
+
expect(Job).to receive(:perform_in).with(10, hash_including(error_count: 1))
|
64
81
|
subject
|
65
82
|
end
|
66
83
|
|
67
84
|
it "executes the job with an log message indicating that the webhook will be retried" do
|
68
85
|
expect(PactBroker::Webhooks::Service).to receive(:execute_triggered_webhook_now)
|
69
86
|
.with(triggered_webhook, {
|
70
|
-
|
71
|
-
|
72
|
-
|
87
|
+
execution_options: {
|
88
|
+
failure_log_message: "Retrying webhook in 10 seconds",
|
89
|
+
success_log_message: "Successfully executed webhook",
|
90
|
+
the: 'options'
|
91
|
+
},
|
92
|
+
webhook_context: webhook_context
|
73
93
|
})
|
74
94
|
subject
|
75
95
|
end
|
@@ -84,12 +104,13 @@ module PactBroker
|
|
84
104
|
context "when an error occurs for the second time" do
|
85
105
|
before do
|
86
106
|
allow(PactBroker::Webhooks::Service).to receive(:execute_triggered_webhook_now).and_raise("an error")
|
107
|
+
job_params[:error_count] = 1
|
87
108
|
end
|
88
109
|
|
89
|
-
subject { Job.new.perform(triggered_webhook: triggered_webhook, error_count: 1, database_connector: database_connector, base_url: base_url) }
|
110
|
+
# subject { Job.new.perform(triggered_webhook: triggered_webhook, error_count: 1, database_connector: database_connector, base_url: base_url) }
|
90
111
|
|
91
112
|
it "reschedules the job in 60 seconds" do
|
92
|
-
expect(Job).to receive(:perform_in).with(60,
|
113
|
+
expect(Job).to receive(:perform_in).with(60, hash_including(error_count: 2))
|
93
114
|
subject
|
94
115
|
end
|
95
116
|
|
@@ -102,16 +123,20 @@ module PactBroker
|
|
102
123
|
|
103
124
|
context "when the job is not successful for the last time" do
|
104
125
|
let(:success) { false }
|
126
|
+
before do
|
127
|
+
job_params[:error_count] = 6
|
128
|
+
end
|
105
129
|
|
106
|
-
subject { Job.new.perform(triggered_webhook: triggered_webhook, error_count: 6, database_connector: database_connector, base_url: base_url) }
|
130
|
+
# subject { Job.new.perform(triggered_webhook: triggered_webhook, error_count: 6, database_connector: database_connector, base_url: base_url) }
|
107
131
|
|
108
132
|
it "executes the job with an log message indicating that the webhook has failed" do
|
109
133
|
expect(PactBroker::Webhooks::Service).to receive(:execute_triggered_webhook_now)
|
110
|
-
.with(triggered_webhook,
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
134
|
+
.with(triggered_webhook, hash_including(
|
135
|
+
execution_options: hash_including(
|
136
|
+
failure_log_message: "Webhook execution failed after 7 attempts",
|
137
|
+
success_log_message: "Successfully executed webhook")
|
138
|
+
)
|
139
|
+
)
|
115
140
|
subject
|
116
141
|
end
|
117
142
|
|
@@ -131,6 +156,18 @@ module PactBroker
|
|
131
156
|
subject
|
132
157
|
end
|
133
158
|
end
|
159
|
+
|
160
|
+
context "when the webhook gets deleted between executions" do
|
161
|
+
before do
|
162
|
+
allow(PactBroker::Webhooks::TriggeredWebhook).to receive(:find).and_return(nil)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "does not reschedule the job" do
|
166
|
+
expect(Job).to_not receive(:perform_in)
|
167
|
+
expect(logger).to receive(:info).with(/Could not find webhook with id: 1/)
|
168
|
+
subject
|
169
|
+
end
|
170
|
+
end
|
134
171
|
end
|
135
172
|
end
|
136
173
|
end
|
@@ -8,7 +8,7 @@ module PactBroker
|
|
8
8
|
describe Render do
|
9
9
|
describe "#call" do
|
10
10
|
before do
|
11
|
-
allow(PactBroker::Api::PactBrokerUrls).to receive(:
|
11
|
+
allow(PactBroker::Api::PactBrokerUrls).to receive(:pact_version_url_with_metadata).and_return("http://foo")
|
12
12
|
allow(PactBroker::Api::PactBrokerUrls).to receive(:verification_url) do | verification, base_url |
|
13
13
|
expect(verification).to_not be nil
|
14
14
|
"http://verification"
|
@@ -92,11 +92,11 @@ module PactBroker
|
|
92
92
|
[ double("label", name: "foo"), double("label", name: "bar") ]
|
93
93
|
end
|
94
94
|
|
95
|
+
let(:webhook_context) { { base_url: base_url } }
|
96
|
+
|
95
97
|
let(:nil_pact) { nil }
|
96
98
|
let(:nil_verification) { nil }
|
97
99
|
|
98
|
-
subject { Render.call(template, pact, verification, base_url) }
|
99
|
-
|
100
100
|
TEST_CASES = [
|
101
101
|
["${pactbroker.pactUrl}", "http://foo", :pact, :verification],
|
102
102
|
["${pactbroker.consumerVersionNumber}", "1.2.3+foo", :pact, :verification],
|
@@ -124,7 +124,7 @@ module PactBroker
|
|
124
124
|
it "replaces #{template} with #{expected_output.inspect}" do
|
125
125
|
the_pact = send(pact_var_name)
|
126
126
|
the_verification = send(verification_var_name)
|
127
|
-
output = Render.call(template, the_pact, the_verification,
|
127
|
+
output = Render.call(template, the_pact, the_verification, webhook_context)
|
128
128
|
expect(output).to eq expected_output
|
129
129
|
end
|
130
130
|
end
|
@@ -132,7 +132,7 @@ module PactBroker
|
|
132
132
|
|
133
133
|
context "with an escaper" do
|
134
134
|
subject do
|
135
|
-
Render.call(template, pact, verification,
|
135
|
+
Render.call(template, pact, verification, webhook_context) do | value |
|
136
136
|
CGI.escape(value)
|
137
137
|
end
|
138
138
|
end
|
@@ -142,6 +142,27 @@ module PactBroker
|
|
142
142
|
|
143
143
|
it { is_expected.to eq "http%3A%2F%2Ffoo" }
|
144
144
|
end
|
145
|
+
|
146
|
+
context "with webhook context data passed in" do
|
147
|
+
let(:webhook_context) do
|
148
|
+
{
|
149
|
+
consumer_version_number: "webhook-version-number",
|
150
|
+
consumer_version_tags: %w[webhook tags]
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
it "uses the consumer_version_number in preference to the field on the domain models" do
|
155
|
+
template = "${pactbroker.consumerVersionNumber}"
|
156
|
+
output = Render.call(template, pact, verification, webhook_context)
|
157
|
+
expect(output).to eq "webhook-version-number"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "uses the consumer_version_tags in preference to the field on the domain models" do
|
161
|
+
template = "${pactbroker.consumerVersionTags}"
|
162
|
+
output = Render.call(template, pact, verification, webhook_context)
|
163
|
+
expect(output).to eq "webhook, tags"
|
164
|
+
end
|
165
|
+
end
|
145
166
|
end
|
146
167
|
|
147
168
|
describe "#call with placeholder domain objects" do
|
@@ -150,11 +171,11 @@ module PactBroker
|
|
150
171
|
let(:base_url) { "http://broker" }
|
151
172
|
|
152
173
|
it "does not blow up with a placeholder pact" do
|
153
|
-
Render.call("", placeholder_pact, nil,
|
174
|
+
Render.call("", placeholder_pact, nil, {})
|
154
175
|
end
|
155
176
|
|
156
177
|
it "does not blow up with a placeholder verification" do
|
157
|
-
Render.call("", placeholder_pact, placeholder_verification,
|
178
|
+
Render.call("", placeholder_pact, placeholder_verification, {})
|
158
179
|
end
|
159
180
|
end
|
160
181
|
end
|
@@ -196,6 +196,13 @@ module PactBroker
|
|
196
196
|
end
|
197
197
|
|
198
198
|
describe "update_by_uuid" do
|
199
|
+
before do
|
200
|
+
td.create_consumer("Foo")
|
201
|
+
.create_provider
|
202
|
+
.create_webhook(old_webhook_params)
|
203
|
+
.create_consumer("Foo2")
|
204
|
+
end
|
205
|
+
|
199
206
|
let(:uuid) { '1234' }
|
200
207
|
let(:old_webhook_params) do
|
201
208
|
{
|
@@ -209,7 +216,7 @@ module PactBroker
|
|
209
216
|
password: 'password'
|
210
217
|
}
|
211
218
|
end
|
212
|
-
let(:
|
219
|
+
let(:new_request_webhook_params) do
|
213
220
|
{
|
214
221
|
method: 'GET',
|
215
222
|
url: 'http://example.com',
|
@@ -217,16 +224,17 @@ module PactBroker
|
|
217
224
|
headers: {'Content-Type' => 'text/plain'}
|
218
225
|
}
|
219
226
|
end
|
227
|
+
let(:new_request) { PactBroker::Domain::WebhookRequest.new(new_request_webhook_params) }
|
220
228
|
let(:new_event) do
|
221
229
|
PactBroker::Webhooks::WebhookEvent.new(name: 'something_else')
|
222
230
|
end
|
223
|
-
|
224
|
-
td.create_consumer
|
225
|
-
.create_provider
|
226
|
-
.create_webhook(old_webhook_params)
|
227
|
-
end
|
231
|
+
let(:new_consumer) { PactBroker::Domain::Pacticipant.new(name: "Foo2") }
|
228
232
|
let(:new_webhook) do
|
229
|
-
PactBroker::Domain::Webhook.new(
|
233
|
+
PactBroker::Domain::Webhook.new(
|
234
|
+
consumer: new_consumer,
|
235
|
+
events: [new_event],
|
236
|
+
request: new_request
|
237
|
+
)
|
230
238
|
end
|
231
239
|
|
232
240
|
subject { Repository.new.update_by_uuid(uuid, new_webhook) }
|
@@ -241,6 +249,7 @@ module PactBroker
|
|
241
249
|
expect(updated_webhook.request.username).to eq nil
|
242
250
|
expect(updated_webhook.request.password).to eq nil
|
243
251
|
expect(updated_webhook.events.first.name).to eq 'something_else'
|
252
|
+
expect(updated_webhook.consumer.name).to eq "Foo2"
|
244
253
|
end
|
245
254
|
end
|
246
255
|
|
@@ -332,7 +341,6 @@ module PactBroker
|
|
332
341
|
subject { Repository.new.find_by_consumer_and_provider_and_event_name td.consumer, td.provider, 'something_happened' }
|
333
342
|
|
334
343
|
context "when a webhook exists with a matching consumer and provider and event name" do
|
335
|
-
|
336
344
|
before do
|
337
345
|
td
|
338
346
|
.create_consumer("Consumer")
|
@@ -347,32 +355,15 @@ module PactBroker
|
|
347
355
|
it "returns an array of webhooks" do
|
348
356
|
expect(subject.collect(&:uuid).sort).to eq ['1', '2']
|
349
357
|
end
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
describe "find_for_pact_and_event_name" do
|
354
|
-
context "when a webhook exists with a matching consumer and provider and event name" do
|
355
|
-
before do
|
356
|
-
td
|
357
|
-
.create_consumer("Consumer")
|
358
|
-
.create_consumer_version("1")
|
359
|
-
.create_provider("Another Provider")
|
360
|
-
.create_webhook
|
361
|
-
.create_provider("Provider")
|
362
|
-
.create_pact
|
363
|
-
.create_webhook(uuid: '1', events: [{ name: 'something_happened' }])
|
364
|
-
.create_webhook(uuid: '2', events: [{ name: 'something_happened' }])
|
365
|
-
.create_webhook(uuid: '3', events: [{ name: 'something_else_happened' }])
|
366
|
-
.create_consumer_webhook(uuid: '4', events: [{ name: 'something_happened' }])
|
367
|
-
.create_provider_webhook(uuid: '5', events: [{ name: 'something_happened' }])
|
368
|
-
.create_global_webhook(uuid: '6', events: [{ name: 'something_happened' }])
|
369
|
-
.create_global_webhook(uuid: '7', events: [{ name: 'something_else_happened' }])
|
370
|
-
end
|
371
358
|
|
372
|
-
|
359
|
+
context "when the webhook is not enabled" do
|
360
|
+
before do
|
361
|
+
Webhook.where(uuid: '2').update(enabled: false)
|
362
|
+
end
|
373
363
|
|
374
|
-
|
375
|
-
|
364
|
+
it "is not returned" do
|
365
|
+
expect(subject.collect(&:uuid).sort).to_not include('2 ')
|
366
|
+
end
|
376
367
|
end
|
377
368
|
end
|
378
369
|
end
|
@@ -33,8 +33,117 @@ module PactBroker
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe ".
|
36
|
+
describe ".update_by_uuid" do
|
37
|
+
before do
|
38
|
+
allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:find_by_uuid).and_return(existing_webhook)
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:request) { PactBroker::Webhooks::WebhookRequestTemplate.new(password: existing_password, headers: headers)}
|
42
|
+
let(:existing_password) { nil }
|
43
|
+
let(:headers) { {} }
|
44
|
+
let(:existing_webhook) { PactBroker::Domain::Webhook.new(request: request) }
|
45
|
+
let(:params) do
|
46
|
+
{
|
47
|
+
'request' => {
|
48
|
+
'url' => "http://url"
|
49
|
+
}
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
subject { Service.update_by_uuid("1234", params) }
|
54
|
+
|
55
|
+
it "sends through the params to the repository" do
|
56
|
+
updated_webhook = nil
|
57
|
+
allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
|
58
|
+
updated_webhook = webhook
|
59
|
+
true
|
60
|
+
end
|
61
|
+
subject
|
62
|
+
expect(updated_webhook.request.url).to eq 'http://url'
|
63
|
+
end
|
37
64
|
|
65
|
+
context "when the webhook has a password and the incoming parameters do not contain a password" do
|
66
|
+
let(:existing_password) { 'password' }
|
67
|
+
|
68
|
+
it "does not overwite the password" do
|
69
|
+
updated_webhook = nil
|
70
|
+
allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
|
71
|
+
updated_webhook = webhook
|
72
|
+
true
|
73
|
+
end
|
74
|
+
subject
|
75
|
+
expect(updated_webhook.request.password).to eq 'password'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when the webhook has a password and the incoming parameters contain a *** password" do
|
80
|
+
let(:existing_password) { 'password' }
|
81
|
+
let(:params) do
|
82
|
+
{
|
83
|
+
'request' => {
|
84
|
+
'url' => 'http://url',
|
85
|
+
'password' => '*******'
|
86
|
+
}
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "does not overwite the password" do
|
91
|
+
updated_webhook = nil
|
92
|
+
allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
|
93
|
+
updated_webhook = webhook
|
94
|
+
true
|
95
|
+
end
|
96
|
+
subject
|
97
|
+
expect(updated_webhook.request.password).to eq 'password'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when the webhook has an authorization header and the incoming parameters contain a *** authorization header" do
|
102
|
+
let(:headers) { { 'Authorization' => 'existing'} }
|
103
|
+
let(:params) do
|
104
|
+
{
|
105
|
+
'request' => {
|
106
|
+
'url' => "http://url",
|
107
|
+
'headers' => {
|
108
|
+
'authorization' => "***********"
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
it "does not overwite the authorization header" do
|
115
|
+
updated_webhook = nil
|
116
|
+
allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
|
117
|
+
updated_webhook = webhook
|
118
|
+
true
|
119
|
+
end
|
120
|
+
subject
|
121
|
+
expect(updated_webhook.request.headers['Authorization']).to eq 'existing'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "the incoming parameters contain a password" do
|
126
|
+
let(:params) do
|
127
|
+
{
|
128
|
+
'request' => {
|
129
|
+
'password' => "updated"
|
130
|
+
}
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
it "updates the password" do
|
135
|
+
updated_webhook = nil
|
136
|
+
allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
|
137
|
+
updated_webhook = webhook
|
138
|
+
true
|
139
|
+
end
|
140
|
+
subject
|
141
|
+
expect(updated_webhook.request.password).to eq 'updated'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe ".trigger_webhooks" do
|
38
147
|
let(:verification) { instance_double(PactBroker::Domain::Verification)}
|
39
148
|
let(:pact) { instance_double(PactBroker::Domain::Pact, consumer: consumer, provider: provider, consumer_version: consumer_version)}
|
40
149
|
let(:consumer_version) { PactBroker::Domain::Version.new(number: '1.2.3') }
|
@@ -42,6 +151,12 @@ module PactBroker
|
|
42
151
|
let(:provider) { PactBroker::Domain::Pacticipant.new(name: 'Provider') }
|
43
152
|
let(:webhooks) { [instance_double(PactBroker::Domain::Webhook, description: 'description', uuid: '1244')]}
|
44
153
|
let(:triggered_webhook) { instance_double(PactBroker::Webhooks::TriggeredWebhook) }
|
154
|
+
let(:options) do
|
155
|
+
{ database_connector: double('database_connector'),
|
156
|
+
webhook_context: {},
|
157
|
+
execution_options: {}
|
158
|
+
}
|
159
|
+
end
|
45
160
|
|
46
161
|
before do
|
47
162
|
allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:find_by_consumer_and_or_provider_and_event_name).and_return(webhooks)
|
@@ -49,7 +164,7 @@ module PactBroker
|
|
49
164
|
allow(Job).to receive(:perform_in)
|
50
165
|
end
|
51
166
|
|
52
|
-
subject { Service.trigger_webhooks pact, verification, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED }
|
167
|
+
subject { Service.trigger_webhooks pact, verification, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, options }
|
53
168
|
|
54
169
|
it "finds the webhooks" do
|
55
170
|
expect_any_instance_of(PactBroker::Webhooks::Repository).to receive(:find_by_consumer_and_or_provider_and_event_name).with(consumer, provider, PactBroker::Webhooks::WebhookEvent::DEFAULT_EVENT_NAME)
|
@@ -58,7 +173,7 @@ module PactBroker
|
|
58
173
|
|
59
174
|
context "when webhooks are found" do
|
60
175
|
it "executes the webhook" do
|
61
|
-
expect(Service).to receive(:run_later).with(webhooks, pact, verification, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED)
|
176
|
+
expect(Service).to receive(:run_later).with(webhooks, pact, verification, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, options)
|
62
177
|
subject
|
63
178
|
end
|
64
179
|
end
|
@@ -71,7 +186,7 @@ module PactBroker
|
|
71
186
|
end
|
72
187
|
|
73
188
|
it "logs that no webhook was found" do
|
74
|
-
expect(logger).to receive(:debug).with(/No
|
189
|
+
expect(logger).to receive(:debug).with(/No enabled webhooks found/)
|
75
190
|
subject
|
76
191
|
end
|
77
192
|
end
|
@@ -104,9 +219,13 @@ module PactBroker
|
|
104
219
|
let(:result) { double('result') }
|
105
220
|
let(:options) do
|
106
221
|
{
|
107
|
-
|
108
|
-
|
109
|
-
|
222
|
+
execution_options: {
|
223
|
+
failure_log_message: "Webhook execution failed",
|
224
|
+
show_response: 'foo',
|
225
|
+
},
|
226
|
+
webhook_context: {
|
227
|
+
base_url: 'http://broker'
|
228
|
+
}
|
110
229
|
}
|
111
230
|
end
|
112
231
|
|
@@ -114,10 +233,9 @@ module PactBroker
|
|
114
233
|
allow(PactBroker::Pacts::Service).to receive(:search_for_latest_pact).and_return(pact)
|
115
234
|
allow(PactBroker::Verifications::Service).to receive(:search_for_latest).and_return(verification)
|
116
235
|
allow(PactBroker.configuration).to receive(:show_webhook_response?).and_return('foo')
|
117
|
-
allow(Service).to receive(:base_url).and_return("http://broker")
|
118
236
|
end
|
119
237
|
|
120
|
-
subject { Service.test_execution(webhook) }
|
238
|
+
subject { Service.test_execution(webhook, options) }
|
121
239
|
|
122
240
|
it "searches for the latest matching pact" do
|
123
241
|
expect(PactBroker::Pacts::Service).to receive(:search_for_latest_pact).with(consumer_name: 'consumer', provider_name: 'provider')
|
@@ -168,54 +286,54 @@ module PactBroker
|
|
168
286
|
end
|
169
287
|
end
|
170
288
|
|
171
|
-
describe ".execute_webhook_now integration test", job: true do
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
end
|
289
|
+
# describe ".execute_webhook_now integration test", job: true do
|
290
|
+
# let(:td) { TestDataBuilder.new }
|
291
|
+
|
292
|
+
# let!(:http_request) do
|
293
|
+
# stub_request(:get, "http://example.org").
|
294
|
+
# to_return(:status => 200)
|
295
|
+
# end
|
296
|
+
|
297
|
+
# let!(:pact) do
|
298
|
+
# td.create_consumer
|
299
|
+
# .create_provider
|
300
|
+
# .create_consumer_version
|
301
|
+
# .create_pact
|
302
|
+
# .create_webhook(method: 'GET', url: 'http://example.org')
|
303
|
+
# .create_verification
|
304
|
+
# .and_return(:pact)
|
305
|
+
# end
|
306
|
+
|
307
|
+
# subject { PactBroker::Webhooks::Service.execute_webhook_now td.webhook, pact, td.verification }
|
308
|
+
|
309
|
+
# it "executes the HTTP request of the webhook" do
|
310
|
+
# subject
|
311
|
+
# expect(http_request).to have_been_made
|
312
|
+
# end
|
313
|
+
|
314
|
+
# it "saves the triggered webhook" do
|
315
|
+
# expect { subject }.to change { PactBroker::Webhooks::TriggeredWebhook.count }.by(1)
|
316
|
+
# end
|
317
|
+
|
318
|
+
# it "saves the pact" do
|
319
|
+
# subject
|
320
|
+
# expect(PactBroker::Webhooks::TriggeredWebhook.order(:id).last.pact_publication_id).to_not be nil
|
321
|
+
# end
|
322
|
+
|
323
|
+
# it "saves the verification" do
|
324
|
+
# subject
|
325
|
+
# expect(PactBroker::Webhooks::TriggeredWebhook.order(:id).last.verification_id).to_not be nil
|
326
|
+
# end
|
327
|
+
|
328
|
+
# it "saves the execution" do
|
329
|
+
# expect { subject }.to change { PactBroker::Webhooks::Execution.count }.by(1)
|
330
|
+
# end
|
331
|
+
|
332
|
+
# it "marks the triggered webhook as a success" do
|
333
|
+
# subject
|
334
|
+
# expect(TriggeredWebhook.first.status).to eq TriggeredWebhook::STATUS_SUCCESS
|
335
|
+
# end
|
336
|
+
# end
|
219
337
|
|
220
338
|
describe ".trigger_webhooks integration test", job: true do
|
221
339
|
let!(:http_request) do
|
@@ -224,7 +342,15 @@ module PactBroker
|
|
224
342
|
end
|
225
343
|
|
226
344
|
let(:events) { [{ name: PactBroker::Webhooks::WebhookEvent::DEFAULT_EVENT_NAME }] }
|
227
|
-
|
345
|
+
let(:options) do
|
346
|
+
{
|
347
|
+
database_connector: database_connector,
|
348
|
+
webhook_context: { base_url: 'http://example.org' },
|
349
|
+
execution_options: execution_options
|
350
|
+
}
|
351
|
+
end
|
352
|
+
let(:execution_options) { { show_response: true } }
|
353
|
+
let(:database_connector) { ->(&block) { block.call } }
|
228
354
|
let(:pact) do
|
229
355
|
td.create_consumer
|
230
356
|
.create_provider
|
@@ -235,7 +361,7 @@ module PactBroker
|
|
235
361
|
.and_return(:pact)
|
236
362
|
end
|
237
363
|
|
238
|
-
subject { PactBroker::Webhooks::Service.trigger_webhooks pact, td.verification, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED }
|
364
|
+
subject { PactBroker::Webhooks::Service.trigger_webhooks pact, td.verification, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, options }
|
239
365
|
|
240
366
|
it "executes the HTTP request of the webhook" do
|
241
367
|
subject
|
@@ -243,9 +369,7 @@ module PactBroker
|
|
243
369
|
end
|
244
370
|
|
245
371
|
it "executes the webhook with the correct options" do
|
246
|
-
|
247
|
-
expected_options = {:show_response => 'foo' }
|
248
|
-
expect_any_instance_of(PactBroker::Domain::WebhookRequest).to receive(:execute).with(hash_including(expected_options)).and_call_original
|
372
|
+
expect_any_instance_of(PactBroker::Domain::WebhookRequest).to receive(:execute).with(hash_including(execution_options)).and_call_original
|
249
373
|
subject
|
250
374
|
end
|
251
375
|
|