Skip to content

Commit ca8372f

Browse files
committed
* Allow the validate_subject_confirmation Response validation to be skipped with a skip_subject_confirmation flag passed when initializing the Response
1 parent 7b4417e commit ca8372f

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/onelogin/ruby-saml/response.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,14 @@ def validate_session_expiration(soft = true)
524524
end
525525

526526
# Validates if exists valid SubjectConfirmation (If the response was initialized with the :allowed_clock_drift option,
527-
# timimg validation are relaxed by the allowed_clock_drift value)
527+
# timimg validation are relaxed by the allowed_clock_drift value. If the response was initialized with the
528+
# :skip_subject_confirmation option, this validation is skipped)
528529
# If fails, the error is added to the errors array
529530
# @return [Boolean] True if exists a valid SubjectConfirmation, otherwise False if soft=True
530531
# @raise [ValidationError] if soft == false and validation fails
531532
#
532533
def validate_subject_confirmation
534+
return true if options[:skip_subject_confirmation]
533535
valid_subject_confirmation = false
534536

535537
subject_confirmation_nodes = xpath_from_signed_assertion('/a:Subject/a:SubjectConfirmation')

test/response_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,27 @@ class RubySamlTest < Minitest::Test
616616
assert !response_invalid_subjectconfirmation_noa.send(:validate_subject_confirmation)
617617
assert_includes response_invalid_subjectconfirmation_noa.errors, "A valid SubjectConfirmation was not found on this Response"
618618
end
619+
620+
it "return true when the skip_subject_confirmation option is passed and the subject confirmation is valid" do
621+
opts = {}
622+
opts[:skip_subject_confirmation] = true
623+
response_with_skip = OneLogin::RubySaml::Response.new(response_document_valid_signed, opts)
624+
response_with_skip.settings = settings
625+
response_with_skip.settings.assertion_consumer_service_url = 'recipient'
626+
Time.expects(:now).times(0) # ensures the test isn't run and thus Time.now.utc is never called within the test
627+
assert response_with_skip.send(:validate_subject_confirmation)
628+
assert_empty response_with_skip.errors
629+
end
630+
631+
it "return true when the skip_subject_confirmation option is passed and the response has an invalid subject confirmation" do
632+
opts = {}
633+
opts[:skip_subject_confirmation] = true
634+
response_with_skip = OneLogin::RubySaml::Response.new(read_invalid_response("invalid_subjectconfirmation_noa.xml.base64"), opts)
635+
response_with_skip.settings = settings
636+
Time.expects(:now).times(0) # ensures the test isn't run and thus Time.now.utc is never called within the test
637+
assert response_with_skip.send(:validate_subject_confirmation)
638+
assert_empty response_with_skip.errors
639+
end
619640
end
620641

621642
describe "#validate_session_expiration" do

0 commit comments

Comments
 (0)