Skip to content

Commit

Permalink
feat(auth): cascade UI before diagnostic api and broker api
Browse files Browse the repository at this point in the history
Need to perform UI auth logic before API auth logic in SAAS broker
  • Loading branch information
bethesque committed Oct 16, 2017
1 parent a60d4f5 commit 1b95461
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/pact_broker/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ def configure_database_connection
def prepare_app
configure_middleware

# need this first so UI login logic is performed before API login logic
@cascade_apps << build_ui

if configuration.enable_diagnostic_endpoints
@cascade_apps << build_diagnostic
end

@cascade_apps << build_ui
@cascade_apps << build_api
end

Expand Down
25 changes: 25 additions & 0 deletions spec/lib/pact_broker/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@ def call(env)
expect(last_response.headers["WWW-Authenticate"]).to eq "Basic realm=\"Protected\""
end
end

context "ordering of calls" do
class TestAuth1
def initialize app; end
def call env; end
end

class TestAuth2 < TestAuth1; end

before do
allow(TestAuth1).to receive(:new).and_return(test_auth_1)
allow(TestAuth2).to receive(:new).and_return(test_auth_2)
end

let(:test_auth_1) { instance_double('TestAuth1', call: [404, {}, []]) }
let(:test_auth_2) { instance_double('TestAuth2', call: [404, {}, []]) }

it "calls the UI auth before the API auth" do
expect(test_auth_1).to receive(:call).ordered
expect(test_auth_2).to receive(:call).ordered
app.use_ui_auth TestAuth1
app.use_api_auth TestAuth2
get "/", nil, {'HTTP_ACCEPT' => 'text/html'}
end
end
end

describe "authenticate" do
Expand Down

0 comments on commit 1b95461

Please sign in to comment.