pact_broker 2.34.0 → 2.35.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +2 -0
  3. data/.github/FUNDING.yml +4 -0
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +34 -0
  6. data/DEVELOPER_DOCUMENTATION.md +24 -1
  7. data/DEVELOPER_SETUP.md +40 -20
  8. data/Dockerfile +22 -0
  9. data/db/migrations/000028_create_all_pact_publications.rb +0 -1
  10. data/db/migrations/20180311_optimise_head_matrix.rb +0 -1
  11. data/lib/pact/doc/doc_file.rb +0 -1
  12. data/lib/pact_broker/api/contracts/webhook_contract.rb +1 -1
  13. data/lib/pact_broker/api/decorators/decorator_context.rb +5 -5
  14. data/lib/pact_broker/api/decorators/pact_decorator.rb +0 -1
  15. data/lib/pact_broker/api/decorators/pact_pacticipant_decorator.rb +0 -1
  16. data/lib/pact_broker/api/decorators/tag_decorator.rb +0 -1
  17. data/lib/pact_broker/api/decorators/webhook_decorator.rb +0 -1
  18. data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +8 -5
  19. data/lib/pact_broker/api/decorators/webhook_request_template_decorator.rb +1 -4
  20. data/lib/pact_broker/api/decorators/webhooks_decorator.rb +1 -2
  21. data/lib/pact_broker/api/resources/base_resource.rb +0 -1
  22. data/lib/pact_broker/api/resources/error_handler.rb +14 -7
  23. data/lib/pact_broker/api/resources/pact.rb +4 -9
  24. data/lib/pact_broker/api/resources/pact_webhooks.rb +0 -1
  25. data/lib/pact_broker/api/resources/verifications.rb +4 -8
  26. data/lib/pact_broker/api/resources/webhook.rb +4 -8
  27. data/lib/pact_broker/api/resources/webhook_execution.rb +36 -17
  28. data/lib/pact_broker/api/resources/webhook_execution_methods.rb +13 -0
  29. data/lib/pact_broker/api/resources/webhook_resource_methods.rb +8 -15
  30. data/lib/pact_broker/api/resources/webhooks.rb +3 -12
  31. data/lib/pact_broker/api.rb +1 -1
  32. data/lib/pact_broker/app.rb +2 -0
  33. data/lib/pact_broker/domain/webhook.rb +29 -18
  34. data/lib/pact_broker/hash_refinements.rb +13 -0
  35. data/lib/pact_broker/locale/en.yml +16 -0
  36. data/lib/pact_broker/logging.rb +1 -1
  37. data/lib/pact_broker/pacts/diff.rb +0 -1
  38. data/lib/pact_broker/pacts/pact_version.rb +13 -7
  39. data/lib/pact_broker/pacts/repository.rb +4 -6
  40. data/lib/pact_broker/pacts/service.rb +3 -4
  41. data/lib/pact_broker/repositories/helpers.rb +1 -1
  42. data/lib/pact_broker/string_refinements.rb +13 -0
  43. data/lib/pact_broker/tags/repository.rb +0 -1
  44. data/lib/pact_broker/ui/views/index/_css_and_js.haml +1 -0
  45. data/lib/pact_broker/ui/views/index/show-with-tags.haml +8 -2
  46. data/lib/pact_broker/ui/views/matrix/show.haml +12 -2
  47. data/lib/pact_broker/verifications/repository.rb +0 -1
  48. data/lib/pact_broker/verifications/service.rb +7 -5
  49. data/lib/pact_broker/version.rb +1 -1
  50. data/lib/pact_broker/versions/parse_semantic_version.rb +0 -1
  51. data/lib/pact_broker/webhooks/execution.rb +0 -1
  52. data/lib/pact_broker/webhooks/execution_configuration.rb +45 -0
  53. data/lib/pact_broker/webhooks/job.rb +5 -8
  54. data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +39 -12
  55. data/lib/pact_broker/webhooks/redact_logs.rb +21 -4
  56. data/lib/pact_broker/webhooks/render.rb +11 -2
  57. data/lib/pact_broker/webhooks/repository.rb +11 -5
  58. data/lib/pact_broker/webhooks/service.rb +21 -27
  59. data/lib/pact_broker/webhooks/triggered_webhook.rb +0 -1
  60. data/lib/pact_broker/webhooks/webhook_request_logger.rb +13 -0
  61. data/lib/pact_broker/webhooks/webhook_request_template.rb +32 -18
  62. data/lib/rack/pact_broker/add_vary_header.rb +39 -0
  63. data/lib/rack/pact_broker/convert_file_extension_to_accept_header.rb +2 -0
  64. data/lib/webmachine/rack_adapter_monkey_patch.rb +0 -1
  65. data/public/javascripts/clipboard.js +73 -0
  66. data/public/javascripts/matrix.js +0 -2
  67. data/public/stylesheets/index.css +19 -0
  68. data/script/prod/clean-up.sql +11 -0
  69. data/script/query.rb +0 -1
  70. data/script/seed-matrix.rb +0 -1
  71. data/script/seed.rb +0 -1
  72. data/spec/features/delete_version_spec.rb +0 -1
  73. data/spec/features/execute_unsaved_webhook_spec.rb +56 -0
  74. data/spec/features/execute_webhook_spec.rb +2 -5
  75. data/spec/features/get_version_spec.rb +0 -1
  76. data/spec/lib/pact_broker/api/contracts/put_pact_params_contract_spec.rb +0 -1
  77. data/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb +0 -1
  78. data/spec/lib/pact_broker/api/decorators/relationships_csv_decorator_spec.rb +0 -2
  79. data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +0 -1
  80. data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +26 -9
  81. data/spec/lib/pact_broker/api/decorators/webhook_request_template_decorator_spec.rb +3 -1
  82. data/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb +3 -2
  83. data/spec/lib/pact_broker/api/resources/badge_spec.rb +0 -2
  84. data/spec/lib/pact_broker/api/resources/dashboard_spec.rb +0 -1
  85. data/spec/lib/pact_broker/api/resources/error_handler_spec.rb +3 -0
  86. data/spec/lib/pact_broker/api/resources/group_spec.rb +0 -1
  87. data/spec/lib/pact_broker/api/resources/pact_spec.rb +0 -2
  88. data/spec/lib/pact_broker/api/resources/pacticipant_spec.rb +0 -1
  89. data/spec/lib/pact_broker/api/resources/tag_spec.rb +0 -2
  90. data/spec/lib/pact_broker/api/resources/verifications_spec.rb +9 -7
  91. data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +13 -15
  92. data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +0 -1
  93. data/spec/lib/pact_broker/certificates/service_spec.rb +11 -5
  94. data/spec/lib/pact_broker/domain/group_spec.rb +0 -1
  95. data/spec/lib/pact_broker/domain/webhook_spec.rb +11 -4
  96. data/spec/lib/pact_broker/feature_toggle_spec.rb +0 -1
  97. data/spec/lib/pact_broker/groups/service_spec.rb +0 -1
  98. data/spec/lib/pact_broker/hash_refinements_spec.rb +15 -0
  99. data/spec/lib/pact_broker/matrix/repository_spec.rb +0 -2
  100. data/spec/lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names_spec.rb +0 -1
  101. data/spec/lib/pact_broker/pacts/pact_version_spec.rb +16 -0
  102. data/spec/lib/pact_broker/pacts/repository_spec.rb +11 -0
  103. data/spec/lib/pact_broker/pacts/service_spec.rb +12 -5
  104. data/spec/lib/pact_broker/relationships/groupify_spec.rb +0 -2
  105. data/spec/lib/pact_broker/tags/repository_spec.rb +0 -1
  106. data/spec/lib/pact_broker/verifications/service_spec.rb +10 -3
  107. data/spec/lib/pact_broker/versions/repository_spec.rb +0 -1
  108. data/spec/lib/pact_broker/webhooks/execution_configuration_spec.rb +18 -0
  109. data/spec/lib/pact_broker/webhooks/job_spec.rb +21 -24
  110. data/spec/lib/pact_broker/webhooks/redact_logs_spec.rb +16 -5
  111. data/spec/lib/pact_broker/webhooks/repository_spec.rb +16 -1
  112. data/spec/lib/pact_broker/webhooks/service_spec.rb +23 -64
  113. data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +108 -24
  114. data/spec/migrations/23_pact_versions_spec.rb +3 -1
  115. data/spec/spec_helper.rb +4 -2
  116. data/spec/support/database_cleaner.rb +0 -1
  117. metadata +19 -5
  118. data/spec/support/jobs.rb +0 -12
