Skip to content

Commit 2bff5f6

Browse files
committed
Merge branch 'master' of github.com:onelogin/ruby-saml
2 parents 09e9cac + 9f710c5 commit 2bff5f6

8 files changed

Lines changed: 39 additions & 12 deletions

File tree

.travis.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ rvm:
77
- 2.2.10
88
- 2.3.8
99
- 2.4.6
10-
- 2.5.5
11-
- 2.6.3
12-
- 2.7.0
10+
- 2.5.8
11+
- 2.6.6
12+
- 2.7.2
1313
- ree
1414
- jruby-1.7.27
1515
- jruby-9.1.17.0
16-
- jruby-9.2.7.0
16+
- jruby-9.2.13.0
1717
gemfile:
1818
- Gemfile
1919
- gemfiles/nokogiri-1.5.gemfile
@@ -29,7 +29,7 @@ matrix:
2929
gemfile: gemfiles/nokogiri-1.5.gemfile
3030
- rvm: jruby-9.1.17.0
3131
gemfile: gemfiles/nokogiri-1.5.gemfile
32-
- rvm: jruby-9.2.7.0
32+
- rvm: jruby-9.2.13.0
3333
gemfile: gemfiles/nokogiri-1.5.gemfile
3434
- rvm: 2.1.5
3535
gemfile: gemfiles/nokogiri-1.5.gemfile
@@ -39,11 +39,11 @@ matrix:
3939
gemfile: gemfiles/nokogiri-1.5.gemfile
4040
- rvm: 2.4.6
4141
gemfile: gemfiles/nokogiri-1.5.gemfile
42-
- rvm: 2.5.5
42+
- rvm: 2.5.8
4343
gemfile: gemfiles/nokogiri-1.5.gemfile
44-
- rvm: 2.6.3
44+
- rvm: 2.6.6
4545
gemfile: gemfiles/nokogiri-1.5.gemfile
46-
- rvm: 2.7.0
46+
- rvm: 2.7.2
4747
gemfile: gemfiles/nokogiri-1.5.gemfile
4848
env:
4949
- JRUBY_OPTS="--debug"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_authnst
292292
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_conditions: true}) # skips conditions
293293
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_subject_confirmation: true}) # skips subject confirmation
294294
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
295+
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_audience: true}) # skips audience check
295296
```
296297
297298
All that's left is to wrap everything in a controller and reference it in the initialization and consumption URLs in OneLogin. A full controller example could look like this:

lib/onelogin/ruby-saml/idp_metadata_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def get_idp_metadata(url, validate_cert)
189189
end
190190

191191
get = Net::HTTP::Get.new(uri.request_uri)
192+
get.basic_auth uri.user, uri.password if uri.user
192193
@response = http.request(get)
193194
return response.body if response.is_a? Net::HTTPSuccess
194195

lib/onelogin/ruby-saml/response.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Response < SamlMessage
3434
# This is not a whitelist to allow people extending OneLogin::RubySaml:Response
3535
# and pass custom options
3636
AVAILABLE_OPTIONS = [
37-
:allowed_clock_drift, :check_duplicated_attributes, :matches_request_id, :settings, :skip_authnstatement, :skip_conditions,
37+
:allowed_clock_drift, :check_duplicated_attributes, :matches_request_id, :settings, :skip_audience, :skip_authnstatement, :skip_conditions,
3838
:skip_destination, :skip_recipient_check, :skip_subject_confirmation
3939
]
4040
# TODO: Update the comment on initialize to describe every option
@@ -47,6 +47,8 @@ class Response < SamlMessage
4747
# or :matches_request_id that will validate that the response matches the ID of the request,
4848
# or skip the subject confirmation validation with the :skip_subject_confirmation option
4949
# or skip the recipient validation of the subject confirmation element with :skip_recipient_check option
50+
# or skip the audience validation with :skip_audience option
51+
#
5052
def initialize(response, options = {})
5153
raise ArgumentError.new("Response cannot be nil") if response.nil?
5254

@@ -595,11 +597,13 @@ def validate_in_response_to
595597
end
596598

597599
# Validates the Audience, (If the Audience match the Service Provider EntityID)
600+
# If the response was initialized with the :skip_audience option, this validation is skipped,
598601
# If fails, the error is added to the errors array
599602
# @return [Boolean] True if there is an Audience Element that match the Service Provider EntityID, otherwise False if soft=True
600603
# @raise [ValidationError] if soft == false and validation fails
601604
#
602605
def validate_audience
606+
return true if options[:skip_audience]
603607
return true if audiences.empty? || settings.sp_entity_id.nil? || settings.sp_entity_id.empty?
604608

605609
unless audiences.include? settings.sp_entity_id

lib/xml_security.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def validate_document(idp_cert_fingerprint, soft = true, options = {})
241241
validate_signature(base64_cert, soft)
242242
end
243243

244-
def validate_document_with_cert(idp_cert)
244+
def validate_document_with_cert(idp_cert, soft = true)
245245
# get cert from response
246246
cert_element = REXML::XPath.first(
247247
self,

ruby-saml.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
1616
"README.md"
1717
]
1818
s.files = `git ls-files`.split("\n")
19-
s.homepage = %q{http://github.com/onelogin/ruby-saml}
19+
s.homepage = %q{https://github.com/onelogin/ruby-saml}
2020
s.rdoc_options = ["--charset=UTF-8"]
2121
s.require_paths = ["lib"]
2222
s.rubygems_version = %q{1.3.7}
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
3939
s.add_runtime_dependency('nokogiri', '<= 1.5.11')
4040
elsif RUBY_VERSION < '2.1'
4141
s.add_runtime_dependency('nokogiri', '>= 1.5.10', '<= 1.6.8.1')
42-
elseif RUBY_VERSION < '2.3'
42+
elsif RUBY_VERSION < '2.3'
4343
s.add_runtime_dependency('nokogiri', '>= 1.9.1', '<= 1.10.0')
4444
else
4545
s.add_runtime_dependency('nokogiri', '>= 1.10.5')

test/response_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class RubySamlTest < Minitest::Test
3838
let(:response_multiple_signed) { OneLogin::RubySaml::Response.new(read_invalid_response("multiple_signed.xml.base64")) }
3939
let(:response_audience_self_closed) { OneLogin::RubySaml::Response.new(read_response("response_audience_self_closed_tag.xml.base64")) }
4040
let(:response_invalid_audience) { OneLogin::RubySaml::Response.new(read_invalid_response("invalid_audience.xml.base64")) }
41+
let(:response_invalid_audience_with_skip) { OneLogin::RubySaml::Response.new(read_invalid_response("invalid_audience.xml.base64"), {:skip_audience => true}) }
4142
let(:response_invalid_signed_element) { OneLogin::RubySaml::Response.new(read_invalid_response("response_invalid_signed_element.xml.base64")) }
4243
let(:response_invalid_issuer_assertion) { OneLogin::RubySaml::Response.new(read_invalid_response("invalid_issuer_assertion.xml.base64")) }
4344
let(:response_invalid_issuer_message) { OneLogin::RubySaml::Response.new(read_invalid_response("invalid_issuer_message.xml.base64")) }
@@ -703,6 +704,13 @@ def generate_audience_error(expected, actual)
703704
assert !response_invalid_audience.send(:validate_audience)
704705
assert_includes response_invalid_audience.errors, generate_audience_error(response_invalid_audience.settings.sp_entity_id, ['http://invalid.audience.com'])
705706
end
707+
708+
it "return true when there is no valid audience but skip_destination option is used" do
709+
response_invalid_audience_with_skip.settings = settings
710+
response_invalid_audience_with_skip.settings.sp_entity_id = "https://invalid.example.com/audience"
711+
assert response_invalid_audience_with_skip.send(:validate_audience)
712+
assert_empty response_invalid_audience_with_skip.errors
713+
end
706714
end
707715

708716
describe "#validate_issuer" do

test/xml_security_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@ class XmlSecurityTest < Minitest::Test
395395
end
396396

397397
describe '#validate_document_with_cert' do
398+
describe 'with invalid document ' do
399+
describe 'when certificate is invalid' do
400+
let(:document_data) { read_response('response_with_signed_message_and_assertion.xml')
401+
.sub(/<ds:X509Certificate>.*<\/ds:X509Certificate>/, "<ds:X509Certificate>invalid<\/ds:X509Certificate>") }
402+
let(:document) { OneLogin::RubySaml::Response.new(document_data).document }
403+
let(:idp_cert) { OpenSSL::X509::Certificate.new(ruby_saml_cert_text) }
404+
405+
it 'is invalid' do
406+
refute document.validate_document_with_cert(idp_cert), 'Document should be invalid'
407+
end
408+
end
409+
end
410+
398411
describe 'with valid document ' do
399412
describe 'when response has cert' do
400413
let(:document_data) { read_response('response_with_signed_message_and_assertion.xml') }

0 commit comments

Comments
 (0)