diff --git a/app/models/concerns/calnet_authentication.rb b/app/models/concerns/calnet_authentication.rb index dcf1f498..eff849f4 100644 --- a/app/models/concerns/calnet_authentication.rb +++ b/app/models/concerns/calnet_authentication.rb @@ -57,7 +57,7 @@ def auth_params_from(auth) # Raise [Error::CalnetError] if any required attributes are missing def verify_calnet_attributes!(auth_extra) affiliations = affiliations_from(auth_extra) - raise_missing_calnet_attribute_error(auth_extra, ['berkeleyEduAffiliations']) if affiliations.blank? + return log_missing_calnet_attribute(auth_extra, ['berkeleyEduAffiliations']) if affiliations.blank? required_attributes = required_attributes_for(affiliations) @@ -67,15 +67,14 @@ def verify_calnet_attributes!(auth_extra) return if missing.empty? - raise_missing_calnet_attribute_error(auth_extra, missing) + log_missing_calnet_attribute(auth_extra, missing) end - def raise_missing_calnet_attribute_error(auth_extra, missing) + def log_missing_calnet_attribute(auth_extra, missing) missing_attrs = "Expected CalNet attribute(s) not found (case-sensitive): #{missing.join(', ')}." actual_calnet_keys = auth_extra.keys.reject { |k| k.start_with?('duo') }.sort - msg = "#{missing_attrs} The actual CalNet attributes: #{actual_calnet_keys.join(', ')}. The user is #{auth_extra['displayName']}" - Rails.logger.error(msg) - raise Error::CalnetError, msg + msg = "#{missing_attrs} The actual CalNet attributes: #{actual_calnet_keys.join(', ')}. The user is #{auth_extra['uid']}" + Rails.logger.info(msg) end def affiliations_from(auth_extra) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 86f6ed98..768d4f49 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -21,7 +21,7 @@ expect { User.from_omniauth(auth) }.to raise_error(Error::InvalidAuthProviderError) end - it 'rejects calnet when a required schema attribute is missing or renamed' do + it 'logs a warning when a required schema attribute is missing or renamed' do auth = { 'provider' => 'calnet', 'extra' => { @@ -43,9 +43,10 @@ actual = %w[berkeleyEduAffiliations berkeleyEduAlternatid berkeleyEduCSID berkeleyEduIsMemberOf berkeleyEduUCPathID departmentNumber displayName employeeNumber givenName surname uid] # rubocop:disable Layout/LineLength - msg = "Expected CalNet attribute(s) not found (case-sensitive): #{missing.join(', ')}. The actual CalNet attributes: #{actual.join(', ')}. The user is expected display name" + msg = "Expected CalNet attribute(s) not found (case-sensitive): #{missing.join(', ')}. The actual CalNet attributes: #{actual.join(', ')}. The user is expected UID" # rubocop:enable Layout/LineLength - expect { User.from_omniauth(auth) }.to raise_error(Error::CalnetError, msg) + expect(Rails.logger).to receive(:info).with(msg) + User.from_omniauth(auth) end it 'populates a User object' do @@ -198,7 +199,7 @@ expect { User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra }) }.not_to raise_error end - it 'rejects student-affiliated users if berkeleyEduStuID is missing' do + it 'logs missing berkeleyEduStuID for student-affiliated users' do auth_extra = { 'berkeleyEduAffiliations' => ['STUDENT-TYPE-REGISTERED'], 'berkeleyEduCSID' => 'cs123', @@ -211,10 +212,11 @@ 'uid' => 'student1' } - expect { User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra }) }.to raise_error(Error::CalnetError) + expect(Rails.logger).to receive(:info).with(/berkeleyEduStuID/) + User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra }) end - it 'rejects employee-affiliated users if employeeNumber is missing' do + it 'logs missing employeeNumber for employee-affiliated users' do auth_extra = { 'berkeleyEduAffiliations' => ['EMPLOYEE-TYPE-STAFF'], 'berkeleyEduCSID' => 'cs123', @@ -228,7 +230,8 @@ 'uid' => 'staff1' } - expect { User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra }) }.to raise_error(Error::CalnetError) + expect(Rails.logger).to receive(:info).with(/employeeNumber/) + User.from_omniauth({ 'provider' => 'calnet', 'extra' => auth_extra }) end end