Skip to content

Commit 5247202

Browse files
authored
Merge pull request #404 from joshwetzel/fix_not_before_error_msg
Add missing parenthesis to NotBefore error message
2 parents 6c61d23 + c0ad041 commit 5247202

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

lib/onelogin/ruby-saml/response.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Response < SamlMessage
3737
# with the :skip_conditions, or allow a clock_drift when checking dates with :allowed_clock_drift
3838
# or :matches_request_id that will validate that the response matches the ID of the request,
3939
# or skip the subject confirmation validation with the :skip_subject_confirmation option
40-
# or skip the recipient validation of the subject confirmation element with :skip_recipient_check option
40+
# or skip the recipient validation of the subject confirmation element with :skip_recipient_check option
4141
def initialize(response, options = {})
4242
raise ArgumentError.new("Response cannot be nil") if response.nil?
4343

@@ -651,13 +651,13 @@ def validate_conditions
651651

652652
now = Time.now.utc
653653

654-
if not_before && (now + allowed_clock_drift) < not_before
655-
error_msg = "Current time is earlier than NotBefore condition #{(now + allowed_clock_drift)} < #{not_before})"
654+
if not_before && (now_with_drift = now + allowed_clock_drift) < not_before
655+
error_msg = "Current time is earlier than NotBefore condition (#{now_with_drift} < #{not_before})"
656656
return append_error(error_msg)
657657
end
658658

659-
if not_on_or_after && now >= (not_on_or_after + allowed_clock_drift)
660-
error_msg = "Current time is on or after NotOnOrAfter condition (#{now} >= #{not_on_or_after + allowed_clock_drift})"
659+
if not_on_or_after && now >= (not_on_or_after_with_drift = not_on_or_after + allowed_clock_drift)
660+
error_msg = "Current time is on or after NotOnOrAfter condition (#{now} >= #{not_on_or_after_with_drift})"
661661
return append_error(error_msg)
662662
end
663663

@@ -814,7 +814,7 @@ def validate_signature
814814
opts[:cert] = settings.get_idp_cert
815815
fingerprint = settings.get_fingerprint
816816

817-
unless fingerprint && doc.validate_document(fingerprint, @soft, opts)
817+
unless fingerprint && doc.validate_document(fingerprint, @soft, opts)
818818
return append_error(error_msg)
819819
end
820820
else

test/xml_security_test.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class XmlSecurityTest < Minitest::Test
106106
end
107107
end
108108

109-
describe "#algorithm" do
109+
describe "#algorithm" do
110110
it "SHA1" do
111111
alg = OpenSSL::Digest::SHA1
112112
assert_equal alg, XMLSecurity::BaseDocument.new.algorithm("http://www.w3.org/2000/09/xmldsig#rsa-sha1")
@@ -130,7 +130,7 @@ class XmlSecurityTest < Minitest::Test
130130
alg = OpenSSL::Digest::SHA512
131131
assert_equal alg, XMLSecurity::BaseDocument.new.algorithm("http://www.w3.org/2001/04/xmldsig-more#rsa-sha512")
132132
assert_equal alg, XMLSecurity::BaseDocument.new.algorithm("http://www.w3.org/2001/04/xmldsig-more#sha512")
133-
end
133+
end
134134
end
135135

136136
describe "Fingerprint Algorithms" do
@@ -278,7 +278,7 @@ class XmlSecurityTest < Minitest::Test
278278
logout_request2.sign_document(ruby_saml_key, ruby_saml_cert_text)
279279
# verify our signature
280280
signed_doc2 = XMLSecurity::SignedDocument.new(logout_request2.to_s)
281-
signed_doc2.validate_document(ruby_saml_cert_fingerprint, false)
281+
signed_doc2.validate_document(ruby_saml_cert_fingerprint, false)
282282
assert signed_doc2.validate_document(ruby_saml_cert_fingerprint, false)
283283
end
284284

@@ -293,7 +293,7 @@ class XmlSecurityTest < Minitest::Test
293293
logout_response2.sign_document(ruby_saml_key, ruby_saml_cert_text)
294294
# verify our signature
295295
signed_doc2 = XMLSecurity::SignedDocument.new(logout_response2.to_s)
296-
signed_doc2.validate_document(ruby_saml_cert_fingerprint, false)
296+
signed_doc2.validate_document(ruby_saml_cert_fingerprint, false)
297297
assert signed_doc2.validate_document(ruby_saml_cert_fingerprint, false)
298298
end
299299
end
@@ -316,9 +316,14 @@ class XmlSecurityTest < Minitest::Test
316316
Timecop.freeze Time.parse('2012-11-20 17:55:00 UTC') do
317317
assert !response.is_valid?
318318

319-
contains_expected_error = response.errors.include? "Current time is earlier than NotBefore condition 2012-11-20 17:55:00 UTC < 2012-11-28 17:53:45 UTC)"
320-
contains_expected_error ||= response.errors.include? "Current time is earlier than NotBefore condition Tue Nov 20 17:55:00 UTC 2012 < Wed Nov 28 17:53:45 UTC 2012)"
321-
assert contains_expected_error
319+
time_1 = '2012-11-20 17:55:00 UTC < 2012-11-28 17:53:45 UTC'
320+
time_2 = 'Tue Nov 20 17:55:00 UTC 2012 < Wed Nov 28 17:53:45 UTC 2012'
321+
322+
errors = [time_1, time_2].map do |time|
323+
"Current time is earlier than NotBefore condition (#{time})"
324+
end
325+
326+
assert_predicate response.errors & errors, :any?
322327
end
323328
end
324329

@@ -344,7 +349,7 @@ class XmlSecurityTest < Minitest::Test
344349
assert document.validate_document(fingerprint, true), 'Document should be valid'
345350
end
346351
end
347-
352+
348353
describe 'when response has signed assertion' do
349354
let(:document_data) { read_response('response_with_signed_assertion_3.xml') }
350355
let(:document) { OneLogin::RubySaml::Response.new(document_data).document }

0 commit comments

Comments
 (0)