Skip to content

Commit

Permalink
Add spec to cover PgHero basic auth
Browse files Browse the repository at this point in the history
We want to be sure PgHero is behind basic auth. This spec validates that
once the correct environment variables are set, PgHero will require
basic authentication.

We have to use the rack_test driver so we can use `basic_authorize` to
set the headers, rack_test is the default in RSpec/Capybara, but we have
explicitly set the driver just in case.
  • Loading branch information
mec committed Mar 21, 2024
1 parent baa4968 commit c847de8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/system/pghero_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'PGHero', driver: :rack_test do
describe 'access' do
context 'with the appropriate environment variables set' do
before do
allow(ENV).to receive(:[]).with('PGHERO_USERNAME').and_return('link')
allow(ENV).to receive(:[]).with('PGHERO_PASSWORD').and_return('hyrule')
end

it 'fails without the basic auth credentials' do
visit pg_hero_path

expect(status_code).to be 401
expect(page).to have_content 'HTTP Basic: Access denied.'
end

it 'succeeds with the credentials' do
# this will only work with the rack_test driver
page.driver.browser.basic_authorize 'link', 'hyrule'

visit pg_hero_path

expect(status_code).to be 200
expect(page).to have_link 'Overview'
end
end
end
end

0 comments on commit c847de8

Please sign in to comment.