Skip to content

Commit f26f811

Browse files
logging missing attributes for calnet validatation, loggin uid instead of displayName (#33)
1 parent 12fdb9b commit f26f811

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

app/models/concerns/calnet_authentication.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def auth_params_from(auth)
5757
# Raise [Error::CalnetError] if any required attributes are missing
5858
def verify_calnet_attributes!(auth_extra)
5959
affiliations = affiliations_from(auth_extra)
60-
raise_missing_calnet_attribute_error(auth_extra, ['berkeleyEduAffiliations']) if affiliations.blank?
60+
return log_missing_calnet_attribute(auth_extra, ['berkeleyEduAffiliations']) if affiliations.blank?
6161

6262
required_attributes = required_attributes_for(affiliations)
6363

@@ -67,15 +67,14 @@ def verify_calnet_attributes!(auth_extra)
6767

6868
return if missing.empty?
6969

70-
raise_missing_calnet_attribute_error(auth_extra, missing)
70+
log_missing_calnet_attribute(auth_extra, missing)
7171
end
7272

73-
def raise_missing_calnet_attribute_error(auth_extra, missing)
73+
def log_missing_calnet_attribute(auth_extra, missing)
7474
missing_attrs = "Expected CalNet attribute(s) not found (case-sensitive): #{missing.join(', ')}."
7575
actual_calnet_keys = auth_extra.keys.reject { |k| k.start_with?('duo') }.sort
76-
msg = "#{missing_attrs} The actual CalNet attributes: #{actual_calnet_keys.join(', ')}. The user is #{auth_extra['displayName']}"
77-
Rails.logger.error(msg)
78-
raise Error::CalnetError, msg
76+
msg = "#{missing_attrs} The actual CalNet attributes: #{actual_calnet_keys.join(', ')}. The user is #{auth_extra['uid']}"
77+
Rails.logger.info(msg)
7978
end
8079

8180
def affiliations_from(auth_extra)

spec/models/user_spec.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
expect { User.from_omniauth(auth) }.to raise_error(Error::InvalidAuthProviderError)
2222
end
2323

24-
it 'rejects calnet when a required schema attribute is missing or renamed' do
24+
it 'logs a warning when a required schema attribute is missing or renamed' do
2525
auth = {
2626
'provider' => 'calnet',
2727
'extra' => {
@@ -43,9 +43,10 @@
4343
actual = %w[berkeleyEduAffiliations berkeleyEduAlternatid berkeleyEduCSID berkeleyEduIsMemberOf berkeleyEduUCPathID departmentNumber
4444
displayName employeeNumber givenName surname uid]
4545
# rubocop:disable Layout/LineLength
46-
msg = "Expected CalNet attribute(s) not found (case-sensitive): #{missing.join(', ')}. The actual CalNet attributes: #{actual.join(', ')}. The user is expected display name"
46+
msg = "Expected CalNet attribute(s) not found (case-sensitive): #{missing.join(', ')}. The actual CalNet attributes: #{actual.join(', ')}. The user is expected UID"
4747
# rubocop:enable Layout/LineLength
48-
expect { User.from_omniauth(auth) }.to raise_error(Error::CalnetError, msg)
48+
expect(Rails.logger).to receive(:info).with(msg)
49+
User.from_omniauth(auth)
4950
end
5051

5152
it 'populates a User object' do
@@ -198,7 +199,7 @@
198199
expect { User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra }) }.not_to raise_error
199200
end
200201

201-
it 'rejects student-affiliated users if berkeleyEduStuID is missing' do
202+
it 'logs missing berkeleyEduStuID for student-affiliated users' do
202203
auth_extra = {
203204
'berkeleyEduAffiliations' => ['STUDENT-TYPE-REGISTERED'],
204205
'berkeleyEduCSID' => 'cs123',
@@ -211,10 +212,11 @@
211212
'uid' => 'student1'
212213
}
213214

214-
expect { User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra }) }.to raise_error(Error::CalnetError)
215+
expect(Rails.logger).to receive(:info).with(/berkeleyEduStuID/)
216+
User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra })
215217
end
216218

217-
it 'rejects employee-affiliated users if employeeNumber is missing' do
219+
it 'logs missing employeeNumber for employee-affiliated users' do
218220
auth_extra = {
219221
'berkeleyEduAffiliations' => ['EMPLOYEE-TYPE-STAFF'],
220222
'berkeleyEduCSID' => 'cs123',
@@ -228,7 +230,8 @@
228230
'uid' => 'staff1'
229231
}
230232

231-
expect { User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra }) }.to raise_error(Error::CalnetError)
233+
expect(Rails.logger).to receive(:info).with(/employeeNumber/)
234+
User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra })
232235
end
233236
end
234237

0 commit comments

Comments
 (0)