Skip to content

Commit

Permalink
* Allow the validate_subject_confirmation Response validation to be s…
Browse files Browse the repository at this point in the history
…kipped with a skip_subject_confirmation flag passed when initializing the Response
  • Loading branch information
sthanson committed Aug 18, 2015
1 parent 7b4417e commit ca8372f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/onelogin/ruby-saml/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,14 @@ def validate_session_expiration(soft = true)
end

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

subject_confirmation_nodes = xpath_from_signed_assertion('/a:Subject/a:SubjectConfirmation')
Expand Down
21 changes: 21 additions & 0 deletions test/response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,27 @@ class RubySamlTest < Minitest::Test
assert !response_invalid_subjectconfirmation_noa.send(:validate_subject_confirmation)
assert_includes response_invalid_subjectconfirmation_noa.errors, "A valid SubjectConfirmation was not found on this Response"
end

it "return true when the skip_subject_confirmation option is passed and the subject confirmation is valid" do
opts = {}
opts[:skip_subject_confirmation] = true
response_with_skip = OneLogin::RubySaml::Response.new(response_document_valid_signed, opts)
response_with_skip.settings = settings
response_with_skip.settings.assertion_consumer_service_url = 'recipient'
Time.expects(:now).times(0) # ensures the test isn't run and thus Time.now.utc is never called within the test
assert response_with_skip.send(:validate_subject_confirmation)
assert_empty response_with_skip.errors
end

it "return true when the skip_subject_confirmation option is passed and the response has an invalid subject confirmation" do
opts = {}
opts[:skip_subject_confirmation] = true
response_with_skip = OneLogin::RubySaml::Response.new(read_invalid_response("invalid_subjectconfirmation_noa.xml.base64"), opts)
response_with_skip.settings = settings
Time.expects(:now).times(0) # ensures the test isn't run and thus Time.now.utc is never called within the test
assert response_with_skip.send(:validate_subject_confirmation)
assert_empty response_with_skip.errors
end
end

describe "#validate_session_expiration" do
Expand Down

0 comments on commit ca8372f

Please sign in to comment.