Skip to content

Commit

Permalink
MetadataBuilder uses custom configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
mzappino-noz committed Dec 9, 2024
1 parent 928ae6f commit 4679f33
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/saml_idp/metadata_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def raw_algorithm
private :raw_algorithm

def x509_certificate
certificate = SamlIdp.config.x509_certificate.is_a?(Proc) ? SamlIdp.config.x509_certificate.call : SamlIdp.config.x509_certificate
certificate = configurator.x509_certificate.is_a?(Proc) ? configurator.x509_certificate.call : configurator.x509_certificate
certificate
.to_s
.gsub(/-----BEGIN CERTIFICATE-----/,"")
Expand All @@ -163,7 +163,7 @@ def x509_certificate
alias_method :public_cert, :x509_certificate

def private_key
SamlIdp.config.secret_key
configurator.secret_key
end

def pv_key_password
Expand Down
31 changes: 31 additions & 0 deletions spec/lib/saml_idp/metadata_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,36 @@ module SamlIdp
subject.configurator.single_logout_service_redirect_location = 'https://example.com/saml/logout'
expect(subject.fresh).to match('<SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://example.com/saml/logout"/>')
end

context 'with custom configurator' do
let(:certificate) {'a certificate'}
let(:configurator) do SamlIdp::Configurator.new.tap do |c|
c.secret_key = 'a private key'
c.x509_certificate = certificate
end
end
subject { described_class.new(configurator) }

describe '.private_key' do
it 'returns the given private_key' do
expect(subject.private_key).to eq(configurator.secret_key)
end
end

describe '.x509_certificate' do
context 'with a given certificate string' do
it 'returns the given certificate' do
expect(subject.x509_certificate).to eq('a certificate')
end
end

context 'with a given certificate proc' do
let(:certificate) {Proc.new { "a certificate from proc"}}
it 'returns the given certificate' do
expect(subject.x509_certificate).to eq('a certificate from proc')
end
end
end
end
end
end

0 comments on commit 4679f33

Please sign in to comment.