main
1# frozen_string_literal: true
2
3RSpec.describe Saml::Kit::Builders::LogoutRequest do
4 subject { described_class.new(user, configuration: configuration) }
5
6 let(:user) { User.new(name_id: name_id) }
7 let(:name_id) { SecureRandom.uuid }
8 let(:configuration) do
9 Saml::Kit::Configuration.new do |config|
10 config.generate_key_pair_for(use: :signing)
11 end
12 end
13
14 it 'produces the expected xml' do
15 travel_to 1.second.from_now
16 subject.id = Xml::Kit::Id.generate
17 subject.destination = FFaker::Internet.http_url
18 subject.issuer = FFaker::Internet.http_url
19 subject.name_id_format = Saml::Kit::Namespaces::TRANSIENT
20
21 result = subject.to_xml
22 xml_hash = Hash.from_xml(result)
23
24 expect(xml_hash['LogoutRequest']['ID']).to eql(subject.id)
25 expect(xml_hash['LogoutRequest']['Version']).to eql('2.0')
26 expect(xml_hash['LogoutRequest']['IssueInstant']).to eql(Time.now.utc.iso8601)
27 expect(xml_hash['LogoutRequest']['Destination']).to eql(subject.destination)
28
29 expect(xml_hash['LogoutRequest']['Issuer']).to eql(subject.issuer)
30 expect(xml_hash['LogoutRequest']['NameID']).to eql(name_id)
31 expect(result).to have_xpath("//samlp:LogoutRequest//saml:NameID[@Format=\"#{subject.name_id_format}\"]")
32 end
33
34 it 'includes a signature by default' do
35 xml_hash = Hash.from_xml(subject.to_xml)
36 expect(xml_hash['LogoutRequest']['Signature']).to be_present
37 end
38
39 it 'excludes a signature' do
40 subject.embed_signature = false
41 xml_hash = Hash.from_xml(subject.to_xml)
42 expect(xml_hash['LogoutRequest']['Signature']).to be_nil
43 end
44
45 it 'builds a LogoutRequest' do
46 travel_to 1.second.from_now
47 result = subject.build
48 expect(result).to be_instance_of(Saml::Kit::LogoutRequest)
49 expect(result.to_xml).to eql(subject.to_xml)
50 end
51end