Skip to content

Commit 18a7f0e

Browse files
committed
feat: allow public access to matrix badge
1 parent f95db01 commit 18a7f0e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Diff for: pact_broker/basic_auth.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ class BasicAuth
44
GET = 'GET'.freeze
55
OPTIONS = 'OPTIONS'.freeze
66
HEAD = 'HEAD'.freeze
7-
BADGE_PATH = %r{^/pacts/provider/[^/]+/consumer/.*/badge(?:\.[A-Za-z]+)?$}.freeze
7+
PACT_BADGE_PATH = %r{^/pacts/provider/[^/]+/consumer/.*/badge(?:\.[A-Za-z]+)?$}.freeze
8+
MATRIX_BADGE_PATH = %r{^/matrix/provider/[^/]+/latest/[^/]+/consumer/[^/]+/latest/[^/]+/badge(?:\.[A-Za-z]+)?$}.freeze
89
HEARTBEAT_PATH = "/diagnostic/status/heartbeat".freeze
910

1011
def initialize(app, write_user_username, write_user_password, read_user_username, read_user_password, allow_public_access_to_heartbeat)
@@ -51,7 +52,7 @@ def use_basic_auth?(env)
5152
end
5253

5354
def allow_public_access(env)
54-
env[PATH_INFO] =~ BADGE_PATH || is_heartbeat_and_public_access_allowed?(env)
55+
env[PATH_INFO] =~ PACT_BADGE_PATH || env[PATH_INFO] =~ MATRIX_BADGE_PATH || is_heartbeat_and_public_access_allowed?(env)
5556
end
5657

5758
def is_heartbeat_and_public_access_allowed?(env)

Diff for: spec/basic_auth_spec.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,19 @@
4545
end
4646
end
4747

48-
context "when requesting a badge" do
48+
context "when requesting a pact badge" do
4949
context "when no credentials are used" do
5050
it "allows GET" do
51-
get "pacts/provider/foo/consumer/bar/badge"
51+
get "/pacts/provider/foo/consumer/bar/badge"
52+
expect(last_response.status).to eq 200
53+
end
54+
end
55+
end
56+
57+
context "when requesting a matrix badge" do
58+
context "when no credentials are used" do
59+
it "allows GET" do
60+
get "/matrix/provider/foo/latest/dev/consumer/bar/latest/dev/badge"
5261
expect(last_response.status).to eq 200
5362
end
5463
end

0 commit comments

Comments
 (0)