Skip to content

Commit cde130d

Browse files
authored
Merge pull request #450 from rewardops/master
add ability to skip authnstatement validation
2 parents af2c12b + 7f4307e commit cde130d

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ def saml_settings
235235
end
236236
```
237237
238-
Some assertion validations can be skipped by passing parameters to `OneLogin::RubySaml::Response.new()`. For example, you can skip the `Conditions`, `Recipient`, or the `SubjectConfirmation` validations by initializing the response with different options:
238+
Some assertion validations can be skipped by passing parameters to `OneLogin::RubySaml::Response.new()`. For example, you can skip the `AuthnStatement`, `Conditions`, `Recipient`, or the `SubjectConfirmation` validations by initializing the response with different options:
239239
240240
```ruby
241+
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_authnstatement: true}) # skips AuthnStatement
241242
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_conditions: true}) # skips conditions
242243
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_subject_confirmation: true}) # skips subject confirmation
243244
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_recipient_check: true}) # doens't skip subject confirmation, but skips the recipient check which is a sub check of the subject_confirmation check

lib/onelogin/ruby-saml/response.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ def validate_one_conditions
633633
# @return [Boolean] True if there is a authnstatement element and is unique
634634
#
635635
def validate_one_authnstatement
636+
return true if options[:skip_authnstatement]
637+
636638
authnstatement_nodes = xpath_from_signed_assertion('/a:AuthnStatement')
637639
unless authnstatement_nodes.size == 1
638640
error_msg = "The Assertion must include one AuthnStatement element"

test/response_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class RubySamlTest < Minitest::Test
2424
let(:response_multi_assertion) { OneLogin::RubySaml::Response.new(read_invalid_response("multiple_assertions.xml.base64")) }
2525
let(:response_no_conditions) { OneLogin::RubySaml::Response.new(read_invalid_response("no_conditions.xml.base64")) }
2626
let(:response_no_authnstatement) { OneLogin::RubySaml::Response.new(read_invalid_response("no_authnstatement.xml.base64")) }
27+
let(:response_no_authnstatement_with_skip) { OneLogin::RubySaml::Response.new(read_invalid_response("no_authnstatement.xml.base64"), {:skip_authnstatement => true}) }
2728
let(:response_empty_destination) { OneLogin::RubySaml::Response.new(read_invalid_response("empty_destination.xml.base64")) }
2829
let(:response_empty_destination_with_skip) { OneLogin::RubySaml::Response.new(read_invalid_response("empty_destination.xml.base64"), {:skip_destination => true}) }
2930
let(:response_no_status) { OneLogin::RubySaml::Response.new(read_invalid_response("no_status.xml.base64")) }
@@ -997,6 +998,12 @@ class RubySamlTest < Minitest::Test
997998
response.soft = true
998999
assert response.send(:validate_one_authnstatement)
9991000
end
1001+
1002+
it "return true when SAML Response is empty but skip_authstatement option is used" do
1003+
response_no_authnstatement_with_skip.soft = true
1004+
assert response_no_authnstatement_with_skip.send(:validate_one_authnstatement)
1005+
assert_empty response_empty_destination_with_skip.errors
1006+
end
10001007
end
10011008

10021009
describe "#check_conditions" do

0 commit comments

Comments
 (0)