Commit 5dc6608

mo <mo@mokhan.ca>
2018-03-12 00:49:06
parse status message from saml Response.
1 parent fbfb862
lib/saml/kit/respondable.rb
@@ -24,6 +24,11 @@ module Saml
         at_xpath('./*/samlp:Status/samlp:StatusCode/@Value').try(:value)
       end
 
+      # Returns the /Status/StatusMessage
+      def status_message
+        at_xpath('./*/samlp:Status/samlp:StatusMessage').try(:text)
+      end
+
       # Returns the /InResponseTo attribute.
       def in_response_to
         at_xpath('./*/@InResponseTo').try(:value)
spec/fixtures/no_nameid.saml_response.erb
@@ -1,4 +1,4 @@
-<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Destination="<%= fetch(:destination, 'https://www.example.com/acs') %>" ID="_d2b481a92e895f1436189403b7d5ccd1" InResponseTo="<%= fetch(:in_response_to, "_4db60150-227a-439b-a686-e7c57a9b5f9a") %>" IssueInstant="<%= issue_instant.iso8601 %>" Version="2.0">
+<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Destination="<%= fetch(:destination, 'https://www.example.com') %>" ID="_d2b481a92e895f1436189403b7d5ccd1" InResponseTo="<%= fetch(:in_response_to, "_4db60150-227a-439b-a686-e7c57a9b5f9a") %>" IssueInstant="<%= issue_instant.iso8601 %>" Version="2.0">
   <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"><%= fetch(:issuer, 'https://www.example.com') %></saml2:Issuer>
   <saml2p:Status>
     <saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"></saml2p:StatusCode>
spec/fixtures/requester_error.saml_response.erb
@@ -0,0 +1,7 @@
+<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" ID="<%= Xml::Kit::Id.generate %>" InResponseTo="<%= Xml::Kit::Id.generate %>" IssueInstant="<%= fetch(:issue_instant, Time.now).iso8601 %>" Destination="<%= fetch(:destination, 'https://www.example.com') %>" Version="2.0">
+  <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"><%= fetch(:issuer, 'https://www.example.com') %></saml2:Issuer>
+  <saml2p:Status>
+    <saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Requester"></saml2p:StatusCode>
+    <saml2p:StatusMessage><%= fetch(:status_message, "Invalid message signature") %></saml2p:StatusMessage>
+  </saml2p:Status>
+</saml2p:Response>
spec/saml/kit/response_spec.rb
@@ -560,6 +560,13 @@ XML
       subject = described_class.new(xml)
       expect(subject.name_id).to be_nil
     end
+
+    it 'parses a response with a status code of Requester' do
+      message = FFaker::Lorem.sentence
+      subject = described_class.new(expand_template('requester_error.saml_response', status_message: message))
+      expect(subject.status_code).to eql(Saml::Kit::Namespaces::REQUESTER_ERROR)
+      expect(subject.status_message).to eql(message)
+    end
   end
 
   describe '#build' do