Sha256: 4a500066a0728f42e2d8c6252691c89d8c8ebccf6533a029fcc46ad692736bb9

Contents?: true

Size: 1.79 KB

Versions: 24

Compression:

Stored size: 1.79 KB

Contents

require_relative './principal'

RSpec.describe "Logout Response" do
  let(:user) { Principal.new(id: SecureRandom.uuid, email: "hello@example.com") }

  it 'generates a logout response' do
    xml = Saml::Kit::Metadata.build_xml do |builder|
      builder.contact_email = 'hi@example.com'
      builder.organization_name = "Acme, Inc"
      builder.organization_url = 'https://www.example.com'
      builder.build_identity_provider do |x|
        x.add_single_sign_on_service('https://www.example.com/login', binding: :http_post)
        x.add_single_sign_on_service('https://www.example.com/login', binding: :http_redirect)
        x.add_single_logout_service('https://www.example.com/logout', binding: :http_post)
        x.name_id_formats = [ Saml::Kit::Namespaces::EMAIL_ADDRESS ]
        x.attributes << :id
        x.attributes << :email
      end
      builder.build_service_provider do |x|
        x.add_assertion_consumer_service('https://www.example.com/consume', binding: :http_post)
        x.add_single_logout_service('https://www.example.com/logout', binding: :http_post)
      end
    end

    idp = Saml::Kit::IdentityProviderMetadata.new(xml)
    url, saml_params = idp.logout_request_for(user, binding: :http_post)
    uri = URI.parse("#{url}?#{saml_params.map { |(x, y)| "#{x}=#{y}" }.join('&')}")

    raw_params = Hash[uri.query.split("&amp;").map { |x| x.split("=", 2) }].symbolize_keys

    binding = idp.single_logout_service_for(binding: :http_post)
    saml_request = binding.deserialize(raw_params)
    sp = Saml::Kit::ServiceProviderMetadata.new(xml)
    allow(saml_request).to receive(:provider).and_return(sp)
    url, saml_params = saml_request.response_for(binding: :http_post)
    expect(url).to eql("https://www.example.com/logout")
    expect(saml_params['SAMLResponse']).to be_present
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
saml-kit-1.3.0 spec/examples/logout_response_spec.rb
saml-kit-1.2.0 spec/examples/logout_response_spec.rb
saml-kit-1.1.0 spec/examples/logout_response_spec.rb
saml-kit-1.0.31 spec/examples/logout_response_spec.rb
saml-kit-1.0.30 spec/examples/logout_response_spec.rb
saml-kit-1.0.29 spec/examples/logout_response_spec.rb
saml-kit-1.0.28 spec/examples/logout_response_spec.rb
saml-kit-1.0.27 spec/examples/logout_response_spec.rb
saml-kit-1.0.26 spec/examples/logout_response_spec.rb
saml-kit-1.0.25 spec/examples/logout_response_spec.rb
saml-kit-1.0.24 spec/examples/logout_response_spec.rb
saml-kit-1.0.23 spec/examples/logout_response_spec.rb
saml-kit-1.0.22 spec/examples/logout_response_spec.rb
saml-kit-1.0.21 spec/examples/logout_response_spec.rb
saml-kit-1.0.20 spec/examples/logout_response_spec.rb
saml-kit-1.0.19 spec/examples/logout_response_spec.rb
saml-kit-1.0.18 spec/examples/logout_response_spec.rb
saml-kit-1.0.17 spec/examples/logout_response_spec.rb
saml-kit-1.0.16 spec/examples/logout_response_spec.rb
saml-kit-1.0.15 spec/examples/logout_response_spec.rb