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

Improve the error message when validating the audience #292

Merged
merged 1 commit into from
Dec 3, 2015
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/onelogin/ruby-saml/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def validate_audience
return true if audiences.empty? || settings.issuer.nil? || settings.issuer.empty?

unless audiences.include? settings.issuer
error_msg = "#{settings.issuer} is not a valid audience for this Response"
error_msg = "#{settings.issuer} is not a valid audience for this Response - Valid audiences: #{audiences.join(',')}"
return append_error(error_msg)
end

Expand Down
8 changes: 4 additions & 4 deletions test/response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class RubySamlTest < Minitest::Test
settings.issuer = 'invalid'
response_valid_signed.settings = settings
response_valid_signed.soft = false
error_msg = "#{response_valid_signed.settings.issuer} is not a valid audience for this Response"
error_msg = "#{response_valid_signed.settings.issuer} is not a valid audience for this Response - Valid audiences: https://someone.example.com/audience"
assert_raises(OneLogin::RubySaml::ValidationError, error_msg) do
response_valid_signed.is_valid?
end
Expand Down Expand Up @@ -368,7 +368,7 @@ class RubySamlTest < Minitest::Test
settings.issuer = 'invalid'
response_valid_signed.settings = settings
response_valid_signed.is_valid?
assert_includes response_valid_signed.errors, "#{response_valid_signed.settings.issuer} is not a valid audience for this Response"
assert_includes response_valid_signed.errors, "#{response_valid_signed.settings.issuer} is not a valid audience for this Response - Valid audiences: https://someone.example.com/audience"
end

it "return false when no ID present in the SAML Response" do
Expand Down Expand Up @@ -411,7 +411,7 @@ class RubySamlTest < Minitest::Test
response.settings = settings
response.settings.issuer = 'invalid_audience'
assert !response.send(:validate_audience)
assert_includes response.errors, "#{response.settings.issuer} is not a valid audience for this Response"
assert_includes response.errors, "#{response.settings.issuer} is not a valid audience for this Response - Valid audiences: {audience}"
end
end

Expand Down Expand Up @@ -551,7 +551,7 @@ class RubySamlTest < Minitest::Test
response_invalid_audience.settings = settings
response_invalid_audience.settings.issuer = "https://invalid.example.com/audience"
assert !response_invalid_audience.send(:validate_audience)
assert_includes response_invalid_audience.errors, "#{response_invalid_audience.settings.issuer} is not a valid audience for this Response"
assert_includes response_invalid_audience.errors, "#{response_invalid_audience.settings.issuer} is not a valid audience for this Response - Valid audiences: http://invalid.audience.com"
end
end

Expand Down