Skip to content

Commit 7b4417e

Browse files
committed
Merge pull request SAML-Toolkits#258 from sthanson/fix_session_expires_at_drift
Fix allowed_clock_drift on the validate_session_expiration test
2 parents 3905e83 + a129662 commit 7b4417e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,18 @@ 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+
opts = {}
638+
opts[:allowed_clock_drift] = drift
639+
640+
response_with_drift = OneLogin::RubySaml::Response.new(response_document_without_recipient, opts)
641+
response_with_drift.settings = settings
642+
assert response_with_drift.send(:validate_session_expiration)
643+
assert_empty response_with_drift.errors
644+
end
633645
end
634646

635647
describe "#validate_signature" do

0 commit comments

Comments
 (0)