Commit 2d873ae

mo <mo@mokhan.ca>
2017-12-04 20:36:40
include organization into in service provider metadata.
1 parent b9abf39
Changed files (2)
lib/saml/kit/builders/service_provider_metadata.rb
@@ -3,6 +3,7 @@ module Saml
     module Builders
       class ServiceProviderMetadata
         attr_accessor :id, :entity_id, :acs_urls, :logout_urls, :name_id_formats, :sign
+        attr_accessor :organization_name, :organization_url, :contact_email
         attr_accessor :want_assertions_signed
 
         def initialize(configuration = Saml::Kit.configuration)
@@ -58,6 +59,14 @@ module Saml
                   xml.AssertionConsumerService Binding: item[:binding], Location: item[:location], index: index, isDefault: index == 0 ? true : false
                 end
               end
+              xml.Organization do
+                xml.OrganizationName organization_name, 'xml:lang': "en"
+                xml.OrganizationDisplayName organization_name, 'xml:lang': "en"
+                xml.OrganizationURL organization_url, 'xml:lang': "en"
+              end
+              xml.ContactPerson contactType: "technical" do
+                xml.Company "mailto:#{contact_email}"
+              end
             end
           end
         end
spec/saml/builders/service_provider_metadata_spec.rb
@@ -2,10 +2,16 @@ require 'spec_helper'
 
 RSpec.describe Saml::Kit::Builders::ServiceProviderMetadata do
   let(:assertion_consumer_service_url) { FFaker::Internet.http_url }
+  let(:email) { FFaker::Internet.email }
+  let(:org_name) { FFaker::Movie.title }
+  let(:url) { FFaker::Internet.uri("https") }
   let(:entity_id) { FFaker::Internet.uri("https") }
 
   it 'builds the service provider metadata' do
+    subject.contact_email = email
     subject.entity_id = entity_id
+    subject.organization_name = org_name
+    subject.organization_url = url
     subject.add_assertion_consumer_service(assertion_consumer_service_url, binding: :http_post)
     subject.name_id_formats = [
       Saml::Kit::Namespaces::PERSISTENT,
@@ -35,5 +41,10 @@ RSpec.describe Saml::Kit::Builders::ServiceProviderMetadata do
       Saml::Kit.configuration.stripped_signing_certificate,
       Saml::Kit.configuration.stripped_encryption_certificate,
     ])
+    expect(result['EntityDescriptor']['Organization']['OrganizationName']).to eql(org_name)
+    expect(result['EntityDescriptor']['Organization']['OrganizationDisplayName']).to eql(org_name)
+    expect(result['EntityDescriptor']['Organization']['OrganizationURL']).to eql(url)
+    expect(result['EntityDescriptor']['ContactPerson']['contactType']).to eql("technical")
+    expect(result['EntityDescriptor']['ContactPerson']['Company']).to eql("mailto:#{email}")
   end
 end