Skip to content

Commit

Permalink
EVSS DependentsApplicationJob Form Encryption (#11520)
Browse files Browse the repository at this point in the history
* removes unrelated commits

* fixes KMS decryption & JSON parsing

* adds decryption spec
  • Loading branch information
John Bramley authored Jan 31, 2023
1 parent 3219095 commit 879d471
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/models/dependents_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,6 @@ def user_can_access_evss
end

def create_submission_job
EVSS::DependentsApplicationJob.perform_async(id, parsed_form, user.uuid)
EVSS::DependentsApplicationJob.perform_async(id, KmsEncrypted::Box.new.encrypt(parsed_form.to_json), user.uuid)
end
end
3 changes: 2 additions & 1 deletion app/workers/evss/dependents_application_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class DependentsApplicationJob
sidekiq_options retry: false

# rubocop:disable Metrics/MethodLength
def perform(app_id, form, user_uuid)
def perform(app_id, encrypted_form, user_uuid)
@app_id = app_id
form = JSON.parse(KmsEncrypted::Box.new.decrypt(encrypted_form))
user = User.find(user_uuid)
service = Dependents::Service.new(user)
cached_info = Dependents::RetrievedInfo.for_user(user)
Expand Down
31 changes: 23 additions & 8 deletions spec/jobs/evss/dependents_application_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,29 @@ def reload_dependents_application
end
end

it 'uses, then deletes a cache of user info' do
VCR.use_cassette(
'evss/dependents/all',
match_requests_on: %i[method uri body]
) do
expect_any_instance_of(EVSS::Dependents::RetrievedInfo).to receive(:body).once.and_call_original
expect_any_instance_of(EVSS::Dependents::RetrievedInfo).to receive(:delete).once.and_call_original
described_class.drain
context 'user info protection' do
before { allow_any_instance_of(KmsEncrypted::Box).to receive(:decrypt).and_return(dependents_application.form) }

it 'decrypts the encrypted user form argument' do
VCR.use_cassette(
'evss/dependents/all',
match_requests_on: %i[method uri body]
) do
expect_any_instance_of(KmsEncrypted::Box).to receive(:decrypt)
described_class.drain
reload_dependents_application
end
end

it 'uses, then deletes a cache of user info' do
VCR.use_cassette(
'evss/dependents/all',
match_requests_on: %i[method uri body]
) do
expect_any_instance_of(EVSS::Dependents::RetrievedInfo).to receive(:body).once.and_call_original
expect_any_instance_of(EVSS::Dependents::RetrievedInfo).to receive(:delete).once.and_call_original
described_class.drain
end
end
end
end
Expand Down

0 comments on commit 879d471

Please sign in to comment.