-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logging for contact information updates (#12398)
* Add logging for contact information updates * Add more logging locations and start tweaking tests * Add expiration to test * Move logging and tests to profile base controller * Please rubocop * Remove duplicate logging * Remove duplicate logging * Move files back * Remove unnecessary file * Make rubocop happy
- Loading branch information
1 parent
badd7f1
commit bce8975
Showing
5 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
modules/mobile/spec/controllers/profile_base_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require_relative '../support/sis_session_helper' | ||
require_relative '../support/iam_session_helper' | ||
require_relative '../support/matchers/json_schema_matcher' | ||
|
||
RSpec.shared_examples 'sso logging' do |type| | ||
describe "#{type} logging" do | ||
before do | ||
allow(Rails.logger).to receive(:warn) | ||
|
||
if type == :sis | ||
@new_headers = sis_headers | ||
else | ||
@new_headers = iam_headers | ||
iam_sign_in | ||
end | ||
end | ||
|
||
it 'logs after create' do | ||
request.headers.merge! @new_headers | ||
post :create | ||
|
||
log_name = nil | ||
log_value = nil | ||
|
||
expect(Rails.logger).to have_received(:warn) do |name, value| | ||
log_name = name | ||
log_value = value.to_json | ||
end | ||
|
||
expect(log_name).to eq('Mobile::V0::ProfileBaseController#create request completed') | ||
expect(log_value).to match_json_schema('sso_log') | ||
end | ||
|
||
it 'logs after update' do | ||
request.headers.merge! @new_headers | ||
put :update, params: { | ||
id: 1 | ||
} | ||
|
||
log_name = nil | ||
log_value = nil | ||
|
||
expect(Rails.logger).to have_received(:warn) do |name, value| | ||
log_name = name | ||
log_value = value.to_json | ||
end | ||
|
||
expect(log_name).to eq('Mobile::V0::ProfileBaseController#update request completed') | ||
expect(log_value).to match_json_schema('sso_log') | ||
end | ||
|
||
it 'logs after destroy' do | ||
request.headers.merge! @new_headers | ||
delete :destroy, params: { | ||
id: 1 | ||
} | ||
|
||
log_name = nil | ||
log_value = nil | ||
|
||
expect(Rails.logger).to have_received(:warn) do |name, value| | ||
log_name = name | ||
log_value = value.to_json | ||
end | ||
|
||
expect(log_name).to eq('Mobile::V0::ProfileBaseController#destroy request completed') | ||
expect(log_value).to match_json_schema('sso_log') | ||
end | ||
end | ||
end | ||
|
||
RSpec.describe Mobile::V0::ProfileBaseController, type: :controller do | ||
include JsonSchemaMatchers | ||
|
||
controller do | ||
def create | ||
head :ok | ||
end | ||
|
||
def update | ||
head :ok | ||
end | ||
|
||
def destroy | ||
head :ok | ||
end | ||
end | ||
|
||
include_examples 'sso logging', :iam | ||
include_examples 'sso logging', :sis | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"required": [ | ||
"user_uuid", | ||
"sso_cookie_contents", | ||
"request_host" | ||
], | ||
"properties": { | ||
"user_uuid": { | ||
"type": "string" | ||
}, | ||
"sso_cookie_contents": { | ||
"type": "object", | ||
"required": [ | ||
"patientIcn", | ||
"signIn", | ||
"credential_used", | ||
"expirationTime" | ||
], | ||
"properties": { | ||
"patientIcn": { | ||
"type": "string" | ||
}, | ||
"signIn": { | ||
"type": "object", | ||
"required": [ | ||
"serviceName", | ||
"authBroker" | ||
], | ||
"properties": { | ||
"serviceName": { | ||
"type": "string" | ||
}, | ||
"clientId": { | ||
"type": "string" | ||
}, | ||
"authBroker": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"credential_used": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"request_host": { | ||
"type": "string" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module SISSessionHelper | ||
def sis_access_token | ||
@sis_access_token ||= create(:access_token) | ||
end | ||
|
||
def sis_bearer_token | ||
@sis_bearer_token ||= SignIn::AccessTokenJwtEncoder.new(access_token: sis_access_token).perform | ||
end | ||
|
||
def sis_user | ||
@sis_user ||= create(:user, :api_auth, uuid: sis_access_token.user_uuid) | ||
end | ||
|
||
def sis_headers(additional_headers = nil) | ||
headers = { | ||
'Authorization' => "Bearer #{sis_bearer_token}", | ||
'X-Key-Inflection' => 'camel', | ||
'Authentication-Method' => 'SIS' | ||
} | ||
headers.merge!(additional_headers) if additional_headers | ||
headers | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include SISSessionHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters