Skip to content

Commit

Permalink
Fix SAML name extractor for students (#1148)
Browse files Browse the repository at this point in the history
* Use name assertions for students

* Update test
  • Loading branch information
RichDom2185 committed Aug 11, 2024
1 parent 67ba014 commit c2f659a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/cadet/auth/providers/saml/nusstu_assertion_extractor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ defmodule Cadet.Auth.Providers.NusstuAssertionExtractor do
end

def get_name(assertion) do
Map.get(assertion.attributes, "samaccountname")
first_name = Map.get(assertion.attributes, "givenname")
last_name = Map.get(assertion.attributes, "surname")
"#{first_name} #{last_name}"
end
end
12 changes: 10 additions & 2 deletions test/cadet/auth/providers/saml/nusstu_assertion_extractor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ defmodule Cadet.Auth.Providers.NusstuAssertionExtractorTest do
alias Cadet.Auth.Providers.NusstuAssertionExtractor, as: Testee

@username "JohnT"
@assertion %{attributes: %{"samaccountname" => @username}}
@firstname "John"
@lastname "Tan"
@assertion %{
attributes: %{
"samaccountname" => @username,
"givenname" => @firstname,
"surname" => @lastname
}
}

test "success" do
assert @username == Testee.get_username(@assertion)
assert @username == Testee.get_name(@assertion)
assert @firstname <> " " <> @lastname == Testee.get_name(@assertion)
end
end

0 comments on commit c2f659a

Please sign in to comment.