Skip to content

Commit

Permalink
Whoops, didn't know that OneLogin::RubySaml::Atrributes values have t…
Browse files Browse the repository at this point in the history
…o be arrays
  • Loading branch information
Alex Dolski committed Jan 24, 2024
1 parent 76f240c commit efb1917
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions app/models/affiliation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ def self.from_omniauth(info)
if info # this will be nil when using the OmniAuth developer strategy
# Explanation of this logic:
# https://uofi.app.box.com/notes/801448983786?s=5k6iiozlhp5mui5b4vrbskn3pu968j8r
if info.multi(ITRUST_AFFILIATION_ATTRIBUTE).include?("staff") ||
info.multi(ITRUST_AFFILIATION_ATTRIBUTE).include?("allied")
if info[ITRUST_AFFILIATION_ATTRIBUTE].include?("staff") ||
info[ITRUST_AFFILIATION_ATTRIBUTE].include?("allied")
key = FACULTY_STAFF_KEY
elsif info.multi(ITRUST_AFFILIATION_ATTRIBUTE).include?("student")
if %w(1G 1V 1M 1L).include?(info.multi(ITRUST_LEVEL_CODE_ATTRIBUTE))
elsif info[ITRUST_AFFILIATION_ATTRIBUTE].include?("student")
if %w(1G 1V 1M 1L).include?(info[ITRUST_LEVEL_CODE_ATTRIBUTE])
key = GRADUATE_STUDENT_KEY
elsif info.multi(ITRUST_LEVEL_CODE_ATTRIBUTE) == "1U"
elsif info[ITRUST_LEVEL_CODE_ATTRIBUTE] == "1U"
key = UNDERGRADUATE_STUDENT_KEY
end
if %w(PHD CAS).include?(info.multi(ITRUST_PROGRAM_CODE_ATTRIBUTE).upcase)
if %w(PHD CAS).include?(info[ITRUST_PROGRAM_CODE_ATTRIBUTE].upcase)
key = PHD_STUDENT_KEY
elsif info.multi(ITRUST_PROGRAM_CODE_ATTRIBUTE).present?
elsif info[ITRUST_PROGRAM_CODE_ATTRIBUTE].present?
key = MASTERS_STUDENT_KEY
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/department.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Department < ApplicationRecord
# @return [Department]
#
def self.from_omniauth(attrs)
name = attrs.multi(ITRUST_DEPARTMENT_CODE_ATTRIBUTE)
name = attrs[ITRUST_DEPARTMENT_CODE_ATTRIBUTE]
Department.new(name: name)
end

Expand Down
28 changes: 14 additions & 14 deletions test/models/affiliation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class AffiliationTest < ActiveSupport::TestCase
student" do
attrs = OneLogin::RubySaml::Attributes.new({
Affiliation::ITRUST_AFFILIATION_ATTRIBUTE => %w[student person phone],
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => "",
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => "1U"
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => [""],
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => ["1U"]
})
affiliation = Affiliation.from_omniauth(attrs)
assert_equal Affiliation::UNDERGRADUATE_STUDENT_KEY, affiliation.key
Expand All @@ -17,8 +17,8 @@ class AffiliationTest < ActiveSupport::TestCase
student" do
attrs = OneLogin::RubySaml::Attributes.new({
Affiliation::ITRUST_AFFILIATION_ATTRIBUTE => %w[student person phone],
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => "",
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => "1V"
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => [""],
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => ["1V"]
})
affiliation = Affiliation.from_omniauth(attrs)
assert_equal Affiliation::GRADUATE_STUDENT_KEY, affiliation.key
Expand All @@ -28,8 +28,8 @@ class AffiliationTest < ActiveSupport::TestCase
student" do
attrs = OneLogin::RubySaml::Attributes.new({
Affiliation::ITRUST_AFFILIATION_ATTRIBUTE => %w[student person phone],
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => "something",
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => "1V"
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => ["something"],
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => ["1V"]
})
affiliation = Affiliation.from_omniauth(attrs)
assert_equal Affiliation::MASTERS_STUDENT_KEY, affiliation.key
Expand All @@ -38,8 +38,8 @@ class AffiliationTest < ActiveSupport::TestCase
test "from_omniauth() returns a correct instance for a UIUC Ph.D student" do
attrs = OneLogin::RubySaml::Attributes.new({
Affiliation::ITRUST_AFFILIATION_ATTRIBUTE => %w[student person phone],
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => "PHD",
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => ""
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => ["PHD"],
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => [""]
})
affiliation = Affiliation.from_omniauth(attrs)
assert_equal Affiliation::PHD_STUDENT_KEY, affiliation.key
Expand All @@ -48,8 +48,8 @@ class AffiliationTest < ActiveSupport::TestCase
test "from_omniauth() returns a correct instance for a UIUC staff member" do
attrs = OneLogin::RubySaml::Attributes.new({
Affiliation::ITRUST_AFFILIATION_ATTRIBUTE => %w[staff person phone],
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => nil,
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => nil
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => [nil],
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => [nil]
})
affiliation = Affiliation.from_omniauth(attrs)
assert_equal Affiliation::FACULTY_STAFF_KEY, affiliation.key
Expand All @@ -58,17 +58,17 @@ class AffiliationTest < ActiveSupport::TestCase
test "from_omniauth() returns nil for an unrecognized affiliation" do
attrs = OneLogin::RubySaml::Attributes.new({
Affiliation::ITRUST_AFFILIATION_ATTRIBUTE => %w[bogus cats dogs],
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => "",
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => "1U"
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => [""],
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => ["1U"]
})
assert_nil Affiliation.from_omniauth(attrs)
end

test "from_omniauth() returns nil for an unrecognized level code" do
attrs = OneLogin::RubySaml::Attributes.new({
Affiliation::ITRUST_AFFILIATION_ATTRIBUTE => %w[student cats dogs],
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => "",
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => "bogus"
Affiliation::ITRUST_PROGRAM_CODE_ATTRIBUTE => [""],
Affiliation::ITRUST_LEVEL_CODE_ATTRIBUTE => ["bogus"]
})
assert_nil Affiliation.from_omniauth(attrs)
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/department_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DepartmentTest < ActiveSupport::TestCase

test "from_omniauth() returns a correct instance" do
attrs = OneLogin::RubySaml::Attributes.new({
Department::ITRUST_DEPARTMENT_CODE_ATTRIBUTE => "bugs"
Department::ITRUST_DEPARTMENT_CODE_ATTRIBUTE => ["bugs"]
})
dept = Department.from_omniauth(attrs)
assert_equal "bugs", dept.name
Expand Down

0 comments on commit efb1917

Please sign in to comment.