@@ -1,4 +1,5 @@
1
1
  require 'pact_broker/webhooks/job'
2
+ require 'pact_broker/webhooks/execution_configuration'
2
3
 
3
4
  module PactBroker
4
5
  module Webhooks
@@ -9,11 +10,15 @@ module PactBroker
9
10
  allow(PactBroker::Webhooks::Service).to receive(:update_triggered_webhook_status)
10
11
  allow(PactBroker::Webhooks::TriggeredWebhook).to receive(:find).and_return(triggered_webhook)
11
12
  allow(Job).to receive(:logger).and_return(logger)
13
+ allow(webhook_execution_configuration).to receive(:with_success_log_message).and_return(webhook_execution_configuration)
14
+ allow(webhook_execution_configuration).to receive(:with_failure_log_message).and_return(webhook_execution_configuration)
12
15
  end
13
16
 
14
17
  let(:base_url) { "http://broker" }
15
18
  let(:triggered_webhook) { instance_double("PactBroker::Webhooks::TriggeredWebhook", webhook_uuid: '1234', id: 1) }
16
- let(:result) { instance_double("PactBroker::Domain::WebhookExecutionResult", success?: success)}
19
+ let(:result) { instance_double("PactBroker::Domain::WebhookExecutionResult", success?: success) }
20
+ let(:webhook_execution_configuration) { instance_double(PactBroker::Webhooks::ExecutionConfiguration, to_hash: webhook_execution_configuration_hash) }
21
+ let(:webhook_execution_configuration_hash) { { the: 'options' } }
17
22
  let(:success) { true }
