Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Validate cert only if present

Oliver Günthera4bcc206bce9
diff --git a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
index 6ac62cb2271..2ddd4762aa7 100644
--- a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
+++ b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
@@ -55,7 +55,7 @@ module Saml
validates_presence_of :idp_cert,
if: -> { model.idp_cert_changed? }
validate :idp_cert_is_valid,
- if: -> { model.idp_cert_changed? }
+ if: -> { model.idp_cert_changed? && model.idp_cert.present? }
attribute :authn_requests_signed
validate :authn_requests_signed_requires_cert
@@ -69,7 +69,7 @@ module Saml
model.loaded_idp_certificates.each do |cert|
if OneLogin::RubySaml::Utils.is_cert_expired(cert)
errors.add :certificate, :certificate_expired
- return
+ break
end
end
rescue OpenSSL::X509::CertificateError => e
diff --git a/modules/auth_saml/app/models/saml/provider/hash_builder.rb b/modules/auth_saml/app/models/saml/provider/hash_builder.rb
index c208b94e53f..68954119e0b 100644
--- a/modules/auth_saml/app/models/saml/provider/hash_builder.rb
+++ b/modules/auth_saml/app/models/saml/provider/hash_builder.rb
@@ -23,16 +23,20 @@ module Saml
return { idp_cert_fingerprint: }
end
- certificates = loaded_idp_certificates.map(&:to_pem)
- if certificates.count > 1
- {
- idp_cert_multi: {
- signing: certificates,
- encryption: certificates
+ if idp_cert.present?
+ certificates = loaded_idp_certificates.map(&:to_pem)
+ if certificates.count > 1
+ {
+ idp_cert_multi: {
+ signing: certificates,
+ encryption: certificates
+ }
}
- }
+ else
+ { idp_cert: certificates.first }
+ end
else
- { idp_cert: certificates.first }
+ {}
end
end