Skip to content

Commit 7f6906a

Browse files
authored
updates SSOe & SiS Cerner cookie setting log (#27500)
* updates SSOe & SiS Cerner cookie setting log * spec updates
1 parent 46af18d commit 7f6906a

File tree

4 files changed

+74
-12
lines changed

4 files changed

+74
-12
lines changed

app/controllers/concerns/authentication_and_sso_concerns.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def set_cerner_eligibility_cookie
117117
}
118118

119119
Rails.logger.info('[SessionsController] Cerner Eligibility', eligible:, previous_value:, cookie_action: :set,
120-
icn: @current_user.icn)
120+
icn: @current_user.icn,
121+
cerner_limited: current_user.cerner_limited?)
121122
end
122123

123124
def set_session_expiration_header

app/services/sign_in/user_loader.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,18 @@ def validate_account_and_session
5757
end
5858

5959
def set_cerner_eligibility_cookie
60-
cookies.permanent[CERNER_ELIGIBLE_COOKIE_NAME] = {
61-
value: current_user.cerner_full?,
60+
cookie_name = CERNER_ELIGIBLE_COOKIE_NAME
61+
previous_value = ActiveModel::Type::Boolean.new.cast(cookies.signed[cookie_name] || cookies[cookie_name])
62+
eligible = current_user.cerner_full?
63+
64+
cookies.permanent[cookie_name] = {
65+
value: eligible,
6266
domain: IdentitySettings.sign_in.info_cookie_domain
6367
}
68+
69+
Rails.logger.info('[SignIn][UserLoader] Cerner Eligibility', eligible:, previous_value:, cookie_action: :set,
70+
icn: user_account.icn,
71+
cerner_limited: current_user.cerner_limited?)
6472
end
6573

6674
def user_attributes

spec/controllers/v1/sessions_controller_spec.rb

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -956,11 +956,16 @@ def expect_logger_msg(level, msg)
956956
let(:cerner_eligible_cookie) { 'CERNER_ELIGIBLE' }
957957
let(:expected_log_message) { '[SessionsController] Cerner Eligibility' }
958958
let(:previous_value) { nil }
959-
let(:expected_log_payload) { { eligible:, previous_value:, cookie_action: :set, icn: user.icn } }
959+
let(:cerner_limited) { false }
960+
let(:expected_log_payload) do
961+
{ eligible:, previous_value:, cookie_action: :set, icn: user.icn, cerner_limited: }
962+
end
960963

961964
before do
962965
SAMLRequestTracker.create(uuid: login_uuid, payload: { type: 'idme', application: 'some-applicaton' })
963966
allow(Rails.logger).to receive(:info)
967+
allow(IdentitySettings.sign_in).to receive(:info_cookie_domain).and_return('some-domain')
968+
allow_any_instance_of(User).to receive(:cerner_limited?).and_return(cerner_limited)
964969
end
965970

966971
context 'when the cerner eligible cookie is not present' do
@@ -971,12 +976,28 @@ def expect_logger_msg(level, msg)
971976
context 'when the user is cerner eligible' do
972977
let(:eligible) { true }
973978

974-
it 'sets the cookie and logs the cerner eligibility' do
975-
call_endpoint
979+
context 'and user is cerner_limited' do
980+
let(:cerner_limited) { true }
976981

977-
expect(response.headers['set-cookie']).to include('domain=some-domain')
978-
expect(cookies[cerner_eligible_cookie]).to eq(eligible.to_s)
979-
expect(Rails.logger).to have_received(:info).with(expected_log_message, expected_log_payload)
982+
it 'sets the cookie and logs the cerner eligibility' do
983+
call_endpoint
984+
985+
expect(response.headers['set-cookie']).to include('domain=some-domain')
986+
expect(cookies[cerner_eligible_cookie]).to eq(eligible.to_s)
987+
expect(Rails.logger).to have_received(:info).with(expected_log_message, expected_log_payload)
988+
end
989+
end
990+
991+
context 'and user is not cerner_limited' do
992+
let(:cerner_limited) { false }
993+
994+
it 'sets the cookie and logs the cerner eligibility' do
995+
call_endpoint
996+
997+
expect(response.headers['set-cookie']).to include('domain=some-domain')
998+
expect(cookies[cerner_eligible_cookie]).to eq(eligible.to_s)
999+
expect(Rails.logger).to have_received(:info).with(expected_log_message, expected_log_payload)
1000+
end
9801001
end
9811002
end
9821003

@@ -1001,10 +1022,22 @@ def expect_logger_msg(level, msg)
10011022
cookies[cerner_eligible_cookie] = true
10021023
end
10031024

1004-
it 'logs the cerner eligibility with the previous value' do
1005-
call_endpoint
1025+
context 'and user is cerner_limited' do
1026+
let(:cerner_limited) { true }
10061027

1007-
expect(Rails.logger).to have_received(:info).with(expected_log_message, expected_log_payload)
1028+
it 'logs the cerner eligibility with the previous value' do
1029+
call_endpoint
1030+
1031+
expect(Rails.logger).to have_received(:info).with(expected_log_message, expected_log_payload)
1032+
end
1033+
end
1034+
1035+
context 'and user is not cerner_limited' do
1036+
it 'logs the cerner eligibility with the previous value' do
1037+
call_endpoint
1038+
1039+
expect(Rails.logger).to have_received(:info).with(expected_log_message, expected_log_payload)
1040+
end
10081041
end
10091042
end
10101043

spec/services/sign_in/user_loader_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
let(:cookies) do
1111
hash = {}
1212
def hash.permanent = self
13+
def hash.signed = self
1314
hash
1415
end
1516

@@ -208,6 +209,7 @@ def hash.permanent = self
208209
allow(Settings.mhv.oh_facility_checks)
209210
.to receive(:pretransitioned_oh_facilities)
210211
.and_return(stub_cerner_facility_ids)
212+
allow(Rails.logger).to receive(:info)
211213
end
212214

213215
context 'fully eligible user' do
@@ -229,6 +231,15 @@ def hash.permanent = self
229231
expect(Identity::CernerProvisionerJob).to have_received(:perform_async)
230232
.with(user_icn, false, :sis)
231233
end
234+
235+
it 'logs the cerner eligibility with cerner_limited: false' do
236+
subject
237+
238+
expect(Rails.logger).to have_received(:info).with(
239+
'[SignIn][UserLoader] Cerner Eligibility',
240+
{ eligible: true, previous_value: nil, cookie_action: :set, icn: user_icn, cerner_limited: false }
241+
)
242+
end
232243
end
233244

234245
context 'messaging-only user' do
@@ -248,6 +259,15 @@ def hash.permanent = self
248259
expect(Identity::CernerProvisionerJob).to have_received(:perform_async)
249260
.with(user_icn, true, :sis)
250261
end
262+
263+
it 'logs the cerner eligibility with cerner_limited: true' do
264+
subject
265+
266+
expect(Rails.logger).to have_received(:info).with(
267+
'[SignIn][UserLoader] Cerner Eligibility',
268+
{ eligible: false, previous_value: nil, cookie_action: :set, icn: user_icn, cerner_limited: true }
269+
)
270+
end
251271
end
252272
end
253273

0 commit comments

Comments
 (0)