18
23
  let(:logger) { double('logger').as_null_object }
19
24
  let(:database_connector) { ->(&block) { block.call } }
@@ -22,8 +27,7 @@ module PactBroker
22
27
  {
23
28
  triggered_webhook: triggered_webhook,
24
29
  database_connector: database_connector,
25
- webhook_context: webhook_context,
26
- logging_options: { the: 'options' }
30
+ webhook_execution_configuration: webhook_execution_configuration
27
31
  }
28
32
  end
29
33
 
@@ -58,11 +62,7 @@ module PactBroker
58
62
  end
59
63
 
60
64
  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
- ))
65
+ expect(Job).to receive(:perform_in).with(10, hash_including(job_params))
66
66
  subject
67
67
  end
68
68
 
@@ -81,16 +81,16 @@ module PactBroker
81
81
  subject
82
82
  end
83
83
 
84
+ it "sets the success and failure messages" do
85
+ expect(webhook_execution_configuration).to receive(:with_success_log_message).with("Successfully executed webhook")
86
+ expect(webhook_execution_configuration).to receive(:with_failure_log_message).with("Retrying webhook in 10 seconds")
87
+ subject
88
+
89
+ end
90
+
84
91
  it "executes the job with an log message indicating that the webhook will be retried" do
85
92
  expect(PactBroker::Webhooks::Service).to receive(:execute_triggered_webhook_now)
86
- .with(triggered_webhook, {
87
- logging_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
93
- })
93
+ .with(triggered_webhook, webhook_execution_configuration_hash)
94
94
  subject
95
95
  end
96
96
 
@@ -122,21 +122,18 @@ module PactBroker
122
122
  end
123
123
 
124
124
  context "when the job is not successful for the last time" do
125
- let(:success) { false }
126
125
  before do
127
126
  job_params[:error_count] = 6
128
127
  end
129
128
 
130
- # subject { Job.new.perform(triggered_webhook: triggered_webhook, error_count: 6, database_connector: database_connector, base_url: base_url) }
129
+ let(:success) { false }
131
130
 
132
131
  it "executes the job with an log message indicating that the webhook has failed" do
132
+ expect(webhook_execution_configuration).to receive(:with_failure_log_message).with("Webhook execution failed after 7 attempts")
133
+ expect(webhook_execution_configuration).to receive(:with_success_log_message).with("Successfully executed webhook")
134
+
133
135
  expect(PactBroker::Webhooks::Service).to receive(:execute_triggered_webhook_now)
