Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/thread safe config - PR2 #2

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the "dynamic configuration via Proc" feature has been deprecated upstream, maybe we can simplify this and write:

certificate = configurator.x509_certificate

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll address this issue later, maybe with upstream

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
Loading