pact_broker 1.18.0.beta.1 → 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -2
- data/README.md +12 -12
- data/example/{heroku → basic_auth}/Gemfile +0 -0
- data/example/{heroku → basic_auth}/Procfile +0 -0
- data/example/{heroku → basic_auth}/README.md +1 -1
- data/example/basic_auth/config.ru +19 -0
- data/example/config.ru +0 -2
- data/lib/pact_broker/api/decorators/versions_decorator.rb +1 -1
- data/lib/pact_broker/api/resources/versions.rb +1 -1
- data/lib/pact_broker/app.rb +7 -6
- data/lib/pact_broker/configuration.rb +4 -42
- data/lib/pact_broker/domain/order_versions.rb +15 -5
- data/lib/pact_broker/domain/webhook.rb +0 -1
- data/lib/pact_broker/domain/webhook_request.rb +6 -4
- data/lib/pact_broker/logging.rb +4 -0
- data/lib/pact_broker/pacticipants/repository.rb +2 -1
- data/lib/pact_broker/pacticipants/service.rb +2 -2
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/webhooks/job.rb +46 -0
- data/lib/pact_broker/webhooks/service.rb +9 -8
- data/lib/pact_broker/webhooks/webhook.rb +1 -1
- data/pact_broker.gemspec +2 -1
- data/pact_broker_client-pact_broker.json +4 -4
- data/script/foo-bar.json +22 -0
- data/script/publish-new.sh +7 -0
- data/script/publish.sh +2 -2
- data/script/recreate-pg-db.sh +7 -0
- data/spec/fixtures/a_consumer-a_provider-2.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-3.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-conflict.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-merged.json +2 -2
- data/spec/fixtures/a_consumer-a_provider.json +1 -1
- data/spec/fixtures/consumer-provider.json +1 -1
- data/spec/fixtures/renderer_pact.json +1 -1
- data/spec/lib/pact_broker/configuration_spec.rb +2 -22
- data/spec/lib/pact_broker/domain/order_versions_spec.rb +30 -10
- data/spec/lib/pact_broker/domain/webhook_request_spec.rb +3 -1
- data/spec/lib/pact_broker/pacticipants/repository_spec.rb +16 -0
- data/spec/lib/pact_broker/webhooks/job_spec.rb +67 -0
- data/spec/lib/pact_broker/webhooks/service_spec.rb +40 -3
- data/spec/support/provider_state_builder.rb +36 -8
- metadata +29 -12
- data/example/heroku/config.ru +0 -12
- data/lib/pact_broker/configuration/configure_basic_auth.rb +0 -83
- data/spec/lib/pact_broker/configuration/configure_basic_auth_spec.rb +0 -267
@@ -1,5 +1,21 @@
|
|
1
1
|
require 'pact_broker/repositories'
|
2
|
+
require 'pact_broker/webhooks/repository'
|
3
|
+
require 'pact_broker/webhooks/service'
|
4
|
+
require 'pact_broker/pacts/repository'
|
5
|
+
require 'pact_broker/pacts/service'
|
6
|
+
require 'pact_broker/pacticipants/repository'
|
7
|
+
require 'pact_broker/pacticipants/service'
|
8
|
+
require 'pact_broker/versions/repository'
|
9
|
+
require 'pact_broker/versions/service'
|
10
|
+
require 'pact_broker/tags/repository'
|
11
|
+
require 'pact_broker/tags/service'
|
12
|
+
require 'pact_broker/domain'
|
2
13
|
require 'json'
|
14
|
+
require 'pact_broker/versions/repository'
|
15
|
+
require 'pact_broker/pacts/repository'
|
16
|
+
require 'pact_broker/pacticipants/repository'
|
17
|
+
require 'pact_broker/tags/repository'
|
18
|
+
require 'pact_broker/webhooks/repository'
|
3
19
|
|
4
20
|
class ProviderStateBuilder
|
5
21
|
|
@@ -83,24 +99,24 @@ class ProviderStateBuilder
|
|
83
99
|
self
|
84
100
|
end
|
85
101
|
|
86
|
-
def create_consumer consumer_name
|
102
|
+
def create_consumer consumer_name = "Consumer #{model_counter}"
|
87
103
|
create_pacticipant consumer_name
|
88
104
|
@consumer = @pacticipant
|
89
105
|
self
|
90
106
|
end
|
91
107
|
|
92
|
-
def create_provider provider_name
|
108
|
+
def create_provider provider_name = "Provider #{model_counter}"
|
93
109
|
create_pacticipant provider_name
|
94
110
|
@provider = @pacticipant
|
95
111
|
self
|
96
112
|
end
|
97
113
|
|
98
|
-
def create_version version_number
|
114
|
+
def create_version version_number = "1.0.#{model_counter}"
|
99
115
|
@version = PactBroker::Domain::Version.create(:number => version_number, :pacticipant => @pacticipant)
|
100
116
|
self
|
101
117
|
end
|
102
118
|
|
103
|
-
def create_consumer_version version_number
|
119
|
+
def create_consumer_version version_number = "1.0.#{model_counter}"
|
104
120
|
@consumer_version = PactBroker::Domain::Version.create(:number => version_number, :pacticipant => @consumer)
|
105
121
|
self
|
106
122
|
end
|
@@ -120,12 +136,23 @@ class ProviderStateBuilder
|
|
120
136
|
self
|
121
137
|
end
|
122
138
|
|
123
|
-
def create_webhook
|
124
|
-
|
139
|
+
def create_webhook params = {}
|
140
|
+
default_params = {method: 'POST', url: 'http://example.org', headers: {'Content-Type' => 'application/json'}}
|
141
|
+
request = PactBroker::Domain::WebhookRequest.new(default_params.merge(params))
|
125
142
|
@webhook = PactBroker::Webhooks::Repository.new.create PactBroker::Webhooks::Service.next_uuid, PactBroker::Domain::Webhook.new(request: request), @consumer, @provider
|
126
143
|
self
|
127
144
|
end
|
128
145
|
|
146
|
+
def model_counter
|
147
|
+
@@model_counter ||= 0
|
148
|
+
@@model_counter += 1
|
149
|
+
@@model_counter
|
150
|
+
end
|
151
|
+
|
152
|
+
def and_return instance_variable_name
|
153
|
+
instance_variable_get("@#{instance_variable_name}")
|
154
|
+
end
|
155
|
+
|
129
156
|
private
|
130
157
|
|
131
158
|
def default_json_content
|
@@ -136,8 +163,9 @@ class ProviderStateBuilder
|
|
136
163
|
"provider" => {
|
137
164
|
"name" => "Pricing Service"
|
138
165
|
},
|
139
|
-
"interactions" => []
|
166
|
+
"interactions" => [],
|
167
|
+
"random" => rand
|
140
168
|
}.to_json
|
141
169
|
end
|
142
170
|
|
143
|
-
end
|
171
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.18.0
|
4
|
+
version: 1.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bethany Skurrie
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-05-
|
13
|
+
date: 2017-05-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '4.0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: sucker_punch
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '2.0'
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '2.0'
|
223
237
|
- !ruby/object:Gem::Dependency
|
224
238
|
name: sqlite3
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -235,7 +249,7 @@ dependencies:
|
|
235
249
|
- !ruby/object:Gem::Version
|
236
250
|
version: '0'
|
237
251
|
- !ruby/object:Gem::Dependency
|
238
|
-
name: pry
|
252
|
+
name: pry-byebug
|
239
253
|
requirement: !ruby/object:Gem::Requirement
|
240
254
|
requirements:
|
241
255
|
- - ">="
|
@@ -395,11 +409,11 @@ files:
|
|
395
409
|
- db/migrations/migration_helper.rb
|
396
410
|
- db/pact_broker_database.sqlite3
|
397
411
|
- example/Gemfile
|
412
|
+
- example/basic_auth/Gemfile
|
413
|
+
- example/basic_auth/Procfile
|
414
|
+
- example/basic_auth/README.md
|
415
|
+
- example/basic_auth/config.ru
|
398
416
|
- example/config.ru
|
399
|
-
- example/heroku/Gemfile
|
400
|
-
- example/heroku/Procfile
|
401
|
-
- example/heroku/README.md
|
402
|
-
- example/heroku/config.ru
|
403
417
|
- example/pact_broker_database.sqlite3
|
404
418
|
- lib/db.rb
|
405
419
|
- lib/pact_broker.rb
|
@@ -462,7 +476,6 @@ files:
|
|
462
476
|
- lib/pact_broker/api/resources/webhooks.rb
|
463
477
|
- lib/pact_broker/app.rb
|
464
478
|
- lib/pact_broker/configuration.rb
|
465
|
-
- lib/pact_broker/configuration/configure_basic_auth.rb
|
466
479
|
- lib/pact_broker/constants.rb
|
467
480
|
- lib/pact_broker/date_helper.rb
|
468
481
|
- lib/pact_broker/db.rb
|
@@ -543,6 +556,7 @@ files:
|
|
543
556
|
- lib/pact_broker/versions/parse_semantic_version.rb
|
544
557
|
- lib/pact_broker/versions/repository.rb
|
545
558
|
- lib/pact_broker/versions/service.rb
|
559
|
+
- lib/pact_broker/webhooks/job.rb
|
546
560
|
- lib/pact_broker/webhooks/repository.rb
|
547
561
|
- lib/pact_broker/webhooks/service.rb
|
548
562
|
- lib/pact_broker/webhooks/webhook.rb
|
@@ -575,9 +589,12 @@ files:
|
|
575
589
|
- public/stylesheets/github.css
|
576
590
|
- public/stylesheets/pact.css
|
577
591
|
- public/stylesheets/relationships.css
|
592
|
+
- script/foo-bar.json
|
578
593
|
- script/publish-2.sh
|
594
|
+
- script/publish-new.sh
|
579
595
|
- script/publish-not-a-pact.sh
|
580
596
|
- script/publish.sh
|
597
|
+
- script/recreate-pg-db.sh
|
581
598
|
- script/update-hal-browser
|
582
599
|
- spec/features/create_webhook_spec.rb
|
583
600
|
- spec/features/delete_pact_spec.rb
|
@@ -634,7 +651,6 @@ files:
|
|
634
651
|
- spec/lib/pact_broker/api/resources/webhook_execution_spec.rb
|
635
652
|
- spec/lib/pact_broker/api/resources/webhook_spec.rb
|
636
653
|
- spec/lib/pact_broker/api/resources/webhooks_spec.rb
|
637
|
-
- spec/lib/pact_broker/configuration/configure_basic_auth_spec.rb
|
638
654
|
- spec/lib/pact_broker/configuration_spec.rb
|
639
655
|
- spec/lib/pact_broker/db/validate_encoding_spec.rb
|
640
656
|
- spec/lib/pact_broker/diagnostic/resources/dependencies_spec.rb
|
@@ -664,6 +680,7 @@ files:
|
|
664
680
|
- spec/lib/pact_broker/ui/view_models/relationship_spec.rb
|
665
681
|
- spec/lib/pact_broker/ui/view_models/relationships_spec.rb
|
666
682
|
- spec/lib/pact_broker/versions/repository_spec.rb
|
683
|
+
- spec/lib/pact_broker/webhooks/job_spec.rb
|
667
684
|
- spec/lib/pact_broker/webhooks/repository_spec.rb
|
668
685
|
- spec/lib/pact_broker/webhooks/service_spec.rb
|
669
686
|
- spec/lib/rack/hal_browser/redirect_spec.rb
|
@@ -732,9 +749,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
732
749
|
version: 2.2.0
|
733
750
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
734
751
|
requirements:
|
735
|
-
- - "
|
752
|
+
- - ">="
|
736
753
|
- !ruby/object:Gem::Version
|
737
|
-
version:
|
754
|
+
version: '0'
|
738
755
|
requirements: []
|
739
756
|
rubyforge_project:
|
740
757
|
rubygems_version: 2.6.11
|
@@ -797,7 +814,6 @@ test_files:
|
|
797
814
|
- spec/lib/pact_broker/api/resources/webhook_execution_spec.rb
|
798
815
|
- spec/lib/pact_broker/api/resources/webhook_spec.rb
|
799
816
|
- spec/lib/pact_broker/api/resources/webhooks_spec.rb
|
800
|
-
- spec/lib/pact_broker/configuration/configure_basic_auth_spec.rb
|
801
817
|
- spec/lib/pact_broker/configuration_spec.rb
|
802
818
|
- spec/lib/pact_broker/db/validate_encoding_spec.rb
|
803
819
|
- spec/lib/pact_broker/diagnostic/resources/dependencies_spec.rb
|
@@ -827,6 +843,7 @@ test_files:
|
|
827
843
|
- spec/lib/pact_broker/ui/view_models/relationship_spec.rb
|
828
844
|
- spec/lib/pact_broker/ui/view_models/relationships_spec.rb
|
829
845
|
- spec/lib/pact_broker/versions/repository_spec.rb
|
846
|
+
- spec/lib/pact_broker/webhooks/job_spec.rb
|
830
847
|
- spec/lib/pact_broker/webhooks/repository_spec.rb
|
831
848
|
- spec/lib/pact_broker/webhooks/service_spec.rb
|
832
849
|
- spec/lib/rack/hal_browser/redirect_spec.rb
|
data/example/heroku/config.ru
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'logger'
|
3
|
-
require 'sequel'
|
4
|
-
require 'pact_broker'
|
5
|
-
require 'pg'
|
6
|
-
|
7
|
-
app = PactBroker::App.new do | config |
|
8
|
-
config.database_connection = Sequel.connect(ENV['DATABASE_URL'], adapter: "postgres", encoding: 'utf8')
|
9
|
-
config.protect_with_basic_auth :all, {username: ENV['PACT_BROKER_USERNAME'], password: ENV['PACT_BROKER_PASSWORD']}
|
10
|
-
end
|
11
|
-
|
12
|
-
run app
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'pact_broker/configuration'
|
2
|
-
|
3
|
-
module PactBroker
|
4
|
-
class Configuration
|
5
|
-
|
6
|
-
class ConfigurableBasicAuth
|
7
|
-
|
8
|
-
def initialize(app)
|
9
|
-
@app = app
|
10
|
-
@predicates = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def protect credentials_list, &predicate
|
14
|
-
basic_auth_proxy = ::Rack::Auth::Basic.new(app) do | username, password |
|
15
|
-
credentials_list.any? do | credentials |
|
16
|
-
username == credentials[:username] && password == credentials[:password]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
predicates << [predicate, basic_auth_proxy]
|
20
|
-
end
|
21
|
-
|
22
|
-
def call(env)
|
23
|
-
predicates = matching_predicates(env)
|
24
|
-
if predicates.any?
|
25
|
-
cascade(predicates, env)
|
26
|
-
else
|
27
|
-
app.call(env)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
attr_accessor :app, :predicates
|
34
|
-
|
35
|
-
def matching_predicates env
|
36
|
-
predicates.select do | predicate, basic_auth_proxy |
|
37
|
-
predicate.call(env)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def cascade predicates, env
|
42
|
-
response = nil
|
43
|
-
predicates.each do | predicate, basic_auth_proxy |
|
44
|
-
response = basic_auth_proxy.call(env)
|
45
|
-
return response if response.first != 401
|
46
|
-
end
|
47
|
-
response
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
class ConfigureBasicAuth
|
53
|
-
|
54
|
-
def self.call app, configuration
|
55
|
-
new(app, configuration).call
|
56
|
-
end
|
57
|
-
|
58
|
-
def initialize app, configuration
|
59
|
-
@configuration = configuration
|
60
|
-
@basic_auth_proxy = ConfigurableBasicAuth.new(app)
|
61
|
-
end
|
62
|
-
|
63
|
-
def call
|
64
|
-
configuration.basic_auth_predicates.each do | scope, predicate |
|
65
|
-
configure_basic_auth_for_scope scope, &predicate
|
66
|
-
end
|
67
|
-
|
68
|
-
basic_auth_proxy
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
attr_accessor :basic_auth_proxy, :configuration
|
74
|
-
|
75
|
-
def configure_basic_auth_for_scope scope, &predicate
|
76
|
-
if configuration.protect_with_basic_auth?(scope)
|
77
|
-
credentials = configuration.basic_auth_credentials_list_for(scope)
|
78
|
-
basic_auth_proxy.protect(credentials, &predicate)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,267 +0,0 @@
|
|
1
|
-
require 'pact_broker/configuration/configure_basic_auth'
|
2
|
-
require 'pact_broker/app'
|
3
|
-
|
4
|
-
module PactBroker
|
5
|
-
class Configuration
|
6
|
-
describe ConfigurableBasicAuth do
|
7
|
-
|
8
|
-
let(:target_app) { ->(env){ [200, {}, ["hello"]] } }
|
9
|
-
let(:app) do
|
10
|
-
auth_app = ConfigurableBasicAuth.new(target_app)
|
11
|
-
auth_app.protect([{username: 'username', password: 'password'}]) do | env |
|
12
|
-
env['PATH_INFO'] == '/foo'
|
13
|
-
end
|
14
|
-
auth_app
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when not authorized" do
|
18
|
-
it "does not allow requests" do
|
19
|
-
get "/foo"
|
20
|
-
expect(last_response.status).to eq 401
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when authorized" do
|
25
|
-
|
26
|
-
before { basic_authorize 'username', 'password' }
|
27
|
-
|
28
|
-
it "allows requests" do
|
29
|
-
get "/foo"
|
30
|
-
expect(last_response.status).to eq 200
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe ConfigureBasicAuth do
|
36
|
-
def read_request_to_ui
|
37
|
-
get "/"
|
38
|
-
last_response
|
39
|
-
end
|
40
|
-
|
41
|
-
def read_request_to_api
|
42
|
-
get "/pacts/latest"
|
43
|
-
last_response
|
44
|
-
end
|
45
|
-
|
46
|
-
def write_request_to_api
|
47
|
-
put "/pacts/provider/foo/consumer/bar/version/1.2.3", '{}', {'Content-Type' => 'application/json'}
|
48
|
-
last_response
|
49
|
-
end
|
50
|
-
|
51
|
-
def read_request_to_diagnostic
|
52
|
-
get "/diagnostic/status/heartbeat"
|
53
|
-
last_response
|
54
|
-
end
|
55
|
-
|
56
|
-
def authorize_request
|
57
|
-
basic_authorize 'username', 'password'
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
before do
|
62
|
-
PactBroker.reset_configuration
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "with no basic_auth" do
|
66
|
-
let(:app) do
|
67
|
-
app = PactBroker::App.new do | config |
|
68
|
-
config.database_connection = PactBroker::DB.connection
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "when not authorized" do
|
73
|
-
it "allows GET requests to the UI" do
|
74
|
-
expect(read_request_to_ui.status).to_not eq 401
|
75
|
-
end
|
76
|
-
|
77
|
-
it "allows GET requests to the API" do
|
78
|
-
expect(read_request_to_api.status).to_not eq 401
|
79
|
-
end
|
80
|
-
|
81
|
-
it "allows non GET requests to the API" do
|
82
|
-
expect(write_request_to_api.status).to_not eq 401
|
83
|
-
end
|
84
|
-
|
85
|
-
it "allows GET requests to the diagnostics app" do
|
86
|
-
expect(read_request_to_diagnostic.status).to_not eq 401
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "with basic_auth for :all" do
|
92
|
-
let(:app) do
|
93
|
-
app = PactBroker::App.new do | config |
|
94
|
-
config.database_connection = PactBroker::DB.connection
|
95
|
-
config.protect_with_basic_auth :all, {username: 'username', password: 'password'}
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "when authorized" do
|
100
|
-
before do
|
101
|
-
authorize_request
|
102
|
-
end
|
103
|
-
|
104
|
-
it "allows GET requests to the UI" do
|
105
|
-
expect(read_request_to_ui.status).to_not eq 401
|
106
|
-
end
|
107
|
-
|
108
|
-
it "allows GET requests to the API" do
|
109
|
-
expect(read_request_to_api.status).to_not eq 401
|
110
|
-
end
|
111
|
-
|
112
|
-
it "allows non GET requests to the API" do
|
113
|
-
expect(write_request_to_api.status).to_not eq 401
|
114
|
-
end
|
115
|
-
|
116
|
-
it "allows GET requests to the diagnostics app" do
|
117
|
-
expect(read_request_to_diagnostic.status).to_not eq 401
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "when not authorized" do
|
122
|
-
it "does not allow GET requests to the UI" do
|
123
|
-
expect(read_request_to_ui.status).to eq 401
|
124
|
-
end
|
125
|
-
|
126
|
-
it "does not allow GET requests the API" do
|
127
|
-
expect(read_request_to_api.status).to eq 401
|
128
|
-
end
|
129
|
-
|
130
|
-
it "does not allow non GET requests the API" do
|
131
|
-
expect(write_request_to_api.status).to eq 401
|
132
|
-
end
|
133
|
-
|
134
|
-
it "does not allow GET requests to the diagnostics app" do
|
135
|
-
expect(read_request_to_diagnostic.status).to eq 401
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "with basic_auth for :app_write" do
|
141
|
-
|
142
|
-
let(:app) do
|
143
|
-
app = PactBroker::App.new do | config |
|
144
|
-
config.database_connection = PactBroker::DB.connection
|
145
|
-
config.protect_with_basic_auth :app_write, {username: 'username', password: 'password'}
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context "when authorized" do
|
150
|
-
before do
|
151
|
-
authorize_request
|
152
|
-
end
|
153
|
-
|
154
|
-
it "allows GET requests to the diagnostics app" do
|
155
|
-
expect(read_request_to_diagnostic.status).to_not eq 401
|
156
|
-
end
|
157
|
-
|
158
|
-
it "allows GET requests to the app_write app" do
|
159
|
-
expect(read_request_to_diagnostic.status).to_not eq 401
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context "when not authorized" do
|
164
|
-
|
165
|
-
it "allows GET requests to the UI" do
|
166
|
-
expect(read_request_to_ui.status).to_not eq 401
|
167
|
-
end
|
168
|
-
|
169
|
-
it "allows GET requests the API" do
|
170
|
-
expect(read_request_to_api.status).to_not eq 401
|
171
|
-
end
|
172
|
-
|
173
|
-
it "does not allow non GET requests the API" do
|
174
|
-
expect(write_request_to_api.status).to eq 401
|
175
|
-
end
|
176
|
-
|
177
|
-
it "allows GET requests to the diagnostics app" do
|
178
|
-
expect(read_request_to_diagnostic.status).to_not eq 401
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "with multiple users for for :app_write" do
|
184
|
-
let(:app) do
|
185
|
-
app = PactBroker::App.new do | config |
|
186
|
-
config.database_connection = PactBroker::DB.connection
|
187
|
-
config.protect_with_basic_auth :app_write, {username: 'read_username', password: 'password'}
|
188
|
-
config.protect_with_basic_auth :app_write, {username: 'another_read_username', password: 'password'}
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
context "when the first credentials are used" do
|
193
|
-
before { basic_authorize 'read_username', 'password' }
|
194
|
-
|
195
|
-
it "allows a request" do
|
196
|
-
write_request_to_api
|
197
|
-
expect(last_response.status).to_not eq 401
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
context "when the second credentials are used" do
|
202
|
-
before { basic_authorize 'another_read_username', 'password' }
|
203
|
-
|
204
|
-
it "allows a request" do
|
205
|
-
write_request_to_api
|
206
|
-
expect(last_response.status).to_not eq 401
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context "when the wrong credentials are used" do
|
211
|
-
before { basic_authorize 'wrong_username', 'password' }
|
212
|
-
|
213
|
-
it "does not allow the request" do
|
214
|
-
write_request_to_api
|
215
|
-
expect(last_response.status).to eq 401
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
context "when no credentials are used" do
|
220
|
-
it "does not allow the request" do
|
221
|
-
write_request_to_api
|
222
|
-
expect(last_response.status).to eq 401
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
describe "with an app_read user and an app user" do
|
229
|
-
let(:app) do
|
230
|
-
app = PactBroker::App.new do | config |
|
231
|
-
config.database_connection = PactBroker::DB.connection
|
232
|
-
config.protect_with_basic_auth :app_read, {username: 'read_username', password: 'password'}
|
233
|
-
config.protect_with_basic_auth :app, {username: 'read_and_write_username', password: 'password'}
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
context "when the app credentials are used" do
|
238
|
-
before { basic_authorize 'read_and_write_username', 'password' }
|
239
|
-
|
240
|
-
it "allows a read request" do
|
241
|
-
read_request_to_api
|
242
|
-
expect(last_response.status).to_not eq 401
|
243
|
-
end
|
244
|
-
|
245
|
-
it "allows a write request" do
|
246
|
-
write_request_to_api
|
247
|
-
expect(last_response.status).to_not eq 401
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
context "when the read_username credentials are used" do
|
252
|
-
before { basic_authorize 'read_username', 'password' }
|
253
|
-
|
254
|
-
it "allows a read request" do
|
255
|
-
read_request_to_api
|
256
|
-
expect(last_response.status).to_not eq 401
|
257
|
-
end
|
258
|
-
|
259
|
-
it "does not allow a write request" do
|
260
|
-
write_request_to_api
|
261
|
-
expect(last_response.status).to eq 401
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|