Commit 90c7e3b
Changed files (3)
lib
saml
kit
builders
templates
spec
saml
builders
lib/saml/kit/builders/templates/metadata.builder
@@ -1,4 +1,5 @@
#xml.instruct!
#xml.EntityDescriptor entity_descriptor_options do
#end
+render identity_provider, xml: xml
render service_provider, xml: xml
lib/saml/kit/builders/metadata.rb
@@ -8,12 +8,12 @@ module Saml
attr_reader :entity_id
attr_reader :configuration
attr_reader :service_provider
+ attr_reader :identity_provider
def initialize(configuration: Saml::Kit.configuration)
@id = Id.generate
@entity_id = configuration.issuer
@configuration = configuration
- @service_provder = nil
end
def build_service_provider
@@ -22,6 +22,12 @@ module Saml
end
end
+ def build_identity_provider
+ @identity_provider = Saml::Kit::IdentityProviderMetadata.builder(configuration: configuration) do |x|
+ yield x if block_given?
+ end
+ end
+
def build
Saml::Kit::Metadata.from(to_xml)
end
spec/saml/builders/metadata_spec.rb
@@ -1,12 +1,12 @@
RSpec.describe Saml::Kit::Builders::Metadata do
describe ".build" do
subject { Saml::Kit::Metadata }
- let(:acs_url) { FFaker::Internet.uri("https") }
+ let(:url) { FFaker::Internet.uri("https") }
it 'builds metadata for a service provider' do
result = subject.build do |builder|
builder.build_service_provider do |x|
- x.add_assertion_consumer_service(acs_url, binding: :http_post)
+ x.add_assertion_consumer_service(url, binding: :http_post)
end
end
@@ -14,7 +14,21 @@ RSpec.describe Saml::Kit::Builders::Metadata do
expect(hash_result['EntityDescriptor']).to be_present
expect(hash_result['EntityDescriptor']['SPSSODescriptor']).to be_present
expect(hash_result['EntityDescriptor']['SPSSODescriptor']['AssertionConsumerService']).to be_present
- expect(hash_result['EntityDescriptor']['SPSSODescriptor']['AssertionConsumerService']['Location']).to eql(acs_url)
+ expect(hash_result['EntityDescriptor']['SPSSODescriptor']['AssertionConsumerService']['Location']).to eql(url)
+ end
+
+ it 'builds metadata for an identity provider' do
+ result = subject.build do |builder|
+ builder.build_identity_provider do |x|
+ x.add_single_sign_on_service(url, binding: :http_post)
+ end
+ end
+
+ hash_result = Hash.from_xml(result.to_xml)
+ expect(hash_result['EntityDescriptor']).to be_present
+ expect(hash_result['EntityDescriptor']['IDPSSODescriptor']).to be_present
+ expect(hash_result['EntityDescriptor']['IDPSSODescriptor']['SingleSignOnService']).to be_present
+ expect(hash_result['EntityDescriptor']['IDPSSODescriptor']['SingleSignOnService']['Location']).to eql(url)
end
end
end