Commit 2ae1e99
Changed files (8)
lib/saml/kit/assertion.rb
@@ -49,7 +49,7 @@ module Saml
private
def encrypted?
- @xml_hash['Response']['EncryptedAssertion'].present?
+ @xml_hash.fetch('Response', {}).fetch('EncryptedAssertion', nil).present?
end
def assertion
@@ -58,7 +58,7 @@ module Saml
Saml::Kit.logger.debug(decrypted)
Hash.from_xml(decrypted)['Assertion']
else
- @xml_hash['Response'].fetch('Assertion', {})
+ @xml_hash.fetch('Response', {}).fetch('Assertion', {})
end
end
lib/saml/kit/authentication_request.rb
@@ -3,8 +3,8 @@ module Saml
class AuthenticationRequest < Document
include Requestable
- def initialize(xml)
- super(xml, name: "AuthnRequest")
+ def initialize(xml, configuration: Saml::Kit.configuration)
+ super(xml, name: "AuthnRequest", configuration: configuration)
end
def assertion_consumer_service_url
lib/saml/kit/configuration.rb
@@ -12,8 +12,6 @@ module Saml
@registry = DefaultRegistry.new
@session_timeout = 3.hours
@logger = Logger.new(STDOUT)
- #generate_key_pair_for(use: :signing)
- #generate_key_pair_for(use: :encryption)
yield self if block_given?
end
lib/saml/kit/document.rb
@@ -12,9 +12,10 @@ module Saml
validate :must_be_expected_type
validate :must_be_valid_version
- attr_reader :content, :name
+ attr_reader :content, :name, :configuration
- def initialize(xml, name:)
+ def initialize(xml, name:, configuration: Saml::Kit.configuration)
+ @configuration = configuration
@content = xml
@name = name
@xml_hash = Hash.from_xml(xml) || {}
lib/saml/kit/response.rb
@@ -11,8 +11,7 @@ module Saml
def initialize(xml, request_id: nil, configuration: Saml::Kit.configuration)
@request_id = request_id
- @configuration = configuration
- super(xml, name: "Response")
+ super(xml, name: "Response", configuration: configuration)
end
def expired?
@@ -47,7 +46,7 @@ module Saml
return unless expected_type?
return unless success?
- unless audiences.include?(Saml::Kit.configuration.issuer)
+ unless audiences.include?(configuration.issuer)
errors[:audience] << error_message(:must_match_issuer)
end
end
lib/saml/kit/trustable.rb
@@ -30,7 +30,7 @@ module Saml
end
def provider
- Saml::Kit.registry.metadata_for(issuer)
+ configuration.registry.metadata_for(issuer)
end
def signature_verified!
spec/saml/authentication_request_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
RSpec.describe Saml::Kit::AuthenticationRequest do
- subject { described_class.new(raw_xml) }
+ subject { described_class.new(raw_xml, configuration: configuration) }
let(:id) { Saml::Kit::Id.generate }
let(:assertion_consumer_service_url) { "https://#{FFaker::Internet.domain_name}/acs" }
let(:issuer) { FFaker::Movie.title }
@@ -17,6 +17,11 @@ RSpec.describe Saml::Kit::AuthenticationRequest do
builder.destination = destination
end.to_xml
end
+ let(:configuration) do
+ Saml::Kit::Configuration.new do |config|
+ config.generate_key_pair_for(use: :signing)
+ end
+ end
it { expect(subject.issuer).to eql(issuer) }
it { expect(subject.id).to eql(id) }
@@ -29,13 +34,13 @@ RSpec.describe Saml::Kit::AuthenticationRequest do
let(:metadata) { instance_double(Saml::Kit::ServiceProviderMetadata) }
before :each do
- allow(Saml::Kit.configuration).to receive(:registry).and_return(registry)
+ allow(configuration).to receive(:registry).and_return(registry)
allow(registry).to receive(:metadata_for).and_return(metadata)
allow(metadata).to receive(:matches?).and_return(true)
end
it 'is valid when left untampered' do
- subject = described_class.new(raw_xml)
+ subject = described_class.new(raw_xml, configuration: configuration)
expect(subject).to be_valid
end
spec/saml/response_spec.rb
@@ -6,11 +6,13 @@ RSpec.describe Saml::Kit::Response do
let(:user) { double(:user, name_id_for: SecureRandom.uuid, assertion_attributes_for: { id: SecureRandom.uuid }) }
let(:registry) { instance_double(Saml::Kit::DefaultRegistry) }
let(:metadata) { instance_double(Saml::Kit::IdentityProviderMetadata) }
- subject { described_class.build(user, request) }
-
- before :each do
- allow(Saml::Kit.configuration).to receive(:registry).and_return(registry)
- allow(Saml::Kit.configuration).to receive(:issuer).and_return(request.issuer)
+ subject { described_class.build(user, request, configuration: configuration) }
+ let(:configuration) do
+ Saml::Kit::Configuration.new do |config|
+ config.issuer = request.issuer
+ config.registry = registry
+ config.generate_key_pair_for(use: :signing)
+ end
end
it 'is valid' do