Skip to content

Commit 084a7c9

Browse files
committed
fix tests
1 parent d19bec0 commit 084a7c9

4 files changed

Lines changed: 15 additions & 17 deletions

File tree

lib/ruby_saml/response.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ def doc_to_validate
800800
# If the response contains the signature, and the assertion was encrypted, validate the original SAML Response
801801
# otherwise, review if the decrypted assertion contains a signature
802802
subject_id = RubySaml::XML::SignedDocumentValidator.subject_id(document)
803-
return nil unless subject_id
803+
return decrypted_document unless subject_id
804804

805805
sig_elements = document.xpath(
806806
"/p:Response[@ID=$id]/ds:Signature",
@@ -858,7 +858,7 @@ def validate_signature
858858
fingerprint_alg: settings.idp_cert_fingerprint_algorithm
859859
}
860860

861-
if fingerprint && RubySaml::XML::SignedDocumentValidator.validate_document(doc, fingerprint, @errors, soft: @soft, **opts)
861+
if fingerprint && RubySaml::XML::SignedDocumentValidator.validate_document(doc, fingerprint, @errors, soft: @soft, **opts).is_a?(TrueClass) # TODO: DANGEROUS
862862
if settings.security[:check_idp_cert_expiration] && RubySaml::Utils.is_cert_expired(idp_cert)
863863
return append_error("IdP x509 certificate expired")
864864
end
@@ -869,7 +869,7 @@ def validate_signature
869869
valid = false
870870
expired = false
871871
idp_certs[:signing].each do |idp_cert|
872-
valid = RubySaml::XML::SignedDocumentValidator.validate_document_with_cert(doc, idp_cert, @errors, soft: @soft)
872+
valid = RubySaml::XML::SignedDocumentValidator.validate_document_with_cert(doc, idp_cert, @errors, soft: @soft).is_a?(TrueClass) # TODO: DANGEROUS
873873
next unless valid
874874

875875
if settings.security[:check_idp_cert_expiration] && RubySaml::Utils.is_cert_expired(idp_cert)
@@ -911,29 +911,27 @@ def cached_signed_assertion
911911
empty_doc = Nokogiri::XML::Document.new
912912

913913
xml = doc_to_validate
914-
dup = doc_to_validate.to_s.dup
915914
return empty_doc if xml.nil?
916915

917-
xml = RubySaml::XML::SignedDocumentValidator.subject_node(xml)
916+
subject = RubySaml::XML::SignedDocumentValidator.subject_node(xml)
918917
return empty_doc if xml.nil? # when no signature/reference is found, return empty document
919918

920-
root = xml.document.root
921-
subject_id = RubySaml::XML::SignedDocumentValidator.subject_id(dup)
919+
subject_id = RubySaml::XML::SignedDocumentValidator.subject_id(xml)
922920
return nil unless subject_id
923921

924-
if root["ID"] != subject_id
922+
if subject['ID'] != subject_id
925923
return empty_doc
926924
end
927925

928926
assertion = empty_doc
929-
if root.name == "Response"
930-
if (result = root.at_xpath("a:Assertion", {"a" => RubySaml::XML::NS_ASSERTION}))
927+
if subject.name == "Response"
928+
if (result = subject.at_xpath("a:Assertion", {"a" => RubySaml::XML::NS_ASSERTION}))
931929
assertion = result
932-
elsif (result = root.at_xpath("a:EncryptedAssertion", {"a" => RubySaml::XML::NS_ASSERTION}))
930+
elsif (result = subject.at_xpath("a:EncryptedAssertion", {"a" => RubySaml::XML::NS_ASSERTION}))
933931
assertion = RubySaml::XML::Decryptor.decrypt_assertion(result, settings&.get_sp_decryption_keys)
934932
end
935-
elsif root.name == "Assertion"
936-
assertion = root
933+
elsif subject.name == "Assertion"
934+
assertion = subject
937935
end
938936

939937
assertion

lib/ruby_saml/xml/signed_document_info.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(noko, check_malformed_doc: true)
1818
end
1919

2020
# Validates the subject_node, which is the signed part of the document
21-
def validate_document(idp_cert_fingerprint = true, options = {})
21+
def validate_document(idp_cert_fingerprint, options = {})
2222
# Get certificate from document
2323
if certificate_object
2424
# Calculate fingerprint using specified algorithm
@@ -37,7 +37,7 @@ def validate_document(idp_cert_fingerprint = true, options = {})
3737
elsif options[:cert]
3838
cert = options[:cert]
3939
else
40-
raise RubySaml::ValidationError.new('Certificate element missing in response (ds:X509Certificate) and no cert provided at settings')
40+
raise RubySaml::ValidationError.new('Certificate element missing in response (ds:X509Certificate) and no cert provided in settings')
4141
end
4242

4343
validate_signature(cert)

lib/ruby_saml/xml/signed_document_validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def with_error_handling(errors, soft)
1313
rescue RubySaml::ValidationError => e
1414
errors << e.message
1515
raise e unless soft
16-
errors
16+
errors # TODO: Return false??
1717
end
1818

1919
# TODO: [ERRORS-REFACTOR] -- Rather than returning array of error,

test/response_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ def generate_audience_error(expected, actual)
943943
response_invalid_x509certificate = RubySaml::Response.new(content)
944944
response_invalid_x509certificate.settings = settings
945945
assert !response_invalid_x509certificate.send(:validate_signature)
946-
assert_includes response_invalid_x509certificate.errors, "Document Certificate Error: PEM_read_bio_X509: no start line"
946+
assert_includes response_invalid_x509certificate.errors, "Document Certificate Error"
947947
assert_includes response_invalid_x509certificate.errors, "Invalid Signature on SAML Response"
948948
end
949949

0 commit comments

Comments
 (0)