Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/api/irs_attempts_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def timestamp
timestamp_param = params.permit(:timestamp)[:timestamp]
return nil if timestamp_param.nil?

Time.strptime(timestamp_param, '%Y-%m-%dT%H:%M:%S%z')
date_fmt = timestamp_param.include?('.') ? '%Y-%m-%dT%H:%M:%S.%N%z' : '%Y-%m-%dT%H:%M:%S%z'

Time.strptime(timestamp_param, date_fmt)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hokay, so. I wanted to accommodate both timestamp formats (what everything we built is using, and what the IRS is sending). This felt like the easiest way to accommodate that -- just check for a literal dot.

We could do a more elegant regexp, or potentially nested exception handling -- catch ArgumentError and try again with the other format, potentially catching it again, but that felt gross. This seemed least bad, but I wouldn't put this on my resume as a shining example of the best code I've ever written.

rescue ArgumentError
nil
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/irs_attempts_api/envelope_encryptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.encrypt(data:, timestamp:, public_key:)
formatted_time = formatted_timestamp(timestamp)

filename =
"FCI-#{IdentityConfig.store.irs_attempt_api_csp_id}_#{formatted_time}_#{digest}.dat.gz.hex"
"FCI-Logingov_#{formatted_time}_#{digest}.dat.gz.hex"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was "LOGIN.gov".

The IRS wanted it to be "Logingov" because they worried that the ".gov" would be treated as a file extension. I don't think we need to accommodate a variable CSP ID, so I just hardcoded it. The "FCI-" portion is already hardcoded.


Result.new(
filename: filename,
Expand Down
9 changes: 9 additions & 0 deletions spec/controllers/api/irs_attempts_api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
end
end

context 'with a timestamp including a fractional second' do
let(:timestamp) { '2022-11-08T18:00:00.000Z' }

it 'accepts the timestamp as valid' do
post :create, params: { timestamp: timestamp }
expect(response.status).to eq(200)
end
end

it 'renders a 404 if disabled' do
allow(IdentityConfig.store).to receive(:irs_attempt_api_enabled).and_return(false)

Expand Down