134
- .with(triggered_webhook, hash_including(
135
- logging_options: hash_including(
136
- failure_log_message: "Webhook execution failed after 7 attempts",
137
- success_log_message: "Successfully executed webhook")
138
- )
139
- )
136
+ .with(triggered_webhook, webhook_execution_configuration_hash)
140
137
  subject
141
138
  end
142
139
 
@@ -4,6 +4,8 @@ module PactBroker
4
4
  module Webhooks
5
5
  describe RedactLogs do
6
6
  describe ".call" do
7
+ let(:values) { [] }
8
+
7
9
  let(:string) do
8
10
  "Authorization: foo\nX-Thing: bar"
9
11
  end
@@ -25,23 +27,32 @@ module PactBroker
25
27
  end
26
28
 
27
29
  it "hides the value of the Authorization header" do
28
- expect(RedactLogs.call(string)).to eq "Authorization: [REDACTED]\nX-Thing: bar"
30
+ expect(RedactLogs.call(string, values)).to eq "Authorization: [REDACTED]\nX-Thing: bar"
29
31
  end
30
32
 
31
33
  it "hides the value of the X-Authorization header" do
32
- expect(RedactLogs.call(x_auth_string)).to eq "X-Authorization: [REDACTED]\nX-Thing: bar"
34
+ expect(RedactLogs.call(x_auth_string, values)).to eq "X-Authorization: [REDACTED]\nX-Thing: bar"
33
35
  end
34
36
 
35
37
  it "hides the value of the X-Auth-Token header" do
36
- expect(RedactLogs.call(x_auth_token)).to eq "X-Auth-Token: [REDACTED]\nX-Thing: bar"
38
+ expect(RedactLogs.call(x_auth_token, values)).to eq "X-Auth-Token: [REDACTED]\nX-Thing: bar"
37
39
  end
38
40
 
39
41
  it "hides the value of the X-Authorization-Token header" do
40
- expect(RedactLogs.call(x_authorization_token)).to eq "X-Authorization-Token: [REDACTED]\nX-Thing: bar"
42
+ expect(RedactLogs.call(x_authorization_token, values)).to eq "X-Authorization-Token: [REDACTED]\nX-Thing: bar"
41
43
  end
42
44
 
43
45
  it "hides the value of the authorization header" do
44
- expect(RedactLogs.call(string_lower)).to eq "authorization: [REDACTED]\nX-Thing: bar"
46
+ expect(RedactLogs.call(string_lower, values)).to eq "authorization: [REDACTED]\nX-Thing: bar"
47
+ end
48
+
49
+ context "with values" do
50
+ let(:values) { %w[foo bar] }
51
+ let(:string) { "blahfoo\nbar wiffle" }
52
+
53
+ it "hides the passed in values" do
54
+ expect(RedactLogs.call(string, values)).to eq "blah********\n******** wiffle"
55
+ end
45
56
  end
46
57
  end
47
58
  end
@@ -430,8 +430,9 @@ module PactBroker
430
430
 
431
431
  let(:webhook_domain) { Repository.new.find_by_uuid td.webhook.uuid }
432
432
  let(:webhook_execution_result) { instance_double("PactBroker::Domain::WebhookExecutionResult", success?: true, logs: "logs") }
433
+ let(:repository) { Repository.new }
433
434
 
434
- subject { Repository.new.create_execution td.triggered_webhook, webhook_execution_result }
435
+ subject { repository.create_execution td.triggered_webhook, webhook_execution_result }
435
436
 
436
437
  it "saves a new webhook execution " do
437
438
  expect { subject }.to change { Execution.count }.by(1)
@@ -444,6 +445,20 @@ module PactBroker
444
445
  it "sets the logs" do
445
446
  expect(subject.logs).to eq "logs"
446
447
  end
