Skip to content

Commit

Permalink
Rescue errors parsing voice OTP encrypted code
Browse files Browse the repository at this point in the history
**Why**: If someone tries to make a request with a bogus encrypted code,
it should not cause the app to blow up with a 500 error.
  • Loading branch information
monfresh committed Mar 3, 2018
1 parent 9dc9f1f commit 01c50e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/voice/otp_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def code
return if encrypted_code.blank?

cipher.decrypt(encrypted_code)
rescue StandardError
nil
end

def message
Expand Down
11 changes: 11 additions & 0 deletions spec/controllers/voice/otp_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
end
end

context 'with an invalid encrypted_code in the URL' do
let(:encrypted_code) { '%25' }

it 'renders a blank 400' do
action

expect(response).to be_bad_request
expect(response.body).to be_empty
end
end

context 'with an encrypted_code in the URL' do
render_views

Expand Down

0 comments on commit 01c50e6

Please sign in to comment.