Commit 1d1cd4e

mo <mo.khan@gmail.com>
2017-11-17 23:58:17
Response < Document
1 parent 6c8d6cf
Changed files (2)
lib/saml/kit/document.rb
@@ -10,7 +10,7 @@ module Saml
       def initialize(xml, name:)
         @content = xml
         @name = name
-        @xml_hash = Hash.from_xml(xml)
+        @xml_hash = Hash.from_xml(xml) || {}
       end
 
       def to_h
lib/saml/kit/response.rb
@@ -1,11 +1,7 @@
 module Saml
   module Kit
-    class Response
-      PROTOCOL_XSD = File.expand_path("./xsd/saml-schema-protocol-2.0.xsd", File.dirname(__FILE__)).freeze
-      include ActiveModel::Validations
-      include XsdValidatable
-
-      attr_reader :content, :name, :request_id
+    class Response < Document
+      attr_reader :request_id
       validates_presence_of :content
       validates_presence_of :id
       validate :must_have_valid_signature
@@ -20,10 +16,8 @@ module Saml
       validate :must_match_issuer
 
       def initialize(xml, request_id: nil)
-        @content = xml
-        @xml_hash = Hash.from_xml(xml) || {}
-        @name = 'Response'
         @request_id = request_id
+        super(xml, name: "Response")
       end
 
       def query_string_parameter
@@ -68,14 +62,6 @@ module Saml
         to_h.fetch(name, {}).fetch('Version', {})
       end
 
-      def to_xml
-        content
-      end
-
-      def to_h
-        @xml_hash
-      end
-
       def certificate
         return unless signed?
         to_h.fetch(name, {}).fetch('Signature', {}).fetch('KeyInfo', {}).fetch('X509Data', {}).fetch('X509Certificate', nil)