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

Define 'soft' variable to prevent exception when doc cert is invalid #555

Merged
merged 1 commit into from
Nov 9, 2020
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
2 changes: 1 addition & 1 deletion lib/xml_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def validate_document(idp_cert_fingerprint, soft = true, options = {})
validate_signature(base64_cert, soft)
end

def validate_document_with_cert(idp_cert)
def validate_document_with_cert(idp_cert, soft = true)
# get cert from response
cert_element = REXML::XPath.first(
self,
Expand Down
13 changes: 13 additions & 0 deletions test/xml_security_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,19 @@ class XmlSecurityTest < Minitest::Test
end

describe '#validate_document_with_cert' do
describe 'with invalid document ' do
describe 'when certificate is invalid' do
let(:document_data) { read_response('response_with_signed_message_and_assertion.xml')
.sub(/<ds:X509Certificate>.*<\/ds:X509Certificate>/, "<ds:X509Certificate>invalid<\/ds:X509Certificate>") }
let(:document) { OneLogin::RubySaml::Response.new(document_data).document }
let(:idp_cert) { OpenSSL::X509::Certificate.new(ruby_saml_cert_text) }

it 'is invalid' do
refute document.validate_document_with_cert(idp_cert), 'Document should be invalid'
end
end
end

describe 'with valid document ' do
describe 'when response has cert' do
let(:document_data) { read_response('response_with_signed_message_and_assertion.xml') }
Expand Down