main
 1RSpec.describe "Metadata" do
 2  it 'consumes metadata' do
 3    raw_xml = <<-XML
 4<?xml version="1.0" encoding="UTF-8"?>
 5<EntityDescriptor entityID="https://www.example.com/metadata" 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" ID="_50643868-c737-40c8-a30d-b5dc7f3c69d9">
 6  <IDPSSODescriptor WantAuthnRequestsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
 7    <NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:persistent</NameIDFormat>
 8    <SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://www.example.com/login"/>
 9  </IDPSSODescriptor>
10  <SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
11    <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</NameIDFormat>
12    <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://www.example.com/consume" index="0" isDefault="true"/>
13  </SPSSODescriptor>
14</EntityDescriptor>
15    XML
16
17    metadata = Saml::Kit::Metadata.from(raw_xml)
18    expect(metadata.entity_id).to eql('https://www.example.com/metadata')
19  end
20
21  it 'produces metadata for a service provider and identity provider' do
22    metadata = Saml::Kit::Metadata.build do |builder|
23      builder.contact_email = 'hi@example.com'
24      builder.organization_name = "Acme, Inc"
25      builder.organization_url = 'https://www.example.com'
26      builder.build_identity_provider do |x|
27        x.add_single_sign_on_service('https://www.example.com/login', binding: :http_post)
28        x.add_single_sign_on_service('https://www.example.com/login', binding: :http_redirect)
29        x.add_single_logout_service('https://www.example.com/logout', binding: :http_post)
30        x.name_id_formats = [ Saml::Kit::Namespaces::EMAIL_ADDRESS ]
31        x.attributes << :id
32        x.attributes << :email
33      end
34      builder.build_service_provider do |x|
35        x.add_assertion_consumer_service('https://www.example.com/consume', binding: :http_post)
36        x.add_single_logout_service('https://www.example.com/logout', binding: :http_post)
37      end
38    end
39    xml = metadata.to_xml(pretty: true)
40    expect(xml).to be_present
41    expect(xml).to have_xpath("//md:EntityDescriptor//md:IDPSSODescriptor")
42    expect(xml).to have_xpath("//md:EntityDescriptor//md:SPSSODescriptor")
43  end
44end