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
@@ -30,7 +30,7 @@
|
|
30
30
|
"status": 200,
|
31
31
|
"headers": {
|
32
32
|
"Content-Type": "application/hal+json;charset=utf-8",
|
33
|
-
"Content-Length": "
|
33
|
+
"Content-Length": "2929"
|
34
34
|
},
|
35
35
|
"body": {
|
36
36
|
"logs": [
|
@@ -55,12 +55,12 @@
|
|
55
55
|
"deprecationWarning": "Replaced by notices"
|
56
56
|
},
|
57
57
|
{
|
58
|
-
"level": "
|
58
|
+
"level": "prompt",
|
59
59
|
"message": " Next steps:",
|
60
60
|
"deprecationWarning": "Replaced by notices"
|
61
61
|
},
|
62
62
|
{
|
63
|
-
"level": "
|
63
|
+
"level": "prompt",
|
64
64
|
"message": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks",
|
65
65
|
"deprecationWarning": "Replaced by notices"
|
66
66
|
}
|
@@ -83,11 +83,11 @@
|
|
83
83
|
"text": " Events detected: contract_published, contract_content_changed (pact content modified since previous publication for Foo version 1)"
|
84
84
|
},
|
85
85
|
{
|
86
|
-
"type": "
|
86
|
+
"type": "prompt",
|
87
87
|
"text": " Next steps:"
|
88
88
|
},
|
89
89
|
{
|
90
|
-
"type": "
|
90
|
+
"type": "prompt",
|
91
91
|
"text": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks"
|
92
92
|
}
|
93
93
|
],
|
@@ -0,0 +1,312 @@
|
|
1
|
+
require "pact_broker/api/middleware/basic_auth"
|
2
|
+
require "pact_broker/api/authorization/resource_access_policy"
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
module Api
|
6
|
+
module Middleware
|
7
|
+
describe "basic auth" do
|
8
|
+
let(:protected_app) { ->(_) { [200, {}, []]} }
|
9
|
+
|
10
|
+
let(:policy) { PactBroker::Api::Authorization::ResourceAccessPolicy.build(allow_public_read_access, allow_public_access_to_heartbeat, enable_public_badge_access) }
|
11
|
+
let(:app) { BasicAuth.new(protected_app, [write_username, write_password], [read_username, read_password], policy) }
|
12
|
+
let(:allow_public_read_access) { false }
|
13
|
+
let(:allow_public_read_access) { false }
|
14
|
+
let(:write_username) { "write_username" }
|
15
|
+
let(:write_password) { "write_password" }
|
16
|
+
let(:read_username) { "read_username" }
|
17
|
+
let(:read_password) { "read_password" }
|
18
|
+
let(:allow_public_access_to_heartbeat) { true }
|
19
|
+
let(:enable_public_badge_access) { true }
|
20
|
+
|
21
|
+
context "when requesting the heartbeat" do
|
22
|
+
let(:path) { "/diagnostic/status/heartbeat" }
|
23
|
+
|
24
|
+
context "when allow_public_access_to_heartbeat is true" do
|
25
|
+
context "when no credentials are used" do
|
26
|
+
it "allows GET" do
|
27
|
+
get path
|
28
|
+
expect(last_response.status).to eq 200
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when allow_public_access_to_heartbeat is false" do
|
34
|
+
let(:allow_public_access_to_heartbeat) { false }
|
35
|
+
|
36
|
+
context "when no credentials are used" do
|
37
|
+
it "does not allow GET" do
|
38
|
+
get path
|
39
|
+
expect(last_response.status).to eq 401
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when the correct credentials are used" do
|
44
|
+
it "allows GET" do
|
45
|
+
basic_authorize "read_username", "read_password"
|
46
|
+
get path
|
47
|
+
expect(last_response.status).to eq 200
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when requesting a pact badge" do
|
54
|
+
context "when no credentials are used" do
|
55
|
+
it "allows GET" do
|
56
|
+
get "/pacts/provider/foo/consumer/bar/badge"
|
57
|
+
expect(last_response.status).to eq 200
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when enable_public_badge_access=false" do
|
62
|
+
let(:enable_public_badge_access) { false }
|
63
|
+
|
64
|
+
it "does not allow GET" do
|
65
|
+
get "/pacts/provider/foo/consumer/bar/badge"
|
66
|
+
expect(last_response.status).to eq 401
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when requesting a matrix badge" do
|
72
|
+
context "when no credentials are used" do
|
73
|
+
it "allows GET" do
|
74
|
+
get "/matrix/provider/foo/latest/dev/consumer/bar/latest/dev/badge"
|
75
|
+
expect(last_response.status).to eq 200
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with the correct username and password for the write user" do
|
81
|
+
it "allows GET" do
|
82
|
+
basic_authorize "write_username", "write_password"
|
83
|
+
get "/"
|
84
|
+
expect(last_response.status).to eq 200
|
85
|
+
end
|
86
|
+
|
87
|
+
it "allows POST" do
|
88
|
+
basic_authorize "write_username", "write_password"
|
89
|
+
post "/"
|
90
|
+
expect(last_response.status).to eq 200
|
91
|
+
end
|
92
|
+
|
93
|
+
it "allows HEAD" do
|
94
|
+
basic_authorize "write_username", "write_password"
|
95
|
+
head "/"
|
96
|
+
expect(last_response.status).to eq 200
|
97
|
+
end
|
98
|
+
|
99
|
+
it "allows OPTIONS" do
|
100
|
+
basic_authorize "write_username", "write_password"
|
101
|
+
options "/"
|
102
|
+
expect(last_response.status).to eq 200
|
103
|
+
end
|
104
|
+
|
105
|
+
it "allows PUT" do
|
106
|
+
basic_authorize "write_username", "write_password"
|
107
|
+
delete "/"
|
108
|
+
expect(last_response.status).to eq 200
|
109
|
+
end
|
110
|
+
|
111
|
+
it "allows PATCH" do
|
112
|
+
basic_authorize "write_username", "write_password"
|
113
|
+
patch "/"
|
114
|
+
expect(last_response.status).to eq 200
|
115
|
+
end
|
116
|
+
|
117
|
+
it "allows DELETE" do
|
118
|
+
basic_authorize "write_username", "write_password"
|
119
|
+
delete "/"
|
120
|
+
expect(last_response.status).to eq 200
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "with the incorrect username for the write user" do
|
125
|
+
it "does not allow POST" do
|
126
|
+
basic_authorize "wrong_username", "write_password"
|
127
|
+
post "/"
|
128
|
+
expect(last_response.status).to eq 401
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "with the incorrect password for the write user" do
|
133
|
+
it "does not allow POST" do
|
134
|
+
basic_authorize "write_username", "wrong_password"
|
135
|
+
post "/"
|
136
|
+
expect(last_response.status).to eq 401
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "with the correct username and password for the read user" do
|
141
|
+
it "allows GET" do
|
142
|
+
basic_authorize "read_username", "read_password"
|
143
|
+
get "/"
|
144
|
+
expect(last_response.status).to eq 200
|
145
|
+
end
|
146
|
+
|
147
|
+
it "allows OPTIONS" do
|
148
|
+
basic_authorize "read_username", "read_password"
|
149
|
+
options "/"
|
150
|
+
expect(last_response.status).to eq 200
|
151
|
+
end
|
152
|
+
|
153
|
+
it "allows HEAD" do
|
154
|
+
basic_authorize "read_username", "read_password"
|
155
|
+
head "/"
|
156
|
+
expect(last_response.status).to eq 200
|
157
|
+
end
|
158
|
+
|
159
|
+
it "does not allow POST" do
|
160
|
+
basic_authorize "read_username", "read_password"
|
161
|
+
post "/"
|
162
|
+
expect(last_response.status).to eq 401
|
163
|
+
end
|
164
|
+
|
165
|
+
it "does not allow PUT" do
|
166
|
+
basic_authorize "read_username", "read_password"
|
167
|
+
put "/"
|
168
|
+
expect(last_response.status).to eq 401
|
169
|
+
end
|
170
|
+
|
171
|
+
it "does not allow PATCH" do
|
172
|
+
basic_authorize "read_username", "read_password"
|
173
|
+
patch "/"
|
174
|
+
expect(last_response.status).to eq 401
|
175
|
+
end
|
176
|
+
|
177
|
+
it "does not allow DELETE" do
|
178
|
+
basic_authorize "read_username", "read_password"
|
179
|
+
delete "/"
|
180
|
+
expect(last_response.status).to eq 401
|
181
|
+
end
|
182
|
+
|
183
|
+
it "allows POST to the pacts for verification endpoint" do
|
184
|
+
basic_authorize "read_username", "read_password"
|
185
|
+
post "/pacts/provider/Foo/for-verification"
|
186
|
+
expect(last_response.status).to eq 200
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "with the incorrect username and password for the write user" do
|
191
|
+
it "does not allow GET" do
|
192
|
+
basic_authorize "write_username", "wrongpassword"
|
193
|
+
get "/"
|
194
|
+
expect(last_response.status).to eq 401
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "with the incorrect username and password for the read user" do
|
199
|
+
it "does not allow GET" do
|
200
|
+
basic_authorize "read_username", "wrongpassword"
|
201
|
+
get "/"
|
202
|
+
expect(last_response.status).to eq 401
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "with a request to the badge URL" do
|
207
|
+
context "with no credentials" do
|
208
|
+
it "allows GET" do
|
209
|
+
get "/pacts/provider/foo/consumer/bar/badge"
|
210
|
+
expect(last_response.status).to eq 200
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context "when there is no read only user configured" do
|
216
|
+
before do
|
217
|
+
allow($stdout).to receive(:puts)
|
218
|
+
end
|
219
|
+
|
220
|
+
let(:read_username) { nil }
|
221
|
+
let(:read_password) { nil }
|
222
|
+
|
223
|
+
context "when allow_public_read_access is false" do
|
224
|
+
context "with no credentials" do
|
225
|
+
it "does not allow a GET" do
|
226
|
+
get "/"
|
227
|
+
expect(last_response.status).to eq 401
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "with empty credentials" do
|
232
|
+
it "does not allow a GET" do
|
233
|
+
basic_authorize("", "")
|
234
|
+
get "/"
|
235
|
+
expect(last_response.status).to eq 401
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context "with incorrect credentials" do
|
240
|
+
it "does not allow a GET" do
|
241
|
+
basic_authorize("foo", "bar")
|
242
|
+
get "/"
|
243
|
+
expect(last_response.status).to eq 401
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context "when allow_public_read_access is true" do
|
249
|
+
let(:allow_public_read_access) { true }
|
250
|
+
|
251
|
+
context "with no credentials" do
|
252
|
+
it "allows a GET" do
|
253
|
+
get "/"
|
254
|
+
expect(last_response.status).to eq 200
|
255
|
+
end
|
256
|
+
|
257
|
+
it "does not allow POST" do
|
258
|
+
post "/"
|
259
|
+
expect(last_response.status).to eq 401
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context "with empty credentials" do
|
264
|
+
before do
|
265
|
+
basic_authorize("", "")
|
266
|
+
end
|
267
|
+
|
268
|
+
it "allows a GET" do
|
269
|
+
get "/"
|
270
|
+
expect(last_response.status).to eq 200
|
271
|
+
end
|
272
|
+
|
273
|
+
it "does not allow POST" do
|
274
|
+
post "/"
|
275
|
+
expect(last_response.status).to eq 401
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
context "with incorrect credentials" do
|
280
|
+
before do
|
281
|
+
basic_authorize("foo", "bar")
|
282
|
+
end
|
283
|
+
|
284
|
+
it "allows a GET" do
|
285
|
+
get "/"
|
286
|
+
expect(last_response.status).to eq 200
|
287
|
+
end
|
288
|
+
|
289
|
+
it "does not allow POST" do
|
290
|
+
post "/"
|
291
|
+
expect(last_response.status).to eq 401
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context "when the credentials are configured with empty strings" do
|
298
|
+
before do
|
299
|
+
basic_authorize("", "")
|
300
|
+
end
|
301
|
+
|
302
|
+
let(:write_username) { "" }
|
303
|
+
let(:write_password) { "" }
|
304
|
+
|
305
|
+
subject { get("/") }
|
306
|
+
|
307
|
+
its(:status) { is_expected.to eq 401 }
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
@@ -4,7 +4,8 @@ module PactBroker
|
|
4
4
|
module Api
|
5
5
|
module Resources
|
6
6
|
describe Tag do
|
7
|
-
let(:tag) { double("PactBroker::Domain::Tag") }
|
7
|
+
let(:tag) { double("PactBroker::Domain::Tag", version: version) }
|
8
|
+
let(:version) { double("version") }
|
8
9
|
let(:tag_decorator) { instance_double("PactBroker::Api::Decorators::TagDecorator", :to_json => tag_json) }
|
9
10
|
let(:tag_json) { {"some" => "tag"}.to_json }
|
10
11
|
let(:tag_attributes) {
|
@@ -99,9 +100,10 @@ module PactBroker
|
|
99
100
|
allow_any_instance_of(PactBroker::Api::Resources::Tag).to receive(:tag_url).and_return(tag_url)
|
100
101
|
allow(Tags::Service).to receive(:find).and_return(tag)
|
101
102
|
allow(PactBroker::Api::Decorators::TagDecorator).to receive(:new).and_return(tag_decorator)
|
102
|
-
|
103
|
+
allow(deployed_version_service).to receive(:maybe_create_deployed_version_for_tag).and_return("uuid")
|
103
104
|
end
|
104
105
|
|
106
|
+
let(:deployed_version_service) { class_double("PactBroker::Deployments::DeployedVersionService").as_stubbed_const }
|
105
107
|
let(:tag_url) { "http://example.org/tag/url"}
|
106
108
|
let(:create_deployed_versions_for_tags) { false }
|
107
109
|
|
@@ -118,12 +120,16 @@ module PactBroker
|
|
118
120
|
expect(last_response.status).to be 200
|
119
121
|
end
|
120
122
|
|
123
|
+
it "maybe creates a deployed version" do
|
124
|
+
expect(deployed_version_service).to receive(:maybe_create_deployed_version_for_tag).with(version, "prod")
|
125
|
+
subject
|
126
|
+
end
|
127
|
+
|
121
128
|
it "renders the tag" do
|
122
129
|
expect(tag_decorator).to receive(:to_json).with(user_options: hash_including(base_url: "http://example.org"))
|
123
130
|
subject
|
124
131
|
expect(last_response.body).to eq tag_json
|
125
132
|
end
|
126
|
-
|
127
133
|
end
|
128
134
|
|
129
135
|
context "when the tag does not exist" do
|
@@ -137,6 +143,11 @@ module PactBroker
|
|
137
143
|
subject
|
138
144
|
end
|
139
145
|
|
146
|
+
it "maybe creates a deployed version" do
|
147
|
+
expect(deployed_version_service).to receive(:maybe_create_deployed_version_for_tag).with(version, "prod")
|
148
|
+
subject
|
149
|
+
end
|
150
|
+
|
140
151
|
it "returns a 201" do
|
141
152
|
subject
|
142
153
|
expect(last_response.status).to be 201
|
@@ -148,42 +159,6 @@ module PactBroker
|
|
148
159
|
expect(last_response.body).to eq tag_json
|
149
160
|
end
|
150
161
|
end
|
151
|
-
|
152
|
-
context "when create_deployed_versions_for_tags is true" do
|
153
|
-
before do
|
154
|
-
allow_any_instance_of(described_class).to receive(:environment_service).and_return(environment_service)
|
155
|
-
allow_any_instance_of(described_class).to receive(:deployed_version_service).and_return(deployed_version_service)
|
156
|
-
allow(environment_service).to receive(:find_by_name).and_return(environment)
|
157
|
-
allow(deployed_version_service).to receive(:next_uuid).and_return("uuid")
|
158
|
-
allow(tag).to receive(:version).and_return(version)
|
159
|
-
end
|
160
|
-
let(:environment_service) { class_double("PactBroker::Environments::Service").as_stubbed_const }
|
161
|
-
let(:deployed_version_service) { class_double("PactBroker::Deployments::DeployedVersionService").as_stubbed_const }
|
162
|
-
let(:environment) { nil }
|
163
|
-
let(:create_deployed_versions_for_tags) { true }
|
164
|
-
let(:version) { double("version") }
|
165
|
-
|
166
|
-
it "looks for a matching environment" do
|
167
|
-
expect(environment_service).to receive(:find_by_name).with("prod")
|
168
|
-
subject
|
169
|
-
end
|
170
|
-
|
171
|
-
context "when the tag name matches an existing environment" do
|
172
|
-
let(:environment) { double("environment") }
|
173
|
-
|
174
|
-
it "creates a deployed version" do
|
175
|
-
expect(deployed_version_service).to receive(:find_or_create).with(anything, version, environment, nil)
|
176
|
-
subject
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
context "when the tag name does not match an existing environment" do
|
181
|
-
it "does not create a deployed version" do
|
182
|
-
expect_any_instance_of(described_class).to_not receive(:deployed_version_service)
|
183
|
-
subject
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
162
|
end
|
188
163
|
end
|
189
164
|
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require "pact_broker/app"
|
2
|
+
require "anyway/testing/helpers"
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
describe App do
|
6
|
+
include Anyway::Testing::Helpers
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(PactBroker::DB).to receive(:run_migrations)
|
10
|
+
end
|
11
|
+
|
12
|
+
class TestApp2 < PactBroker::App
|
13
|
+
def configure_database_connection
|
14
|
+
# do nothing so we don't screw up our test connection
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
around do | example |
|
19
|
+
env_vars = {
|
20
|
+
"PACT_BROKER_BASIC_AUTH_ENABLED" => basic_auth_enabled,
|
21
|
+
"PACT_BROKER_BASIC_AUTH_USERNAME" => basic_auth_username,
|
22
|
+
"PACT_BROKER_BASIC_AUTH_PASSWORD" => basic_auth_password,
|
23
|
+
"PACT_BROKER_BASIC_AUTH_READ_ONLY_USERNAME" => basic_auth_read_only_username,
|
24
|
+
"PACT_BROKER_BASIC_AUTH_READ_ONLY_PASSWORD" => basic_auth_read_only_password,
|
25
|
+
"PACT_BROKER_ALLOW_PUBLIC_READ" => allow_public_read,
|
26
|
+
"PACT_BROKER_ENABLE_PUBLIC_BADGE_ACCESS" => enable_public_badge_access
|
27
|
+
}
|
28
|
+
with_env(env_vars, &example)
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:basic_auth_enabled) { "true" }
|
32
|
+
let(:basic_auth_username) { "user" }
|
33
|
+
let(:basic_auth_password) { "pass" }
|
34
|
+
let(:basic_auth_read_only_username) { "rouser" }
|
35
|
+
let(:basic_auth_read_only_password) { "ropass" }
|
36
|
+
let(:allow_public_read) { "false" }
|
37
|
+
let(:enable_public_badge_access) { "false" }
|
38
|
+
|
39
|
+
let(:app) do
|
40
|
+
TestApp2.new do | configuration |
|
41
|
+
configuration.database_connection = PactBroker::DB.connection
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
subject { get("/") }
|
46
|
+
|
47
|
+
context "with correct write credentials" do
|
48
|
+
before do
|
49
|
+
basic_authorize "user", "pass"
|
50
|
+
end
|
51
|
+
|
52
|
+
its(:status) { is_expected.to eq 200 }
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with correct read credentials" do
|
56
|
+
before do
|
57
|
+
basic_authorize "rouser", "ropass"
|
58
|
+
end
|
59
|
+
|
60
|
+
its(:status) { is_expected.to eq 200 }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with incorrect credentials" do
|
64
|
+
before do
|
65
|
+
basic_authorize "wrong", "pass"
|
66
|
+
end
|
67
|
+
|
68
|
+
its(:status) { is_expected.to eq 401 }
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with no credentials" do
|
72
|
+
its(:status) { is_expected.to eq 401 }
|
73
|
+
|
74
|
+
context "when allow_public_read=true" do
|
75
|
+
let(:allow_public_read) { "true" }
|
76
|
+
|
77
|
+
its(:status) { is_expected.to eq 200 }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with basic auth enabled but no username or password configured" do
|
82
|
+
before do
|
83
|
+
basic_authorize "", ""
|
84
|
+
end
|
85
|
+
|
86
|
+
let(:basic_auth_username) { "" }
|
87
|
+
let(:basic_auth_password) { "" }
|
88
|
+
|
89
|
+
its(:status) { is_expected.to eq 401 }
|
90
|
+
end
|
91
|
+
|
92
|
+
context "with basic auth disabled" do
|
93
|
+
let(:basic_auth_enabled) { "false" }
|
94
|
+
|
95
|
+
context "with no credentials" do
|
96
|
+
its(:status) { is_expected.to eq 200 }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "accessing a badge" do
|
101
|
+
before do
|
102
|
+
td.create_pact_with_hierarchy("foo", "1", "bar")
|
103
|
+
end
|
104
|
+
|
105
|
+
subject { get(PactBroker::Api::PactBrokerUrls.badge_url_for_latest_pact(td.and_return(:pact))) }
|
106
|
+
|
107
|
+
its(:status) { is_expected.to eq 401 }
|
108
|
+
|
109
|
+
context "with no basic auth configured" do
|
110
|
+
let(:basic_auth_enabled) { "false" }
|
111
|
+
|
112
|
+
its(:status) { is_expected.to eq 307 }
|
113
|
+
end
|
114
|
+
|
115
|
+
context "with public badge access enabled" do
|
116
|
+
let(:enable_public_badge_access) { "true" }
|
117
|
+
|
118
|
+
its(:status) { is_expected.to eq 307 }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|