Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose NameID Format on SloLogoutrequest #420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/onelogin/ruby-saml/slo_logoutrequest.rb
Expand Up @@ -66,6 +66,18 @@ def name_id

alias_method :nameid, :name_id

# @return [String] Gets the NameID Format of the Logout Request.
#
def name_id_format
@name_id_node ||= REXML::XPath.first(document, "/p:LogoutRequest/a:NameID", { "p" => PROTOCOL, "a" => ASSERTION })
@name_id_format ||=
if @name_id_node && @name_id_node.attribute("Format")
@name_id_node.attribute("Format").value
end
end

alias_method :nameid_format, :name_id_format

# @return [String|nil] Gets the ID attribute from the Logout Request. if exists.
#
def id
Expand Down
4 changes: 4 additions & 0 deletions test/logout_requests/slo_request_with_name_id_format.xml
@@ -0,0 +1,4 @@
<samlp:LogoutRequest Version='2.0' ID='_c0348950-935b-0131-1060-782bcb56fcaa' xmlns:samlp='urn:oasis:names:tc:SAML:2.0:protocol' IssueInstant='2014-03-21T19:20:13'>
<saml:Issuer xmlns:saml='urn:oasis:names:tc:SAML:2.0:assertion'>https://app.onelogin.com/saml/metadata/SOMEACCOUNT</saml:Issuer>
<saml:NameID xmlns:saml='urn:oasis:names:tc:SAML:2.0:assertion' Format='urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'>someone@example.org</saml:NameID>
</samlp:LogoutRequest>
8 changes: 8 additions & 0 deletions test/slo_logoutrequest_test.rb
Expand Up @@ -91,6 +91,14 @@ class RubySamlTest < Minitest::Test
end
end

describe "#nameid_format" do
let(:logout_request) { OneLogin::RubySaml::SloLogoutrequest.new(logout_request_document_with_name_id_format) }

it "extract the format attribute of the name id element" do
assert_equal "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress", logout_request.nameid_format
end
end

describe "#issuer" do
it "return the issuer inside the logout request" do
assert_equal "https://app.onelogin.com/saml/metadata/SOMEACCOUNT", logout_request.issuer
Expand Down
9 changes: 9 additions & 0 deletions test/test_helper.rb
Expand Up @@ -183,6 +183,15 @@ def logout_request_document
@logout_request_document
end

def logout_request_document_with_name_id_format
unless @logout_request_document_with_name_id_format
xml = read_logout_request("slo_request_with_name_id_format.xml")
deflated = Zlib::Deflate.deflate(xml, 9)[2..-5]
@logout_request_document_with_name_id_format = Base64.encode64(deflated)
end
@logout_request_document_with_name_id_format
end

def logout_request_xml_with_session_index
@logout_request_xml_with_session_index ||= File.read(File.join(File.dirname(__FILE__), 'logout_requests', 'slo_request_with_session_index.xml'))
end
Expand Down