diff --git a/lib/pact_broker/api/renderers/html_pact_renderer.rb b/lib/pact_broker/api/renderers/html_pact_renderer.rb
index c1ca69ac8..12bf2df8c 100644
--- a/lib/pact_broker/api/renderers/html_pact_renderer.rb
+++ b/lib/pact_broker/api/renderers/html_pact_renderer.rb
@@ -50,7 +50,8 @@ def head
def pact_metadata
"
"
end
- def badge_list_items
- if PactBroker.configuration.enable_public_badge_access
+ def badge_list_item
"
-
-
-
"
- end
+ end
+
+ def badge_markdown_item
+ "
+
+ "
end
def badge_markdown
- "[![#{@pact.consumer.name}/#{@pact.provider.name} Pact Status](#{badge_url})](#{badge_target_url})"
+ warning = if badges_protected?
+ "If the broker is protected by authentication, set `enable_public_badge_access` to true in the configuration to enable badges to be embedded in a markdown file.\n"
+ else
+ ""
+ end
+ "#{warning}[![#{@pact.consumer.name}/#{@pact.provider.name} Pact Status](#{badge_url})](#{badge_target_url})"
+ end
+
+ def badges_protected?
+ !PactBroker.configuration.enable_public_badge_access
end
def base_url
diff --git a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb
index 80bb0a26b..0d1695f17 100644
--- a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb
+++ b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb
@@ -60,6 +60,16 @@ module Renderers
expect(subject).to include "[![Consumer/Provider Pact Status](http://badge)](http://base)"
end
+ context "when enable_public_badge_access is false" do
+ before do
+ PactBroker.configuration.enable_public_badge_access = false
+ end
+
+ it "renders a message instructing the user to turn public access on" do
+ expect(subject).to include "set `enable_public_badge_access` to true in the configuration"
+ end
+ end
+
context "when the content is not a valid pact, but is still JSON" do
before do
allow(pact).to receive(:content_hash).and_return(content_hash)