448
+
449
+ context "when the triggered webhook has been deleted in the meantime" do
450
+ before do
451
+ TriggeredWebhook.where(id: td.triggered_webhook.id).delete
452
+ allow(repository).to receive(:logger).and_return(logger)
453
+ end
454
+
455
+ let(:logger) { double('logger') }
456
+
457
+ it "just logs the error" do
458
+ expect(logger).to receive(:info).with(/triggered webhook with id #{td.triggered_webhook.id}/)
459
+ subject
460
+ end
461
+ end
447
462
  end
448
463
 
449
464
  describe "delete_triggered_webhooks_by_webhook_uuid" do
@@ -4,6 +4,7 @@ require 'pact_broker/webhooks/triggered_webhook'
4
4
  require 'pact_broker/webhooks/webhook_event'
5
5
  require 'webmock/rspec'
6
6
  require 'sucker_punch/testing/inline'
7
+ require 'pact_broker/webhooks/execution_configuration'
7
8
 
8
9
  module PactBroker
9
10
 
@@ -217,25 +218,19 @@ module PactBroker
217
218
  let(:verification) { instance_double(PactBroker::Domain::Verification) }
218
219
  let(:trigger_on_verification) { false }
219
220
  let(:result) { double('result') }
220
- let(:options) do
221
- {
222
- logging_options: {
223
- failure_log_message: "Webhook execution failed",
224
- show_response: 'foo',
225
- },
226
- webhook_context: {
227
- base_url: 'http://broker'
228
- }
229
- }
221
+ let(:execution_configuration) do
222
+ instance_double(PactBroker::Webhooks::ExecutionConfiguration, to_hash: execution_configuration_hash)
230
223
  end
224
+ let(:execution_configuration_hash) { { the: 'options' } }
231
225
 
232
226
  before do
233
227
  allow(PactBroker::Pacts::Service).to receive(:search_for_latest_pact).and_return(pact)
234
228
  allow(PactBroker::Verifications::Service).to receive(:search_for_latest).and_return(verification)
235
229
  allow(PactBroker.configuration).to receive(:show_webhook_response?).and_return('foo')
230
+ allow(execution_configuration).to receive(:with_failure_log_message).and_return(execution_configuration)
236
231
  end
237
232
 
238
- subject { Service.test_execution(webhook, options) }
233
+ subject { Service.test_execution(webhook, execution_configuration) }
239
234
 
240
235
  it "searches for the latest matching pact" do
241
236
  expect(PactBroker::Pacts::Service).to receive(:search_for_latest_pact).with(consumer_name: 'consumer', provider_name: 'provider')
@@ -248,7 +243,7 @@ module PactBroker
248
243
 
249
244
  context "when the trigger is not for a verification" do
250
245
  it "executes the webhook with the pact" do
251
- expect(webhook).to receive(:execute).with(pact, nil, options)
246
+ expect(webhook).to receive(:execute).with(pact, nil, execution_configuration_hash)
252
247
  subject
253
248
  end
254
249
  end
@@ -271,7 +266,7 @@ module PactBroker
271
266
  end
272
267
 
273
268
  it "executes the webhook with the pact and the verification" do
274
- expect(webhook).to receive(:execute).with(pact, verification, options)
269
+ expect(webhook).to receive(:execute).with(pact, verification, execution_configuration_hash)
275
270
  subject
276
271
  end
277
272
 
@@ -286,55 +281,6 @@ module PactBroker
286
281
  end
287
282
  end
288
283
 
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
337
-
338
284
  describe ".trigger_webhooks integration test", job: true do
339
285
  let!(:http_request) do
340
286
  stub_request(:get, "http://example.org").
@@ -342,11 +288,15 @@ module PactBroker
342
288
  end
343
289
 
344
290
  let(:events) { [{ name: PactBroker::Webhooks::WebhookEvent::DEFAULT_EVENT_NAME }] }
291
+ let(:webhook_execution_configuration) do
292
+ PactBroker::Webhooks::ExecutionConfiguration.new
293
+ .with_webhook_context(base_url: 'http://example.org')
294
+ .with_show_response(true)
295
+ end
345
296
  let(:options) do
346
297
  {
347
298
  database_connector: database_connector,
348
- webhook_context: { base_url: 'http://example.org' },
349
- logging_options: logging_options
299
+ webhook_execution_configuration: webhook_execution_configuration
350
300
  }
351
301
  end
352
302
  let(:logging_options) { { show_response: true } }
@@ -386,6 +336,15 @@ module PactBroker
386
336
  expect(TriggeredWebhook.first.status).to eq TriggeredWebhook::STATUS_SUCCESS
387
337
  end
388
338
  end
339
+
340
+ describe "parameters" do
341
+ subject { Service.parameters }
342
+
343
+ it "returns a list of parameters and their descriptions" do
344
+ expect(subject.first.name).to start_with "pactbroker.consumerName"
345
+ expect(subject.first.description).to eq "the consumer name"
346
+ end
347
+ end
389
348
  end
390
349
  end
391
350
  end
@@ -7,11 +7,11 @@ module PactBroker
7
7
  {
8
8
  method: 'POST',
9
9
  url: url,
10
- username: "foo",
11
- password: "bar",
10
+ username: "username",
11
+ password: password,
12
12
  uuid: "1234",
13
13
  body: body,
14
- headers: {'Foo' => 'bar'}
14
+ headers: headers
15
15
  }
16
16
  end
17
17
 
@@ -19,14 +19,16 @@ module PactBroker
19
19
  {
20
20
  method: 'POST',
21
21
  url: built_url,
22
- username: "foo",
23
- password: "bar",
22
+ username: "usernameBUILT",
23
+ password: "passwordBUILT",
24
24
  uuid: "1234",
25
25
  body: built_body,
26
- headers: {'Foo' => 'bar'}
26
+ headers: {'headername' => 'headervalueBUILT'}
27
27
  }
28
28
  end
29
29
 
30
+ let(:password) { "password" }
31
+ let(:headers) { {'headername' => 'headervalue'} }
30
32
  let(:url) { "http://example.org/hook?foo=bar" }
31
33
  let(:base_url) { "http://broker" }
32
34
  let(:built_url) { "http://example.org/hook?foo=barBUILT" }
@@ -38,28 +40,11 @@ module PactBroker
38
40
  allow(PactBroker::Webhooks::Render).to receive(:call) do | content, pact, verification, &block |
39
41
  content + "BUILT"
40
42
  end
41
-
42
- allow(PactAndVerificationParameters).to receive(:new).and_return(pact_and_verification_parameters)
43
43
  end
44
44
 
45
- let(:pact_and_verification_parameters) { instance_double(PactAndVerificationParameters, to_hash: params_hash)}
46
45
  let(:params_hash) { double('params hash') }
47
- let(:pact) { double('pact') }
48
- let(:verification) { double('verification') }
49
- let(:webhook_context) { { some: "context", base_url: base_url } }
50
- let(:template_context) do
51
- {
52
- pact: pact,
53
- verification: verification,
54
- webhook_context: webhook_context
55
- }
56
- end
57
- subject { WebhookRequestTemplate.new(attributes).build(template_context) }
58
46
 
59
- it "creates the template parameters" do
60
- expect(PactAndVerificationParameters).to receive(:new).with(pact, verification, webhook_context)
61
- subject
62
- end
47
+ subject { WebhookRequestTemplate.new(attributes).build(params_hash) }
63
48
 
64
49
  it "renders the url template" do
65
50
  expect(PactBroker::Webhooks::Render).to receive(:call).with(url, params_hash) do | content, pact, verification, &block |
@@ -90,10 +75,109 @@ module PactBroker
90
75
  end
91
76
  end
92
77
 
78
+ it "renders each header value" do
79
+ expect(PactBroker::Webhooks::Render).to receive(:call).with('headervalue', params_hash)
80
+ subject
81
+ end
82
+
83
+ it "renders the username" do
84
+ expect(PactBroker::Webhooks::Render).to receive(:call).with('username', params_hash)
85
+ subject
86
+ end
87
+
88
+ it "renders the password" do
89
+ expect(PactBroker::Webhooks::Render).to receive(:call).with('password', params_hash)
90
+ subject
91
+ end
92
+
93
93
  it "creates a new PactBroker::Domain::WebhookRequest" do
94
94
  expect(PactBroker::Domain::WebhookRequest).to receive(:new).with(new_attributes)
95
95
  subject
96
96
  end
97
+
98
+ context "when optional attributes are missing" do
99
+ let(:attributes) do
100
+ {
101
+ method: 'POST',
102
+ url: url,
103
+ uuid: "1234",
104
+ }
105
+ end
106
+
107
+ it "does not blow up" do
108
+ subject
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "redacted_headers" do
114
+ subject { WebhookRequestTemplate.new(attributes) }
115
+
116
+ let(:headers) do
117
+ {
118
+ 'Authorization' => 'foo',
119
+ 'X-authorization' => 'bar',
120
+ 'Token' => 'bar',
121
+ 'X-Auth-Token' => 'bar',
122
+ 'X-Authorization-Token' => 'bar',
123
+ 'OK' => 'ok'
124
+ }
125
+ end
126
+
127
+ let(:expected_headers) do
128
+ {
129
+ 'Authorization' => '**********',
130
+ 'X-authorization' => '**********',
131
+ 'Token' => '**********',
132
+ 'X-Auth-Token' => '**********',
133
+ 'X-Authorization-Token' => '**********',
134
+ 'OK' => 'ok'
135
+ }
136
+ end
137
+
138
+ it "redacts sensitive headers" do
139
+ expect(subject.redacted_headers).to eq expected_headers
140
+ end
141
+
142
+ context "when there is a parameter in the value" do
143
+ let(:headers) do
144
+ {
145
+ 'Authorization' => '${pactbroker.secret}'
146
+ }
147
+ end
148
+
149
+ let(:expected_headers) do
150
+ {
151
+ 'Authorization' => '${pactbroker.secret}'
152
+ }
153
+ end
154
+
155
+ it "does not redact it" do
156
+ expect(subject.redacted_headers).to eq expected_headers
157
+ end
158
+ end
159
+ end
160
+
161
+ describe "display_password" do
162
+ subject { WebhookRequestTemplate.new(attributes) }
163
+
164
+ context "when it is nil" do
165
+ let(:password) { nil }
166
+
167
+ its(:display_password) { is_expected.to be nil }
168
+ end
169
+
170
+ context "when the password contains a parameter" do
171
+ let(:password) { "${pactbroker.foo}" }
172
+
173
+ its(:display_password) { is_expected.to eq password }
174
+ end
175
+
176
+ context "when the password does not contains a parameter" do
177
+ let(:password) { "foo" }
178
+
179
+ its(:display_password) { is_expected.to eq "**********" }
180
+ end
97
181
  end
98
182
  end
99
183
  end
@@ -1,3 +1,5 @@
1
+ require 'pact_broker/webhooks/execution_configuration'
2
+
1
3
  describe 'migrate to pact versions (migrate 22-31)', migration: true do
2
4
  before do
3
5
  PactBroker::Database.migrate(22)
@@ -13,7 +15,6 @@ describe 'migrate to pact versions (migrate 22-31)', migration: true do
13
15
  let!(:pact_1) { create(:pacts, {version_id: consumer_version_1[:id], provider_id: provider[:id], pact_version_content_sha: '1234', created_at: now, updated_at: pact_updated_at}) }
14
16
  let!(:pact_2) { create(:pacts, {version_id: consumer_version_2[:id], provider_id: provider[:id], pact_version_content_sha: '1234', created_at: now, updated_at: pact_updated_at}) }
15
17
 
16
-
17
18
  subject { PactBroker::Database.migrate }
18
19
 
19
20
  it "keeps the same number of pacts" do
@@ -71,6 +72,7 @@ describe 'migrate to pact versions (migrate 22-31)', migration: true do
71
72
  consumer_version_number: '1.2.3',
72
73
  json_content: load_fixture('a_consumer-a_provider.json')
73
74
  },{
75
+ webhook_execution_configuration: PactBroker::Webhooks::ExecutionConfiguration.new
74
76
  }
75
77
  )
76
78
  end
data/spec/spec_helper.rb CHANGED
@@ -52,5 +52,7 @@ RSpec.configure do | config |
52
52
  end
53
53
  end
54
54
 
55
- # SemanticLogger.add_appender(io: $stdout)
56
- # SemanticLogger.default_level = :info
55
+ if ENV["DEBUG"] == "true"
56
+ SemanticLogger.add_appender(io: $stdout)
57
+ SemanticLogger.default_level = :info
58
+ end
@@ -20,7 +20,6 @@ RSpec.configure do |config|
20
20
  PactBroker::Database.drop_objects
21
21
  end
22
22
 
23
-
24
23
  config.after :each, migration: true do
25
24
  PactBroker::Database.migrate
26
25
  PactBroker::Database.truncate