Skip to content

Commit

Permalink
spec & mock updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bramleyjl committed Dec 17, 2024
1 parent 082452d commit b51b540
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 91 deletions.
1 change: 0 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ map_services:
oauth_url: https://veteran.apps-staging.va.gov
client_cert_path: spec/fixtures/map/oauth.crt
client_key_path: spec/fixtures/map/oauth.key
provider_jwks_path: /sts/oauth/v1/jwks
sign_up_service_url: https://cerner.apps-staging.va.gov
sign_up_service_provisioning_api_key: abcd1234
secure_token_service:
Expand Down
2 changes: 1 addition & 1 deletion lib/map/security_token/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def client_cert_path
end

def provider_jwks_path
Settings.map_services.provider_jwks_path
'/sts/oauth/v1/jwks'
end

def service_name
Expand Down
8 changes: 5 additions & 3 deletions lib/map/security_token/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def token(application:, icn:, cache: true)
Rails.logger.error("#{config.logging_prefix} token failed, parsing error", application:, icn:,
context: e.message)
raise e
rescue JWT::DecodeError => e
Rails.logger.error("#{config.logging_prefix} token failed, JWT decode error", application:, icn:,
context: e.message)
raise e
rescue Common::Client::Errors::ClientError => e
parse_and_raise_error(e, icn, application)
rescue Common::Exceptions::GatewayTimeout => e
Expand Down Expand Up @@ -63,9 +67,7 @@ def parse_response(response, application, icn)
access_token: response_body['access_token'],
expiration: Time.zone.now + response_body['expires_in']
}
rescue JWT::VerificationError => e
message = "#{config.logging_prefix} token failed, JWT verification error"
Rails.logger.error(message, application:, icn:)
rescue JWT::DecodeError => e
raise e
rescue => e
message = "#{config.logging_prefix} token failed, response unknown"
Expand Down
18 changes: 9 additions & 9 deletions spec/lib/map/security_token/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@
end
end

context 'when response is malformed',
vcr: { cassette_name: 'map/security_token_service_200_malformed_response' } do
let(:expected_error) { Common::Client::Errors::ParsingError }
let(:expected_error_message) { "unexpected token at 'Not valid JSON'" }
let(:expected_logger_message) { "#{log_prefix} token failed, parsing error" }
let(:expected_log_values) { { application:, icn:, context: expected_error_message } }

it 'raises an gateway timeout error and creates a log' do
context 'when response is an invalid token',
vcr: { cassette_name: 'map/security_token_service_200_invalid_token' } do
let(:expected_error) { JWT::DecodeError }
let(:expected_error_context) { 'Signature verification failed' }
let(:expected_logger_message) { "#{log_prefix} token failed, JWT decode error" }
let(:expected_log_values) { { application:, icn:, context: expected_error_context } }

it 'raises a JWT Decode error and creates a log' do
expect(Rails.logger).to receive(:error).with(expected_logger_message, expected_log_values)
expect { subject }.to raise_exception(expected_error, expected_error_message)
expect { subject }.to raise_exception(expected_error, expected_error_context)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/map/sign_up/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
let(:expected_log_message) { "#{log_prefix} agreements accept success, icn: #{icn}" }

before do
Timecop.freeze(Time.zone.local(2023, 1, 1, 12, 0, 0))
Timecop.freeze(Time.zone.local(2024, 9, 1, 12, 0, 0))
allow(Rails.logger).to receive(:info)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/requests/v0/map_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
end
end

context 'when MAP STS client returns a token with an invalid duration',
vcr: { cassette_name: 'map/security_token_service_200_response_invalid_token' } do
context 'when MAP STS client returns an invalid token',
vcr: { cassette_name: 'map/security_token_service_200_invalid_token' } do
it 'responds with error details in response body' do
call_endpoint
expect(JSON.parse(response.body)).to eq(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b51b540

Please sign in to comment.