Skip to content

Commit

Permalink
Merge pull request #1770 from 18F/jmhooper-session-decrypt-error
Browse files Browse the repository at this point in the history
Raise on session decryption errors
  • Loading branch information
jmhooper authored Nov 6, 2017
2 parents 02e4fe4 + 18cbfa6 commit d6c27e5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/services/session_encryptor_error_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SessionEncryptorErrorHandler
def self.call(error, _sid)
raise error
end
end
1 change: 1 addition & 0 deletions config/initializers/session_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
key_prefix: "#{Figaro.env.domain_name}:session:",
url: Figaro.env.redis_url,
},
on_session_load_error: SessionEncryptorErrorHandler,
serializer: SessionEncryptor.new,
}

Expand Down
20 changes: 20 additions & 0 deletions spec/features/session/decryption_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rails_helper'

feature 'Session decryption' do
context 'when there is a session decryption error' do
it 'should raise an error and log the user out' do
sign_in_and_2fa_user

session_encryptor = Rails.application.config.session_options[:serializer]
allow(session_encryptor).to receive(:load).and_raise(Pii::EncryptionError)

expect { visit account_path }.to raise_error(Pii::EncryptionError)

allow(session_encryptor).to receive(:load).and_call_original
visit account_path

# Should redirect to root since the user has been logged out
expect(current_path).to eq(root_path)
end
end
end
File renamed without changes.
1 change: 1 addition & 0 deletions spec/features/users/sign_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
it 'redirects to root_path with user-friendly error message, not a 500 error' do
allow(FeatureManagement).to receive(:use_kms?).and_return(true)
stub_aws_kms_client_invalid_ciphertext
allow(SessionEncryptorErrorHandler).to receive(:call)

user = create(:user)
signin(user.email, 'invalid')
Expand Down

0 comments on commit d6c27e5

Please sign in to comment.