Skip to content

Commit 5322d19

Browse files
authored
Merge pull request #555 from appbot/multi-cert-validation-error
Define 'soft' variable to prevent exception when doc cert is invalid
2 parents 24e90a3 + d0e117a commit 5322d19

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/xml_security.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def validate_document(idp_cert_fingerprint, soft = true, options = {})
241241
validate_signature(base64_cert, soft)
242242
end
243243

244-
def validate_document_with_cert(idp_cert)
244+
def validate_document_with_cert(idp_cert, soft = true)
245245
# get cert from response
246246
cert_element = REXML::XPath.first(
247247
self,

test/xml_security_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@ class XmlSecurityTest < Minitest::Test
395395
end
396396

397397
describe '#validate_document_with_cert' do
398+
describe 'with invalid document ' do
399+
describe 'when certificate is invalid' do
400+
let(:document_data) { read_response('response_with_signed_message_and_assertion.xml')
401+
.sub(/<ds:X509Certificate>.*<\/ds:X509Certificate>/, "<ds:X509Certificate>invalid<\/ds:X509Certificate>") }
402+
let(:document) { OneLogin::RubySaml::Response.new(document_data).document }
403+
let(:idp_cert) { OpenSSL::X509::Certificate.new(ruby_saml_cert_text) }
404+
405+
it 'is invalid' do
406+
refute document.validate_document_with_cert(idp_cert), 'Document should be invalid'
407+
end
408+
end
409+
end
410+
398411
describe 'with valid document ' do
399412
describe 'when response has cert' do
400413
let(:document_data) { read_response('response_with_signed_message_and_assertion.xml') }

0 commit comments

Comments
 (0)