Skip to content

Commit

Permalink
feat: allow public access to matrix badge
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 6, 2019
1 parent f95db01 commit 18a7f0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pact_broker/basic_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class BasicAuth
GET = 'GET'.freeze
OPTIONS = 'OPTIONS'.freeze
HEAD = 'HEAD'.freeze
BADGE_PATH = %r{^/pacts/provider/[^/]+/consumer/.*/badge(?:\.[A-Za-z]+)?$}.freeze
PACT_BADGE_PATH = %r{^/pacts/provider/[^/]+/consumer/.*/badge(?:\.[A-Za-z]+)?$}.freeze
MATRIX_BADGE_PATH = %r{^/matrix/provider/[^/]+/latest/[^/]+/consumer/[^/]+/latest/[^/]+/badge(?:\.[A-Za-z]+)?$}.freeze
HEARTBEAT_PATH = "/diagnostic/status/heartbeat".freeze

def initialize(app, write_user_username, write_user_password, read_user_username, read_user_password, allow_public_access_to_heartbeat)
Expand Down Expand Up @@ -51,7 +52,7 @@ def use_basic_auth?(env)
end

def allow_public_access(env)
env[PATH_INFO] =~ BADGE_PATH || is_heartbeat_and_public_access_allowed?(env)
env[PATH_INFO] =~ PACT_BADGE_PATH || env[PATH_INFO] =~ MATRIX_BADGE_PATH || is_heartbeat_and_public_access_allowed?(env)
end

def is_heartbeat_and_public_access_allowed?(env)
Expand Down
13 changes: 11 additions & 2 deletions spec/basic_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,19 @@
end
end

context "when requesting a badge" do
context "when requesting a pact badge" do
context "when no credentials are used" do
it "allows GET" do
get "pacts/provider/foo/consumer/bar/badge"
get "/pacts/provider/foo/consumer/bar/badge"
expect(last_response.status).to eq 200
end
end
end

context "when requesting a matrix badge" do
context "when no credentials are used" do
it "allows GET" do
get "/matrix/provider/foo/latest/dev/consumer/bar/latest/dev/badge"
expect(last_response.status).to eq 200
end
end
Expand Down

0 comments on commit 18a7f0e

Please sign in to comment.