]> git.openstreetmap.org Git - rails.git/blob - test/models/oauth_nonce_test.rb
Fix stubbing of hostip requests
[rails.git] / test / models / oauth_nonce_test.rb
1 require "test_helper"
2
3 class OauthNonceTest < ActiveSupport::TestCase
4   ##
5   # the nonce has only one property, that it is a unique pair of
6   # string and timestamp.
7   def test_nonce_uniqueness
8     string = "0123456789ABCDEF"
9     timestamp = Time.now.to_i
10
11     nonce1 = OauthNonce.remember(string, timestamp)
12     assert_not_equal false, nonce1, "First nonce should be unique. Check your test database is empty."
13
14     nonce2 = OauthNonce.remember(string, timestamp)
15     assert_equal false, nonce2, "Shouldn't be able to remember the same nonce twice."
16   end
17
18   ##
19   # nonces that are not current should be rejected
20   def test_nonce_not_current
21     string = "0123456789ABCDEF"
22
23     nonce1 = OauthNonce.remember(string, Time.now.to_i - 86430)
24     assert_equal false, nonce1, "Nonces over a day in the past should be rejected"
25
26     nonce2 = OauthNonce.remember(string, Time.now.to_i - 86370)
27     assert_not_equal false, nonce2, "Nonces under a day in the past should be rejected"
28   end
29 end