Skip to content

Commit 1b95461

Browse files
committed
feat(auth): cascade UI before diagnostic api and broker api
Need to perform UI auth logic before API auth logic in SAAS broker
1 parent a60d4f5 commit 1b95461

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/pact_broker/app.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ def configure_database_connection
9292
def prepare_app
9393
configure_middleware
9494

95+
# need this first so UI login logic is performed before API login logic
96+
@cascade_apps << build_ui
97+
9598
if configuration.enable_diagnostic_endpoints
9699
@cascade_apps << build_diagnostic
97100
end
98101

99-
@cascade_apps << build_ui
100102
@cascade_apps << build_api
101103
end
102104

spec/lib/pact_broker/app_spec.rb

+25
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@ def call(env)
107107
expect(last_response.headers["WWW-Authenticate"]).to eq "Basic realm=\"Protected\""
108108
end
109109
end
110+
111+
context "ordering of calls" do
112+
class TestAuth1
113+
def initialize app; end
114+
def call env; end
115+
end
116+
117+
class TestAuth2 < TestAuth1; end
118+
119+
before do
120+
allow(TestAuth1).to receive(:new).and_return(test_auth_1)
121+
allow(TestAuth2).to receive(:new).and_return(test_auth_2)
122+
end
123+
124+
let(:test_auth_1) { instance_double('TestAuth1', call: [404, {}, []]) }
125+
let(:test_auth_2) { instance_double('TestAuth2', call: [404, {}, []]) }
126+
127+
it "calls the UI auth before the API auth" do
128+
expect(test_auth_1).to receive(:call).ordered
129+
expect(test_auth_2).to receive(:call).ordered
130+
app.use_ui_auth TestAuth1
131+
app.use_api_auth TestAuth2
132+
get "/", nil, {'HTTP_ACCEPT' => 'text/html'}
133+
end
134+
end
110135
end
111136

112137
describe "authenticate" do

0 commit comments

Comments
 (0)