Commit 6b91400
Changed files (8)
lib
saml
kit
builders
spec
saml
bindings
builders
lib/saml/kit/builders/logout_response.rb
@@ -7,14 +7,13 @@ module Saml
attr_reader :request
attr_reader :configuration
- def initialize(user, request, configuration: Saml::Kit.configuration)
+ def initialize(request, configuration: Saml::Kit.configuration)
@configuration = configuration
@id = Id.generate
@issuer = configuration.issuer
@now = Time.now.utc
@request = request
@status_code = Namespaces::SUCCESS
- @user = user
@version = "2.0"
end
lib/saml/kit/logout_request.rb
@@ -1,5 +1,6 @@
module Saml
module Kit
+ # This class parses a LogoutRequest SAML document.
class LogoutRequest < Document
include Requestable
validates_presence_of :single_logout_service, if: :expected_type?
@@ -8,25 +9,34 @@ module Saml
super(xml, name: "LogoutRequest", configuration: configuration)
end
+ # Returns the NameID value.
def name_id
to_h[name]['NameID']
end
- def single_logout_service
- return if provider.nil?
- urls = provider.single_logout_services
- urls.first
- end
-
- def response_for(user, binding:, relay_state: nil)
- builder = Saml::Kit::LogoutResponse.builder(user, self) do |x|
+ # Generates a Serialized LogoutResponse using the encoding rules for the specified binding.
+ #
+ # @param binding [Symbol] The binding to use `:http_redirect` or `:http_post`.
+ # @param relay_state [Object] The RelayState to include in the RelayState param.
+ # @return [Array] Returns an array with a url and Hash of parameters to return to the requestor.
+ def response_for(binding:, relay_state: nil)
+ builder = Saml::Kit::LogoutResponse.builder(self) do |x|
yield x if block_given?
end
response_binding = provider.single_logout_service_for(binding: binding)
response_binding.serialize(builder, relay_state: relay_state)
end
+ # @deprecated Use {#Saml::Kit::Builders::LogoutRequest} instead of this.
Builder = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Saml::Kit::LogoutRequest::Builder', 'Saml::Kit::Builders::LogoutRequest')
+
+ private
+
+ def single_logout_service
+ return if provider.nil?
+ urls = provider.single_logout_services
+ urls.first
+ end
end
end
end
spec/saml/bindings/http_post_spec.rb
@@ -58,9 +58,8 @@ RSpec.describe Saml::Kit::Bindings::HttpPost do
end
it 'returns a SAMLResponse for a LogoutResponse' do
- user = double(:user, name_id_for: SecureRandom.uuid)
request = instance_double(Saml::Kit::AuthenticationRequest, id: SecureRandom.uuid)
- builder = Saml::Kit::LogoutResponse.builder_class.new(user, request, configuration: configuration)
+ builder = Saml::Kit::LogoutResponse.builder_class.new(request, configuration: configuration)
url, saml_params = subject.serialize(builder, relay_state: relay_state)
expect(url).to eql(location)
spec/saml/bindings/http_redirect_spec.rb
@@ -95,9 +95,8 @@ RSpec.describe Saml::Kit::Bindings::HttpRedirect do
end
it 'deserializes the SAMLResponse to a LogoutResponse' do
- user = double(:user, name_id_for: SecureRandom.uuid, assertion_attributes_for: [])
request = double(:request, id: SecureRandom.uuid, provider: provider, assertion_consumer_service_url: FFaker::Internet.http_url, name_id_format: Saml::Kit::Namespaces::PERSISTENT, issuer: FFaker::Internet.http_url)
- url, _ = subject.serialize(Saml::Kit::LogoutResponse.builder(user, request))
+ url, _ = subject.serialize(Saml::Kit::LogoutResponse.builder(request))
result = subject.deserialize(query_params_from(url))
expect(result).to be_instance_of(Saml::Kit::LogoutResponse)
end
spec/saml/builders/logout_response_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
RSpec.describe Saml::Kit::Builders::LogoutResponse do
- subject { described_class.new(user, request) }
+ subject { described_class.new(request) }
let(:user) { double(:user, name_id_for: SecureRandom.uuid) }
let(:request) { Saml::Kit::Builders::LogoutRequest.new(user).build }
let(:issuer) { FFaker::Internet.http_url }
spec/saml/logout_request_spec.rb
@@ -130,7 +130,6 @@ RSpec.describe Saml::Kit::LogoutRequest do
end
describe "#response_for" do
- let(:user) { double(:user, name_id_for: SecureRandom.uuid) }
let(:provider) do
Saml::Kit::IdentityProviderMetadata.build do |builder|
builder.add_single_logout_service(FFaker::Internet.uri("https"), binding: :http_post)
@@ -140,7 +139,7 @@ RSpec.describe Saml::Kit::LogoutRequest do
it 'serializes a logout response for a particular user' do
allow(subject).to receive(:provider).and_return(provider)
- _, saml_params = subject.response_for(user, binding: :http_post)
+ _, saml_params = subject.response_for(binding: :http_post)
response_binding = provider.single_logout_service_for(binding: :http_post)
result = response_binding.deserialize(saml_params)
expect(result).to be_instance_of(Saml::Kit::LogoutResponse)
spec/examples_spec.rb
@@ -191,7 +191,7 @@ RSpec.describe "Examples" do
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(user, binding: :http_post)
+ 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
README.md
@@ -229,12 +229,11 @@ generate a response from the request.
```ruby
idp = Saml::Kit::IdentityProviderMetadata.new(xml)
-user = User.new(id: SecureRandom.uuid, email: "hello@example.com")
raw_params = Hash[uri.query.split("&").map { |x| x.split("=", 2) }].symbolize_keys
binding = idp.single_logout_service_for(binding: :http_post)
saml_request = binding.deserialize(raw_params)
-url, saml_params = saml_request.response_for(user, binding: :http_post)
+url, saml_params = saml_request.response_for(binding: :http_post)
puts [url, saml_params].inspect
# ["https://www.example.com/logout", {"SAMLResponse"=>"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48TG9nb3V0UmVzcG9uc2UgeG1sbnM9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpwcm90b2NvbCIgSUQ9Il9kZDA2YmY5MC04ODI2LTQ5ZTMtYmYxNS1jYzAxMWJkNzU3NGEiIFZlcnNpb249IjIuMCIgSXNzdWVJbnN0YW50PSIyMDE3LTEyLTE5VDA1OjQyOjQyWiIgRGVzdGluYXRpb249Imh0dHBzOi8vd3d3LmV4YW1wbGUuY29tL2xvZ291dCIgSW5SZXNwb25zZVRvPSJfYmVhZjJiN2ItMDlmNC00ZmFkLWJkYmYtOWQ0ZDc1N2I5ZDU0Ij48SXNzdWVyIHhtbG5zPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6YXNzZXJ0aW9uIi8+PFN0YXR1cz48U3RhdHVzQ29kZSBWYWx1ZT0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOnN0YXR1czpTdWNjZXNzIi8+PC9TdGF0dXM+PC9Mb2dvdXRSZXNwb25zZT4="}]
```