X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/98184dfb9cacc74ac5bcb91a41a2d5804b3f4f7d..4d20a2c96a3ff722071e7b1093d260b1236b2eeb:/test/models/oauth_nonce_test.rb?ds=inline diff --git a/test/models/oauth_nonce_test.rb b/test/models/oauth_nonce_test.rb index ffbad0af6..dd97278c1 100644 --- a/test/models/oauth_nonce_test.rb +++ b/test/models/oauth_nonce_test.rb @@ -1,15 +1,13 @@ -require 'test_helper' +require "test_helper" class OauthNonceTest < ActiveSupport::TestCase - api_fixtures - ## # the nonce has only one property, that it is a unique pair of # string and timestamp. def test_nonce_uniqueness string = "0123456789ABCDEF" - timestamp = Time.now - + timestamp = Time.now.to_i + nonce1 = OauthNonce.remember(string, timestamp) assert_not_equal false, nonce1, "First nonce should be unique. Check your test database is empty." @@ -17,4 +15,15 @@ class OauthNonceTest < ActiveSupport::TestCase assert_equal false, nonce2, "Shouldn't be able to remember the same nonce twice." end + ## + # nonces that are not current should be rejected + def test_nonce_not_current + string = "0123456789ABCDEF" + + nonce1 = OauthNonce.remember(string, Time.now.to_i - 86430) + assert_equal false, nonce1, "Nonces over a day in the past should be rejected" + + nonce2 = OauthNonce.remember(string, Time.now.to_i - 86370) + assert_not_equal false, nonce2, "Nonces under a day in the past should be rejected" + end end