Skip to content

Commit ca03435

Browse files
authored
Merge pull request #400 from Adam21e/validate_with_cert
validate_document_with_cert uses local cert when no cert in response
2 parents 967a2f5 + bfbae64 commit ca03435

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/xml_security.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,11 @@ def validate_document_with_cert(idp_cert)
260260
# check saml response cert matches provided idp cert
261261
if idp_cert.to_pem != cert.to_pem
262262
return false
263+
end
264+
else
265+
base64_cert = Base64.encode64(idp_cert.to_pem)
263266
end
264-
validate_signature(base64_cert, true)
265-
end
267+
validate_signature(base64_cert, true)
266268
end
267269

268270
def validate_signature(base64_cert, soft = true)

test/xml_security_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,5 +393,29 @@ class XmlSecurityTest < Minitest::Test
393393
end
394394
end
395395
end
396+
397+
describe '#validate_document_with_cert' do
398+
describe 'with valid document ' do
399+
describe 'when response has cert' do
400+
let(:document_data) { read_response('response_with_signed_message_and_assertion.xml') }
401+
let(:document) { OneLogin::RubySaml::Response.new(document_data).document }
402+
let(:idp_cert) { OpenSSL::X509::Certificate.new(ruby_saml_cert_text) }
403+
let(:fingerprint) { '4b68c453c7d994aad9025c99d5efcf566287fe8d' }
404+
405+
it 'is valid' do
406+
assert document.validate_document_with_cert(idp_cert), 'Document should be valid'
407+
end
408+
end
409+
410+
describe 'when response has no cert but you have local cert' do
411+
let(:document) { OneLogin::RubySaml::Response.new(response_document_valid_signed_without_x509certificate).document }
412+
let(:idp_cert) { OpenSSL::X509::Certificate.new(ruby_saml_cert_text) }
413+
414+
it 'is valid' do
415+
assert document.validate_document_with_cert(idp_cert), 'Document should be valid'
416+
end
417+
end
418+
end
419+
end
396420
end
397421
end

0 commit comments

Comments
 (0)