pact_broker 2.81.0 → 2.82.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/CHANGELOG.md +30 -0
- data/DEVELOPER_SETUP.md +1 -1
- data/README.md +7 -5
- data/config.ru +3 -28
- data/db/migrations/20210722_add_index_to_triggered_webhooks_webhook_uuid.rb +7 -0
- data/db/migrations/20210810_set_allow_contract_modification.rb +17 -0
- data/docs/CONFIGURATION.md +398 -0
- data/docs/configuration.yml +320 -0
- data/example/Gemfile +4 -4
- data/example/README.md +15 -22
- data/example/config.ru +1 -24
- data/example/config/pact_broker.yml +9 -0
- data/example/config/puma.rb +3 -0
- data/lib/db.rb +1 -1
- data/lib/pact_broker/api/authorization/resource_access_policy.rb +68 -0
- data/lib/pact_broker/api/authorization/resource_access_rules.rb +40 -0
- data/lib/pact_broker/api/decorators/deployed_version_decorator.rb +2 -0
- data/lib/pact_broker/api/decorators/released_version_decorator.rb +2 -0
- data/lib/pact_broker/api/middleware/basic_auth.rb +63 -0
- data/lib/pact_broker/api/resources/pact.rb +15 -6
- data/lib/pact_broker/api/resources/tag.rb +1 -14
- data/lib/pact_broker/app.rb +52 -30
- data/lib/pact_broker/config/basic_auth_configuration.rb +38 -0
- data/lib/pact_broker/config/load.rb +21 -10
- data/lib/pact_broker/config/runtime_configuration.rb +188 -0
- data/lib/pact_broker/config/runtime_configuration_coercion_methods.rb +41 -0
- data/lib/pact_broker/config/runtime_configuration_database_methods.rb +119 -0
- data/lib/pact_broker/config/runtime_configuration_logging_methods.rb +61 -0
- data/lib/pact_broker/configuration.rb +67 -131
- data/lib/pact_broker/contracts/notice.rb +4 -0
- data/lib/pact_broker/contracts/service.rb +4 -4
- data/lib/pact_broker/db/models.rb +3 -0
- data/lib/pact_broker/db/validate_encoding.rb +0 -4
- data/lib/pact_broker/deployments/deployed_version.rb +8 -2
- data/lib/pact_broker/deployments/deployed_version_service.rb +13 -6
- data/lib/pact_broker/deployments/environment.rb +1 -1
- data/lib/pact_broker/deployments/released_version.rb +8 -0
- data/lib/pact_broker/deployments/released_version_service.rb +12 -0
- data/lib/pact_broker/doc/views/provider-pacts-for-verification.markdown +4 -0
- data/lib/pact_broker/domain/pacticipant.rb +17 -13
- data/lib/pact_broker/domain/verification.rb +4 -22
- data/lib/pact_broker/domain/version.rb +9 -5
- data/lib/pact_broker/domain/webhook.rb +4 -0
- data/lib/pact_broker/error.rb +1 -0
- data/lib/pact_broker/errors.rb +1 -1
- data/lib/pact_broker/feature_toggle.rb +3 -5
- data/lib/pact_broker/hash_refinements.rb +0 -1
- data/lib/pact_broker/index/service.rb +4 -6
- data/lib/pact_broker/initializers/database_connection.rb +80 -0
- data/lib/pact_broker/integrations/integration.rb +5 -0
- data/lib/pact_broker/integrations/service.rb +4 -2
- data/lib/pact_broker/locale/en.yml +1 -0
- data/lib/pact_broker/logging.rb +2 -1
- data/lib/pact_broker/matrix/integration.rb +1 -1
- data/lib/pact_broker/matrix/parse_can_i_deploy_query.rb +2 -2
- data/lib/pact_broker/matrix/quick_row.rb +10 -0
- data/lib/pact_broker/matrix/repository.rb +64 -3
- data/lib/pact_broker/metrics/service.rb +16 -13
- data/lib/pact_broker/pacticipants/repository.rb +4 -0
- data/lib/pact_broker/pacticipants/service.rb +9 -1
- data/lib/pact_broker/pacts/pact_publication.rb +10 -13
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +6 -1
- data/lib/pact_broker/pacts/pact_publication_selector_dataset_module.rb +1 -2
- data/lib/pact_broker/pacts/pact_version.rb +25 -11
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +54 -77
- data/lib/pact_broker/pacts/selected_pact.rb +1 -1
- data/lib/pact_broker/pacts/selector.rb +15 -2
- data/lib/pact_broker/pacts/selectors.rb +4 -0
- data/lib/pact_broker/pacts/service.rb +4 -0
- data/lib/pact_broker/repositories/scopes.rb +12 -1
- data/lib/pact_broker/string_refinements.rb +6 -0
- data/lib/pact_broker/tags/service.rb +8 -1
- data/lib/pact_broker/test/http_test_data_builder.rb +11 -5
- data/lib/pact_broker/ui/views/index/_css_and_js.haml +11 -9
- data/lib/pact_broker/ui/views/index/_pagination.haml +3 -1
- data/lib/pact_broker/ui/views/layouts/main.haml +5 -3
- data/lib/pact_broker/ui/views/matrix/show.haml +10 -8
- data/lib/pact_broker/verifications/required_verification.rb +28 -0
- data/lib/pact_broker/verifications/service.rb +49 -1
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/repository.rb +15 -0
- data/lib/pact_broker/versions/service.rb +32 -2
- data/lib/pact_broker/webhooks/event_listener.rb +3 -0
- data/lib/pact_broker/webhooks/trigger_service.rb +30 -14
- data/lib/pact_broker/webhooks/triggered_webhook.rb +1 -0
- data/lib/pact_broker/webhooks/webhook.rb +2 -2
- data/lib/pact_broker/webhooks/webhook_event.rb +6 -1
- data/lib/semantic_logger/formatters/short.rb +29 -0
- data/pact_broker.gemspec +1 -0
- data/script/data/auto-create-things-for-tags.rb +19 -0
- data/script/data/contract-published-requiring-verification.rb +27 -0
- data/script/{reproduce-issue-expand-currently-deployed.rb → data/expand-currently-deployed.rb} +0 -0
- data/script/docs/generate-configuration-docs.rb +86 -0
- data/spec/features/get_latest_pact_badge_spec.rb +1 -0
- data/spec/features/get_matrix_badge_spec.rb +1 -0
- data/spec/features/publish_pact_spec.rb +21 -7
- data/spec/features/wip_pacts_spec.rb +1 -1
- data/spec/fixtures/approvals/matrix_integration_environment_spec.approved.json +62 -0
- data/spec/fixtures/approvals/matrix_integration_ignore_spec.approved.json +124 -0
- data/spec/fixtures/approvals/matrix_integration_spec.approved.json +173 -0
- data/spec/fixtures/approvals/publish_contract_no_branch.approved.json +9 -9
- data/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json +7 -7
- data/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json +5 -5
- data/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json +5 -5
- data/spec/lib/pact_broker/api/middleware/basic_auth_spec.rb +312 -0
- data/spec/lib/pact_broker/api/resources/tag_spec.rb +14 -39
- data/spec/lib/pact_broker/app_basic_auth_spec.rb +122 -0
- data/spec/lib/pact_broker/config/load_spec.rb +33 -6
- data/spec/lib/pact_broker/config/runtime_configuration_logging_methods_spec.rb +22 -0
- data/spec/lib/pact_broker/config/runtime_configuration_spec.rb +71 -0
- data/spec/lib/pact_broker/configuration_spec.rb +51 -25
- data/spec/lib/pact_broker/errors/error_logger_spec.rb +3 -0
- data/spec/lib/pact_broker/feature_toggle_spec.rb +18 -19
- data/spec/lib/pact_broker/matrix/integration_environment_spec.rb +12 -0
- data/spec/lib/pact_broker/matrix/integration_ignore_spec.rb +15 -3
- data/spec/lib/pact_broker/matrix/integration_spec.rb +47 -6
- data/spec/lib/pact_broker/matrix/parse_can_i_deploy_query_spec.rb +16 -1
- data/spec/lib/pact_broker/matrix/repository_dependency_spec.rb +0 -2
- data/spec/lib/pact_broker/matrix/repository_spec.rb +0 -2
- data/spec/lib/pact_broker/metrics/service_spec.rb +44 -0
- data/spec/lib/pact_broker/pacticipants/service_spec.rb +28 -5
- data/spec/lib/pact_broker/pacts/pact_publication_selector_dataset_module_spec.rb +25 -0
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +30 -1
- data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +107 -20
- data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +1 -1
- data/spec/lib/pact_broker/tags/service_spec.rb +24 -8
- data/spec/lib/pact_broker/verifications/service_spec.rb +146 -0
- data/spec/lib/pact_broker/versions/repository_spec.rb +38 -2
- data/spec/lib/pact_broker/versions/service_spec.rb +93 -2
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +54 -2
- data/spec/lib/rack/pact_broker/invalid_uri_protection_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -1
- data/spec/support/approvals.rb +29 -0
- metadata +52 -13
- data/example/basic_auth/Gemfile +0 -5
- data/example/basic_auth/Procfile +0 -1
- data/example/basic_auth/README.md +0 -43
- data/example/basic_auth/config.ru +0 -19
- data/example/example_data.sql +0 -19
- data/spec/lib/pact_broker/config/save_and_load_spec.rb +0 -25
- data/spec/lib/pact_broker/pacts/service_find_for_verification_spec.rb +0 -50
@@ -80,6 +80,152 @@ module PactBroker
|
|
80
80
|
|
81
81
|
end
|
82
82
|
|
83
|
+
describe "#calculate_required_verifications_for_pact" do
|
84
|
+
subject { Service.calculate_required_verifications_for_pact(pact) }
|
85
|
+
|
86
|
+
context "when there is no verification from the latest version from the main branch" do
|
87
|
+
let!(:pact) do
|
88
|
+
td.create_consumer("Foo")
|
89
|
+
.create_provider("Bar", main_branch: "main")
|
90
|
+
.create_provider_version("1", branch: "main")
|
91
|
+
.create_consumer_version("1")
|
92
|
+
.create_pact
|
93
|
+
.and_return(:pact)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns the required verification for the main branch" do
|
97
|
+
expect(subject).to eq [
|
98
|
+
RequiredVerification.new(
|
99
|
+
provider_version: td.find_version("Bar", "1"),
|
100
|
+
provider_version_descriptions: ["latest version from main branch"]
|
101
|
+
)
|
102
|
+
]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "when there is a verification from the latest version from the main branch" do
|
107
|
+
let!(:pact) do
|
108
|
+
td.create_consumer("Foo")
|
109
|
+
.create_provider("Bar", main_branch: "main")
|
110
|
+
.create_provider_version("1", branch: "main")
|
111
|
+
.create_consumer_version("1")
|
112
|
+
.create_pact
|
113
|
+
.create_verification(provider_version: "2", branch: "main")
|
114
|
+
.and_return(:pact)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "does not return a required verification" do
|
118
|
+
expect(subject).to eq []
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when there is no verification for a deployed version" do
|
123
|
+
let!(:pact) do
|
124
|
+
td.create_environment("test")
|
125
|
+
.create_consumer("Foo")
|
126
|
+
.create_provider("Bar")
|
127
|
+
.create_provider_version("1")
|
128
|
+
.create_consumer_version("1")
|
129
|
+
.create_pact
|
130
|
+
.create_deployed_version_for_provider_version
|
131
|
+
.and_return(:pact)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "returns the required verification for the deployed version" do
|
135
|
+
expect(subject).to eq [
|
136
|
+
RequiredVerification.new(
|
137
|
+
provider_version: td.find_version("Bar", "1"),
|
138
|
+
provider_version_descriptions: ["currently deployed version (test)"]
|
139
|
+
)
|
140
|
+
]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "when there is a verification for a deployed version" do
|
145
|
+
let!(:pact) do
|
146
|
+
td.create_environment("test")
|
147
|
+
.create_consumer("Foo")
|
148
|
+
.create_provider("Bar")
|
149
|
+
.create_provider_version("1")
|
150
|
+
.create_consumer_version("1")
|
151
|
+
.create_pact
|
152
|
+
.create_verification(provider_version: "1")
|
153
|
+
.create_deployed_version_for_provider_version
|
154
|
+
.and_return(:pact)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "does not return a required verification for the deployed version" do
|
158
|
+
expect(subject).to eq []
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "when there is no verification for a released version" do
|
163
|
+
let!(:pact) do
|
164
|
+
td.create_environment("test")
|
165
|
+
.create_consumer("Foo")
|
166
|
+
.create_provider("Bar")
|
167
|
+
.create_provider_version("1")
|
168
|
+
.create_consumer_version("1")
|
169
|
+
.create_pact
|
170
|
+
.create_released_version_for_provider_version
|
171
|
+
.and_return(:pact)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "returns the required verification for the released version" do
|
175
|
+
expect(subject).to eq [
|
176
|
+
RequiredVerification.new(
|
177
|
+
provider_version: td.find_version("Bar", "1"),
|
178
|
+
provider_version_descriptions: ["currently released version (test)"]
|
179
|
+
)
|
180
|
+
]
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when there is a verification for a released version" do
|
185
|
+
let!(:pact) do
|
186
|
+
td.create_environment("test")
|
187
|
+
.create_consumer("Foo")
|
188
|
+
.create_provider("Bar")
|
189
|
+
.create_provider_version("1")
|
190
|
+
.create_consumer_version("1")
|
191
|
+
.create_pact
|
192
|
+
.create_verification(provider_version: "1")
|
193
|
+
.create_released_version_for_provider_version
|
194
|
+
.and_return(:pact)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "does not return a required verification for the deployed version" do
|
198
|
+
expect(subject).to eq []
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "when the latest version from the main branch is deployed and released and has no verification" do
|
203
|
+
let!(:pact) do
|
204
|
+
td.create_environment("test")
|
205
|
+
.create_consumer("Foo")
|
206
|
+
.create_provider("Bar", main_branch: "main")
|
207
|
+
.create_provider_version("1", branch: "main")
|
208
|
+
.create_consumer_version("1")
|
209
|
+
.create_pact
|
210
|
+
.create_deployed_version_for_provider_version
|
211
|
+
.create_released_version_for_provider_version
|
212
|
+
.and_return(:pact)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "deduplicates the required versions" do
|
216
|
+
expect(subject).to eq [
|
217
|
+
RequiredVerification.new(
|
218
|
+
provider_version: td.find_version("Bar", "1"),
|
219
|
+
provider_version_descriptions: [
|
220
|
+
"latest version from main branch",
|
221
|
+
"currently deployed version (test)",
|
222
|
+
"currently released version (test)"
|
223
|
+
])
|
224
|
+
]
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
83
229
|
describe "#errors" do
|
84
230
|
let(:params) { {} }
|
85
231
|
|
@@ -4,8 +4,6 @@ require "pact_broker/versions/repository"
|
|
4
4
|
module PactBroker
|
5
5
|
module Versions
|
6
6
|
describe Repository do
|
7
|
-
|
8
|
-
let(:td) { TestDataBuilder.new }
|
9
7
|
let(:pacticipant_name) { "test_pacticipant" }
|
10
8
|
let(:version_number) { "1.2.3" }
|
11
9
|
|
@@ -176,6 +174,44 @@ module PactBroker
|
|
176
174
|
end
|
177
175
|
end
|
178
176
|
end
|
177
|
+
|
178
|
+
describe "#find_latest_version_from_main_branch" do
|
179
|
+
subject { Repository.new.find_latest_version_from_main_branch(td.find_pacticipant("Foo")) }
|
180
|
+
|
181
|
+
context "when there is a version with the provider's configured main branch as the branch" do
|
182
|
+
before do
|
183
|
+
td.create_consumer("Foo", main_branch: "main")
|
184
|
+
.create_consumer_version("1", branch: "main")
|
185
|
+
.create_consumer_version("2", branch: "main")
|
186
|
+
.create_consumer_version("3", tag_name: "main")
|
187
|
+
.create_consumer_version("4", branch: "not-main")
|
188
|
+
end
|
189
|
+
|
190
|
+
its(:number) { is_expected.to eq "2" }
|
191
|
+
end
|
192
|
+
|
193
|
+
context "when there is a version with the provider's configured main branch as the tag" do
|
194
|
+
before do
|
195
|
+
td.create_consumer("Foo", main_branch: "main")
|
196
|
+
.create_consumer_version("1", branch: "not-main")
|
197
|
+
.create_consumer_version("2", branch: "not-main")
|
198
|
+
.create_consumer_version("3", tag_name: "main")
|
199
|
+
.create_consumer_version("4", branch: "not-main")
|
200
|
+
end
|
201
|
+
|
202
|
+
its(:number) { is_expected.to eq "3" }
|
203
|
+
end
|
204
|
+
|
205
|
+
context "when there are no versions with a matching branch or tag set" do
|
206
|
+
before do
|
207
|
+
td.create_consumer("Foo", main_branch: "main")
|
208
|
+
.create_consumer_version("1", branch: "not-main")
|
209
|
+
.create_consumer_version("2", tag_name: "not-main")
|
210
|
+
end
|
211
|
+
|
212
|
+
it { is_expected.to be_nil }
|
213
|
+
end
|
214
|
+
end
|
179
215
|
end
|
180
216
|
end
|
181
217
|
end
|
@@ -1,11 +1,102 @@
|
|
1
1
|
require "pact_broker/versions/service"
|
2
2
|
|
3
3
|
module PactBroker
|
4
|
-
|
5
4
|
module Versions
|
6
5
|
describe Service do
|
6
|
+
describe ".maybe_set_version_branch_from_tag" do
|
7
|
+
before do
|
8
|
+
allow(PactBroker.configuration).to receive(:use_first_tag_as_branch).and_return(use_first_tag_as_branch)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:pacticipant_name) { "test_pacticipant" }
|
12
|
+
let(:version_number) { "1.2.3" }
|
13
|
+
let(:tag_name) { "prod" }
|
14
|
+
|
15
|
+
subject { Service.maybe_set_version_branch_from_tag(td.find_version(pacticipant_name, version_number), tag_name) }
|
16
|
+
|
17
|
+
context "when use_first_tag_as_branch is true" do
|
18
|
+
let(:use_first_tag_as_branch) { true }
|
19
|
+
|
20
|
+
context "when there is already a tag" do
|
21
|
+
before do
|
22
|
+
td.create_consumer(pacticipant_name)
|
23
|
+
.create_consumer_version(version_number, tag_name: "foo")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "does not set the branch" do
|
27
|
+
subject
|
28
|
+
expect(td.find_version(pacticipant_name, version_number).branch).to be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when the branch is already set" do
|
33
|
+
before do
|
34
|
+
td.create_consumer(pacticipant_name)
|
35
|
+
.create_consumer_version(version_number, branch: "foo")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "does not update the branch" do
|
39
|
+
subject
|
40
|
+
expect(td.find_version(pacticipant_name, version_number).branch).to eq "foo"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when use_first_tag_as_branch is false" do
|
45
|
+
before do
|
46
|
+
td.create_consumer(pacticipant_name)
|
47
|
+
.create_consumer_version(version_number)
|
48
|
+
end
|
49
|
+
|
50
|
+
let(:use_first_tag_as_branch) { false }
|
51
|
+
|
52
|
+
it "does not set the branch" do
|
53
|
+
subject
|
54
|
+
expect(td.find_version(pacticipant_name, version_number).branch).to be_nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the version was outside of the time difference limit" do
|
59
|
+
before do
|
60
|
+
version = td.create_consumer(pacticipant_name)
|
61
|
+
.create_consumer_version(version_number)
|
62
|
+
.and_return(:consumer_version)
|
63
|
+
|
64
|
+
version.update(created_at: created_at)
|
65
|
+
allow(PactBroker.configuration).to receive(:use_first_tag_as_branch_time_limit).and_return(10)
|
66
|
+
allow(Time).to receive(:now).and_return(td.in_utc { Time.new(2021, 1, 2, 10, 10, 11) } )
|
67
|
+
end
|
68
|
+
|
69
|
+
let(:created_at) { td.in_utc { Time.new(2021, 1, 2, 10, 10, 0) }.to_datetime }
|
70
|
+
let(:one_second) { 1/(24 * 60 * 60) }
|
71
|
+
|
72
|
+
it "does not set the branch" do
|
73
|
+
subject
|
74
|
+
expect(td.find_version(pacticipant_name, version_number).branch).to be_nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when the version was created within the limit" do
|
79
|
+
before do
|
80
|
+
version = td.create_consumer(pacticipant_name)
|
81
|
+
.create_consumer_version(version_number)
|
82
|
+
.and_return(:consumer_version)
|
83
|
+
|
84
|
+
version.update(created_at: created_at)
|
85
|
+
allow(PactBroker.configuration).to receive(:use_first_tag_as_branch_time_limit).and_return(10)
|
86
|
+
allow(Time).to receive(:now).and_return(td.in_utc { Time.new(2021, 1, 2, 10, 10, 10) } )
|
87
|
+
end
|
88
|
+
|
89
|
+
let(:created_at) { td.in_utc { Time.new(2021, 1, 2, 10, 10, 0) }.to_datetime }
|
90
|
+
let(:one_second) { 1/(24 * 60 * 60) }
|
91
|
+
|
92
|
+
it "sets the branch" do
|
93
|
+
subject
|
94
|
+
expect(td.find_version(pacticipant_name, version_number).branch).to eq "prod"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
7
99
|
describe ".delete" do
|
8
|
-
let(:td) { TestDataBuilder.new }
|
9
100
|
let!(:version) do
|
10
101
|
td
|
11
102
|
.create_consumer
|
@@ -62,13 +62,18 @@ module PactBroker
|
|
62
62
|
let(:provider) { PactBroker::Domain::Pacticipant.new(name: "Provider") }
|
63
63
|
let(:webhooks) { [webhook]}
|
64
64
|
let(:webhook) do
|
65
|
-
instance_double(PactBroker::Domain::Webhook,
|
65
|
+
instance_double(PactBroker::Domain::Webhook,
|
66
|
+
description: "description",
|
67
|
+
uuid: "1244",
|
68
|
+
expand_currently_deployed_provider_versions?: expand_currently_deployed
|
69
|
+
)
|
66
70
|
end
|
67
71
|
let(:expand_currently_deployed) { false }
|
72
|
+
let(:trigger_on_contract_requiring_verification_published) { false }
|
68
73
|
let(:triggered_webhook) { instance_double(PactBroker::Webhooks::TriggeredWebhook) }
|
69
74
|
let(:event_name) { PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED }
|
70
75
|
let(:event_context) { { some: "data" } }
|
71
|
-
let(:expected_event_context) { { some: "data", event_name:
|
76
|
+
let(:expected_event_context) { { some: "data", event_name: event_name } }
|
72
77
|
let(:webhook_repository) { instance_double(Repository, create_triggered_webhook: triggered_webhook, find_webhooks_to_trigger: webhooks) }
|
73
78
|
|
74
79
|
subject { TriggerService.create_triggered_webhooks_for_event(pact, verification, event_name, event_context) }
|
@@ -111,6 +116,53 @@ module PactBroker
|
|
111
116
|
end
|
112
117
|
end
|
113
118
|
|
119
|
+
context "when the event is contract_requiring_verification_published" do
|
120
|
+
before do
|
121
|
+
allow(TriggerService).to receive(:verification_service).and_return(verification_service)
|
122
|
+
allow(verification_service).to receive(:calculate_required_verifications_for_pact).and_return(required_verifications)
|
123
|
+
end
|
124
|
+
|
125
|
+
let(:event_name) { PactBroker::Webhooks::WebhookEvent::CONTRACT_REQUIRING_VERIFICATION_PUBLISHED }
|
126
|
+
let(:verification_service) { class_double("PactBroker::Verifications::Service").as_stubbed_const }
|
127
|
+
let(:required_verifications) { [required_verification] }
|
128
|
+
let(:required_verification) do
|
129
|
+
instance_double("PactBroker::Verifications::RequiredVerification",
|
130
|
+
provider_version: double("version", number: "1"),
|
131
|
+
provider_version_descriptions: ["foo"]
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "creates a triggered webhook for each required verification" do
|
136
|
+
expect(webhook_repository).to receive(:create_triggered_webhook).with(
|
137
|
+
anything,
|
138
|
+
webhook,
|
139
|
+
pact,
|
140
|
+
verification,
|
141
|
+
TriggerService::RESOURCE_CREATION,
|
142
|
+
PactBroker::Webhooks::WebhookEvent::CONTRACT_REQUIRING_VERIFICATION_PUBLISHED,
|
143
|
+
expected_event_context.merge(provider_version_number: "1", provider_version_descriptions: ["foo"])
|
144
|
+
)
|
145
|
+
subject
|
146
|
+
end
|
147
|
+
|
148
|
+
it "returns the triggered webhooks" do
|
149
|
+
expect(subject.size).to eq 1
|
150
|
+
end
|
151
|
+
|
152
|
+
context "when there are no required verifications" do
|
153
|
+
let(:required_verifications) { [] }
|
154
|
+
|
155
|
+
it "does not create any triggered webhooks" do
|
156
|
+
expect(webhook_repository).to_not receive(:create_triggered_webhook)
|
157
|
+
subject
|
158
|
+
end
|
159
|
+
|
160
|
+
it "returns an empty array" do
|
161
|
+
expect(subject).to eq []
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
114
166
|
context "when there should be a webhook triggered for each consumer version that had a pact verified" do
|
115
167
|
# let(:triggered_webhooks) { [instance_double(TriggeredWebhook, event_context: { some: 'context'}, webhook: instance_double(Webhook, uuid: "webhook-uuid"))]}
|
116
168
|
|
@@ -5,7 +5,7 @@ module Rack
|
|
5
5
|
describe InvalidUriProtection do
|
6
6
|
let(:target_app) { ->(_env){ [200, {}, []] } }
|
7
7
|
let(:app) { InvalidUriProtection.new(target_app) }
|
8
|
-
let(:path) {
|
8
|
+
let(:path) { "/foo" }
|
9
9
|
|
10
10
|
subject { get(path) }
|
11
11
|
|
@@ -28,7 +28,7 @@ module Rack
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context "when the URI contains a new line because someone forgot to strip the result of `git rev-parse HEAD`, and I have totally never done this before myself" do
|
31
|
-
let(:path) {
|
31
|
+
let(:path) { "/foo%0A/bar" }
|
32
32
|
|
33
33
|
it "returns a 422" do
|
34
34
|
expect(subject.status).to eq 422
|
@@ -37,7 +37,7 @@ module Rack
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context "when the URI contains a tab because sooner or later someone is eventually going to do this" do
|
40
|
-
let(:path) {
|
40
|
+
let(:path) { "/foo%09/bar" }
|
41
41
|
|
42
42
|
it "returns a 422" do
|
43
43
|
expect(subject.status).to eq 422
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,7 @@ return if ENV["REGRESSION"] == "true"
|
|
5
5
|
$: << File.expand_path("../../", __FILE__)
|
6
6
|
|
7
7
|
RACK_ENV = ENV["RACK_ENV"] = "test"
|
8
|
+
ENV["PACT_BROKER_LOG_LEVEL"] ||= "info"
|
8
9
|
require "spec/support/simplecov"
|
9
10
|
|
10
11
|
require "support/logging"
|
@@ -60,5 +61,5 @@ end
|
|
60
61
|
|
61
62
|
if ENV["DEBUG"] == "true"
|
62
63
|
SemanticLogger.add_appender(io: $stdout)
|
63
|
-
SemanticLogger.default_level = :
|
64
|
+
SemanticLogger.default_level = :debug
|
64
65
|
end
|
data/spec/support/approvals.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
require "approvals/rspec"
|
2
2
|
require "pact/support"
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
class YamlFormat < Approvals::Writers::TextWriter
|
6
|
+
def format(data)
|
7
|
+
data.to_yaml
|
8
|
+
end
|
9
|
+
|
10
|
+
def filter(data)
|
11
|
+
# Custom data filtering here
|
12
|
+
end
|
13
|
+
end
|
3
14
|
|
4
15
|
Approvals.configure do |c|
|
5
16
|
c.approvals_path = "spec/fixtures/approvals/"
|
@@ -17,10 +28,28 @@ def print_diff(exception)
|
|
17
28
|
end
|
18
29
|
end
|
19
30
|
|
31
|
+
module MatrixQueryContentForApproval
|
32
|
+
def matrix_query_content_for_approval(result)
|
33
|
+
{
|
34
|
+
"deployable" => result.deployment_status_summary.deployable?,
|
35
|
+
"reasons" => result.deployment_status_summary.reasons.collect(&:class).collect(&:name).sort
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
20
40
|
RSpec.configure do | config |
|
21
41
|
config.after(:each) do | example |
|
22
42
|
if example.exception.is_a?(Approvals::ApprovalError)
|
23
43
|
print_diff(example.exception)
|
24
44
|
end
|
25
45
|
end
|
46
|
+
|
47
|
+
def file_name_to_approval_name(filename)
|
48
|
+
sanitize_filename(filename.split("spec/lib/pact_broker/", 2).last.gsub(".rb", ""))
|
49
|
+
end
|
50
|
+
|
51
|
+
def sanitize_filename(filename)
|
52
|
+
filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
|
53
|
+
end
|
54
|
+
|
26
55
|
end
|