Skip to content

Commit

Permalink
Test authentication with profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkadel committed May 26, 2023
1 parent c185a73 commit 7e08a3b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
config.include Capybara::DSL
config.include Capybara::RSpecMatchers, type: :request
config.include Features::SessionHelpers, type: :feature
config.include Features::SessionHelpers, type: :system
config.include Devise::Test::IntegrationHelpers, type: :request

config.include ViewComponent::TestHelpers, type: :component
Expand Down
30 changes: 30 additions & 0 deletions spec/requests/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,34 @@
end
end
end

describe 'profiling authentication' do
let(:user) { FactoryBot.create(:user) }
before do
login_as(user)
allow(ApplicationController).to receive(:current_user).and_return(user)
end

context 'as a non-admin user' do
it 'does not authorize the user' do
allow(Rack::MiniProfiler).to receive(:authorize_request)
get '/'
expect(Rack::MiniProfiler).not_to have_received(:authorize_request)
end
end
context 'as an admin user' do
around do |example|
cached_admin_netids = ENV['ORANGELIGHT_ADMIN_NETIDS'] || ''
ENV['ORANGELIGHT_ADMIN_NETIDS'] = cached_admin_netids + " #{user.uid}"
example.run
ENV['ORANGELIGHT_ADMIN_NETIDS'] = cached_admin_netids
end

it 'authorizes the user' do
allow(Rack::MiniProfiler).to receive(:authorize_request)
get '/'
expect(Rack::MiniProfiler).to have_received(:authorize_request)
end
end
end
end

0 comments on commit 7e08a3b

Please sign in to comment.