Skip to content

Commit 354833c

Browse files
committed
Revert "Add in-built configuration for basic auth."
This reverts commit 99e825b.
1 parent 7444943 commit 354833c

File tree

5 files changed

+7
-313
lines changed

5 files changed

+7
-313
lines changed

lib/pact_broker/app.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'pact_broker/project_root'
44
require 'rack/hal_browser'
55
require 'rack/pact_broker/convert_file_extension_to_accept_header'
6-
require 'pact_broker/configuration/configure_basic_auth'
76

87
module PactBroker
98

@@ -71,12 +70,12 @@ def build_app
7170
apps << PactBroker::UI::App.new
7271
apps << PactBroker::API
7372

74-
cascade = Rack::Cascade.new(apps)
75-
app_with_basic_auth = PactBroker::Configuration::ConfigureBasicAuth.call(cascade, configuration)
76-
7773
@app.map "/" do
78-
run app_with_basic_auth
74+
run Rack::Cascade.new(apps)
7975
end
76+
8077
end
78+
8179
end
82-
end
80+
81+
end

lib/pact_broker/configuration.rb

+1-41
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,13 @@ def self.configuration
44
@@configuration ||= Configuration.default_configuration
55
end
66

7-
def self.reset_configuration
8-
@@configuration = Configuration.default_configuration
9-
end
10-
117
class Configuration
128

13-
REQUEST_METHOD = 'REQUEST_METHOD'.freeze
14-
GET = 'GET'.freeze
15-
PATH_INFO = 'PATH_INFO'.freeze
16-
DIAGNOSTIC = '/diagnostic/'.freeze
17-
189
attr_accessor :log_dir, :database_connection, :auto_migrate_db, :use_hal_browser, :html_pact_renderer
1910
attr_accessor :validate_database_connection_config, :enable_diagnostic_endpoints, :version_parser
20-
attr_accessor :use_case_sensitive_resource_names, :basic_auth_predicates
11+
attr_accessor :use_case_sensitive_resource_names
2112
attr_writer :logger
2213

23-
def initialize
24-
@basic_auth_config = {}
25-
@basic_auth_predicates = [
26-
[:diagnostic, ->(env) { env[PATH_INFO].start_with? DIAGNOSTIC }],
27-
[:app_read, ->(env) { env[REQUEST_METHOD] == GET }],
28-
[:app_write, ->(env) { env[REQUEST_METHOD] != GET }],
29-
[:app, ->(env) { !env[PATH_INFO].start_with? DIAGNOSTIC } ],
30-
[:all, ->(env) { true }]
31-
]
32-
end
33-
3414
def logger
3515
@logger ||= create_logger log_path
3616
end
@@ -49,35 +29,15 @@ def self.default_configuration
4929
config
5030
end
5131

52-
# public
5332
def self.default_html_pact_render
5433
lambda { |pact|
5534
require 'pact_broker/api/renderers/html_pact_renderer'
5635
PactBroker::Api::Renderers::HtmlPactRenderer.call pact
5736
}
5837
end
5938

60-
# public
61-
def protect_with_basic_auth scopes, credentials
62-
[*scopes].each do | scope |
63-
basic_auth_config[scope] = credentials
64-
end
65-
end
66-
67-
# private
68-
def protect_with_basic_auth? scope
69-
!!basic_auth_credentials_for(scope)
70-
end
71-
72-
# private
73-
def basic_auth_credentials_for scope
74-
basic_auth_config[scope] || basic_auth_config[:all]
75-
end
76-
7739
private
7840

79-
attr_reader :basic_auth_config
80-
8141
def create_logger path
8242
FileUtils::mkdir_p File.dirname(path)
8343
logger = Logger.new(path)

lib/pact_broker/configuration/configure_basic_auth.rb

-66
This file was deleted.

spec/lib/pact_broker/configuration/configure_basic_auth_spec.rb

-182
This file was deleted.

spec/lib/pact_broker/configuration_spec.rb

+1-18
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ module PactBroker
1616
end
1717

1818
end
19-
20-
describe "protect_with_basic_auth" do
21-
it "allows configuration for :all scopes at once" do
22-
config = Configuration.new
23-
config.protect_with_basic_auth :all, {some: 'credentials'}
24-
expect(config.protect_with_basic_auth?(:foo)).to be true
25-
expect(config.basic_auth_credentials_for(:foo)).to eq({some: 'credentials'})
26-
end
27-
28-
it "allows configuration for :separate scopes" do
29-
config = Configuration.new
30-
config.protect_with_basic_auth [:foo, :bar], {some: 'credentials'}
31-
expect(config.protect_with_basic_auth?(:foo)).to be true
32-
expect(config.basic_auth_credentials_for(:foo)).to eq({some: 'credentials'})
33-
expect(config.protect_with_basic_auth?(:wiffle)).to be false
34-
end
35-
end
3619
end
3720
end
38-
end
21+
end

0 commit comments

Comments
 (0)