Skip to content

Commit 6c9c505

Browse files
committed
* The clock drift on the validate_session_expiration test was removing available time instead of padding the test with extra time. Added the padding to SessionNotOnOrAfter instead of Time.now
1 parent 3905e83 commit 6c9c505

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/onelogin/ruby-saml/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def validate_session_expiration(soft = true)
515515
return true if session_expires_at.nil?
516516

517517
now = Time.now.utc
518-
unless session_expires_at > (now + allowed_clock_drift)
518+
unless (session_expires_at + allowed_clock_drift) > now
519519
error_msg = "The attributes have expired, based on the SessionNotOnOrAfter of the AttributeStatement of this Response"
520520
return append_error(error_msg)
521521
end

test/response_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,17 @@ class RubySamlTest < Minitest::Test
630630
assert !response.send(:validate_session_expiration)
631631
assert_includes response.errors, "The attributes have expired, based on the SessionNotOnOrAfter of the AttributeStatement of this Response"
632632
end
633+
634+
it "returns true when the session has expired, but is still within the allowed_clock_drift" do
635+
drift = (Time.now - Time.parse("2010-11-19T21:57:37Z")) * 60 # minutes ago that this assertion expired
636+
drift += 10 # add a buffer of 10 minutes to make sure the test passes
637+
638+
response_with_drift = OneLogin::RubySaml::Response.new(response_document_without_recipient,
639+
{allowed_clock_drift: drift})
640+
response_with_drift.settings = settings
641+
assert response_with_drift.send(:validate_session_expiration)
642+
assert_empty response_with_drift.errors
643+
end
633644
end
634645

635646
describe "#validate_signature" do

0 commit comments

Comments
 (0)