Skip to content

Commit

Permalink
FFS-2175: Installed rack-mini-profiler (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
George Byers authored Dec 12, 2024
1 parent 320a795 commit e82fac4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ terraform.tfstate.backup
.vscode
/config/credentials/development.key
/app/config/credentials/master.key

/config/credentials/production.key

#Profiler
/profiler
6 changes: 5 additions & 1 deletion app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ gem "aws-sdk-rails"
gem "aws-sdk-s3"
gem "aws-actionmailer-ses"

# profiling
gem "rack-mini-profiler"
gem "stackprof"

# https://www.ruby-lang.org/en/news/2024/08/01/dos-rexml-cve-2024-41123/
gem "rexml", "~> 3.3.9"
gem "gpgme", "~> 2.0", ">= 2.0.12"
Expand Down Expand Up @@ -110,8 +114,8 @@ group :production do
# Add plugin for pg gem to support AWS RDS IAM
gem "pg-aws_rds_iam", "~> 0.5.0"
end

gem "devise", "~> 4.9"

gem "omniauth-rails_csrf_protection", "~> 1.0"
gem "omniauth-azure-activedirectory-v2"
gem "view_component"
Expand Down
5 changes: 5 additions & 0 deletions app/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ GEM
nio4r (~> 2.0)
racc (1.8.1)
rack (2.2.10)
rack-mini-profiler (3.3.1)
rack (>= 1.2.0)
rack-protection (3.2.0)
base64 (>= 0.1.0)
rack (~> 2.2, >= 2.2.4)
Expand Down Expand Up @@ -458,6 +460,7 @@ GEM
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
stackprof (0.2.26)
standard (1.39.2)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
Expand Down Expand Up @@ -556,6 +559,7 @@ DEPENDENCIES
pg-aws_rds_iam (~> 0.5.0)
premailer-rails
puma (~> 6.4.3)
rack-mini-profiler
rails (~> 7.1.5, >= 7.1.5.1)
rails-controller-testing
rails-erd (~> 1.7)
Expand All @@ -568,6 +572,7 @@ DEPENDENCIES
selenium-webdriver
sidekiq (~> 6.4)
sprockets-rails
stackprof
standard (~> 1.7)
stimulus-rails
timecop
Expand Down
12 changes: 12 additions & 0 deletions app/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base
around_action :switch_locale
before_action :add_newrelic_metadata
before_action :redirect_if_maintenance_mode
before_action :enable_mini_profiler_in_demo

rescue_from ActionController::InvalidAuthenticityToken do
redirect_to root_url, flash: { slim_alert: { type: "info", message_html: t("cbv.error_missing_token_html") } }
Expand All @@ -28,6 +29,7 @@ def site_config
end

private

def show_translate_button?
false
end
Expand All @@ -46,6 +48,16 @@ def current_site
@current_site ||= site_config[params[:site_id]]
end

def enable_mini_profiler_in_demo
return unless demo_mode?

Rack::MiniProfiler.authorize_request
end

def demo_mode?
ENV["DOMAIN_NAME"] == "verify-demo.navapbc.cloud"
end

protected

def pinwheel_for(cbv_flow)
Expand Down
28 changes: 28 additions & 0 deletions app/spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,32 @@ def test_action
expect(response.body).to eq('en')
end
end

describe '#enable_mini_profiler_in_demo' do
before do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("DOMAIN_NAME").and_return(domain_name)
routes.draw do
get 'test_action', to: 'anonymous#test_action'
end
end

context 'when in demo environment' do
let(:domain_name) { "verify-demo.navapbc.cloud" }

it 'authorizes mini profiler' do
expect(Rack::MiniProfiler).to receive(:authorize_request)
get :test_action
end
end

context 'when not in demo environment' do
let(:domain_name) { "snap-income-pilot.com" }

it 'does not authorize mini profiler' do
expect(Rack::MiniProfiler).not_to receive(:authorize_request)
get :test_action
end
end
end
end

0 comments on commit e82fac4

Please sign in to comment.