From ccae363a43c9199ab00bb983f11607bd3bd01803 Mon Sep 17 00:00:00 2001 From: Morten Primdahl Date: Fri, 10 Jun 2011 12:43:35 -0700 Subject: [PATCH] Do not raise when no attributes are given --- lib/onelogin/saml/response.rb | 2 ++ test/ruby-saml_test.rb | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/onelogin/saml/response.rb b/lib/onelogin/saml/response.rb index a814ae7a6..40c4688f9 100644 --- a/lib/onelogin/saml/response.rb +++ b/lib/onelogin/saml/response.rb @@ -50,6 +50,8 @@ def attributes result = {} stmt_element = REXML::XPath.first(document, "/p:Response/a:Assertion/a:AttributeStatement", { "p" => PROTOCOL, "a" => ASSERTION }) + return {} if stmt_element.nil? + stmt_element.elements.each do |attr_element| name = attr_element.attributes["Name"] value = attr_element.elements.first.text diff --git a/test/ruby-saml_test.rb b/test/ruby-saml_test.rb index 35f099ff8..9e8b6af81 100644 --- a/test/ruby-saml_test.rb +++ b/test/ruby-saml_test.rb @@ -38,7 +38,7 @@ class RubySamlTest < Test::Unit::TestCase response = Onelogin::Saml::Response.new(response_document_3) assert !response.name_id.nil? end - + should "check time conditions" do response = Onelogin::Saml::Response.new(response_document) assert !response.check_conditions @@ -111,6 +111,11 @@ class RubySamlTest < Test::Unit::TestCase response = Onelogin::Saml::Response.new(response_document_3) assert_equal "someone@example.com", response.attributes["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"] end + + should "not raise on responses without attributes" do + response = Onelogin::Saml::Response.new(response_document_4) + assert_equal Hash.new, response.attributes + end end context "#session_expires_at" do