Skip to content

Commit

Permalink
feat: changed configuration property name from to
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 17, 2017
1 parent 00ddb7c commit 69ab586
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/renderers/html_pact_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def pact_metadata
end

def badge_list_items
if PactBroker.configuration.enable_badge_resources
if PactBroker.configuration.enable_public_badge_access
"<li class='badge'>
<img src='#{badge_url}'/>
</li>
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/badge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def resource_exists?
end

def is_authorized?(authorization_header)
PactBroker.configuration.enable_badge_resources
super || PactBroker.configuration.enable_public_badge_access
end

def forbidden?
Expand Down
13 changes: 10 additions & 3 deletions lib/pact_broker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ def self.reset_configuration

class Configuration

SAVABLE_SETTING_NAMES = [:order_versions_by_date, :use_case_sensitive_resource_names, :enable_badge_resources, :shields_io_base_url]
SAVABLE_SETTING_NAMES = [:order_versions_by_date, :use_case_sensitive_resource_names, :enable_public_badge_access, :shields_io_base_url]

attr_accessor :log_dir, :database_connection, :auto_migrate_db, :use_hal_browser, :html_pact_renderer
attr_accessor :validate_database_connection_config, :enable_diagnostic_endpoints, :version_parser
attr_accessor :use_case_sensitive_resource_names, :order_versions_by_date
attr_accessor :semver_formats
attr_accessor :enable_badge_resources, :shields_io_base_url
attr_accessor :enable_public_badge_access, :shields_io_base_url
attr_writer :logger

alias_method :enable_badge_resources=, :enable_public_badge_access=

def initialize
@before_resource_hook = ->(resource){}
@after_resource_hook = ->(resource){}
Expand All @@ -39,7 +41,7 @@ def self.default_configuration
config.use_hal_browser = true
config.validate_database_connection_config = true
config.enable_diagnostic_endpoints = true
config.enable_badge_resources = false # For security
config.enable_public_badge_access = false # For security
config.shields_io_base_url = "https://img.shields.io".freeze
config.use_case_sensitive_resource_names = true
config.html_pact_renderer = default_html_pact_render
Expand Down Expand Up @@ -106,6 +108,11 @@ def after_resource &block
end
end

def enable_badge_resources= enable_badge_resources
puts "Pact Broker configuration property `enable_badge_resources` is deprecated. Please use `enable_public_badge_access`"
enable_public_badge_access= enable_badge_resources
end

def save_to_database
# Can't require a Sequel::Model class before the connection has been set
require 'pact_broker/config/save'
Expand Down
2 changes: 1 addition & 1 deletion spec/features/get_latest_pact_badge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe "get latest pact badge" do

before do
PactBroker.configuration.enable_badge_resources = true
PactBroker.configuration.enable_public_badge_access = true
TestDataBuilder.new
.create_consumer('consumer')
.create_provider('provider')
Expand Down
2 changes: 1 addition & 1 deletion spec/features/get_latest_tagged_pact_badge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe "get latest tagged pact badge" do

before do
PactBroker.configuration.enable_badge_resources = true
PactBroker.configuration.enable_public_badge_access = true
PactBroker.configuration.shields_io_base_url = nil
TestDataBuilder.new
.create_consumer('consumer')
Expand Down
2 changes: 1 addition & 1 deletion spec/features/get_latest_untagged_pact_badge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe "get latest untagged pact badge" do

before do
PactBroker.configuration.enable_badge_resources = true
PactBroker.configuration.enable_public_badge_access = true
PactBroker.configuration.shields_io_base_url = nil
TestDataBuilder.new
.create_consumer('consumer')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Renderers
before do
ENV['BACKUP_TZ'] = ENV['TZ']
ENV['TZ'] = "Australia/Melbourne"
PactBroker.configuration.enable_badge_resources = true
PactBroker.configuration.enable_public_badge_access = true
end

after do
Expand Down
47 changes: 32 additions & 15 deletions spec/lib/pact_broker/api/resources/badge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,49 @@ module Resources
let(:path) { "/pacts/provider/provider/consumer/consumer/latest/badge" }
let(:params) { {} }

before do
allow(PactBroker::Pacts::Service).to receive(:find_latest_pact).and_return(pact)
allow(PactBroker::Verifications::Service).to receive(:find_latest_verification_for).and_return(verification)
allow(PactBroker::Badges::Service).to receive(:pact_verification_badge).and_return("badge")
allow(PactBroker::Verifications::Status).to receive(:new).and_return(verification_status)
end

let(:pact) { instance_double("PactBroker::Domain::Pact", consumer: consumer, provider: provider) }
let(:consumer) { double('consumer') }
let(:provider) { double('provider') }
let(:verification) { double("verification") }
let(:verification_status) { instance_double("PactBroker::Verifications::Status", to_sym: :verified) }


subject { get path, params, {'HTTP_ACCEPT' => 'image/svg+xml'}; last_response }

context "when enable_badge_resources is false" do
context "when enable_public_badge_access is false and the request is not authenticated" do
before do
PactBroker.configuration.enable_badge_resources = false
PactBroker.configuration.enable_public_badge_access = false
allow_any_instance_of(Badge).to receive(:authenticated?).and_return(false)
end

it "returns a 404" do
expect(subject.status).to eq 404
it "returns a 401" do
expect(subject.status).to eq 401
end
end

context "when enable_badge_resources is true" do
context "when enable_public_badge_access is false but the request is authenticated" do
before do
PactBroker.configuration.enable_badge_resources = true
allow(PactBroker::Pacts::Service).to receive(:find_latest_pact).and_return(pact)
allow(PactBroker::Verifications::Service).to receive(:find_latest_verification_for).and_return(verification)
allow(PactBroker::Badges::Service).to receive(:pact_verification_badge).and_return("badge")
allow(PactBroker::Verifications::Status).to receive(:new).and_return(verification_status)
PactBroker.configuration.enable_public_badge_access = false
allow_any_instance_of(Badge).to receive(:authenticated?).and_return(true)
end

let(:pact) { instance_double("PactBroker::Domain::Pact", consumer: consumer, provider: provider) }
let(:consumer) { double('consumer') }
let(:provider) { double('provider') }
let(:verification) { double("verification") }
let(:verification_status) { instance_double("PactBroker::Verifications::Status", to_sym: :verified) }
it "returns a 200" do
expect(subject.status).to eq 200
end
end

context "when enable_public_badge_access is true" do

before do
PactBroker.configuration.enable_public_badge_access = true
end

it "retrieves the latest pact" do
expect(PactBroker::Pacts::Service).to receive(:find_latest_pact)
Expand Down

0 comments on commit 69ab586

Please sign in to comment.