Commit e20f83d

mo <mo.khan@gmail.com>
2017-12-23 18:02:41
embed examples
1 parent e2ebfff
lib/saml/kit/authentication_request.rb
@@ -13,6 +13,10 @@ module Saml
     #      <saml:Issuer>Day of the Dangerous Cousins</saml:Issuer>
     #      <samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"/>
     #    </samlp:AuthnRequest>
+    #
+    # Example:
+    #
+    # {include:file:spec/examples/authentication_request_spec.rb}
     class AuthenticationRequest < Document
       include Requestable
 
lib/saml/kit/identity_provider_metadata.rb
@@ -26,6 +26,10 @@ module Saml
     #   puts metadata.to_xml
     #
     # For more details on generating metadata see {Saml::Kit::Metadata}.
+    #
+    # Example:
+    #
+    # {include:file:spec/examples/identity_provider_metadata_spec.rb}
     class IdentityProviderMetadata < Metadata
       def initialize(xml)
         super("IDPSSODescriptor", xml)
lib/saml/kit/service_provider_metadata.rb
@@ -1,5 +1,6 @@
 module Saml
   module Kit
+    # {include:file:spec/examples/service_provider_metadata_spec.rb}
     class ServiceProviderMetadata < Metadata
       def initialize(xml)
         super("SPSSODescriptor", xml)
spec/examples/service_provider_metadata_spec.rb
@@ -1,4 +1,19 @@
 RSpec.describe "Service Provider Metadata" do
+  it 'consumes service provider_metadata' do
+    raw_xml = <<-XML
+<?xml version="1.0" encoding="UTF-8"?>
+<EntityDescriptor entityID="myEntityId" xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
+  <SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
+    <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</NameIDFormat>
+  </SPSSODescriptor>
+</EntityDescriptor>
+    XML
+
+    metadata = Saml::Kit::ServiceProviderMetadata.new(raw_xml)
+    expect(metadata.entity_id).to eql('myEntityId')
+    expect(metadata.name_id_formats).to match_array([Saml::Kit::Namespaces::PERSISTENT])
+  end
+
   it 'produces service provider metadata' do
     metadata = Saml::Kit::Metadata.build do |builder|
       builder.contact_email = 'hi@example.com'