...
|
...
|
@@ -5,6 +5,7 @@ class TokenTest < ActiveSupport::TestCase
|
5
|
5
|
|
6
|
6
|
def setup
|
7
|
7
|
@frozen_time = Time.now
|
|
8
|
+ @token = Token.new
|
8
|
9
|
end
|
9
|
10
|
|
10
|
11
|
def teardown
|
...
|
...
|
@@ -13,28 +14,28 @@ class TokenTest < ActiveSupport::TestCase
|
13
|
13
|
|
14
|
14
|
test "should authentificate" do
|
15
|
15
|
Timecop.freeze(@frozen_time) do
|
16
|
|
- Token.save_session({token: "123", ip: "8.8.8.8", created_at: Time.now})
|
|
16
|
+ @token.save_session({token: "123", ip: "8.8.8.8", created_at: Time.now}, 123)
|
17
|
17
|
assert !! Token.authenticate({token: "123", created_at: Time.now, ip: "8.8.8.8"})
|
18
|
18
|
end
|
19
|
19
|
end
|
20
|
20
|
|
21
|
21
|
test "shouldnt auth with wrong token" do
|
22
|
22
|
Timecop.freeze(@frozen_time) do
|
23
|
|
- Token.save_session({token: "123", ip: "8.8.8.100", created_at: @frozen_time})
|
|
23
|
+ @token.save_session({token: "123", ip: "8.8.8.100", created_at: @frozen_time}, 123)
|
24
|
24
|
assert_false !! Token.authenticate({token: "14423", created_at: @frozen_time, ip: "8.8.8.100"})
|
25
|
25
|
end
|
26
|
26
|
end
|
27
|
27
|
|
28
|
28
|
test "shouldnt auth with wrong time" do
|
29
|
29
|
Timecop.freeze(@frozen_time) do
|
30
|
|
- Token.save_session({token: "123", ip: "8.1.1.1", created_at: @frozen_time})
|
|
30
|
+ @token.save_session({token: "123", ip: "8.1.1.1", created_at: @frozen_time}, 2137213)
|
31
|
31
|
assert_false !! Token.authenticate({token: "123", created_at: @frozen_time + Rails.application.config.max_lifetime + 10, ip: "8.1.1.1"})
|
32
|
32
|
end
|
33
|
33
|
end
|
34
|
34
|
|
35
|
35
|
test "shouldnt auth with wrong ip" do
|
36
|
36
|
Timecop.freeze(@frozen_time) do
|
37
|
|
- Token.save_session({token: "123", ip: "8.1.1.1", created_at: @frozen_time})
|
|
37
|
+ @token.save_session({token: "123", ip: "8.1.1.1", created_at: @frozen_time}, 92137213)
|
38
|
38
|
assert_false !! Token.authenticate({token: "123", created_at: @frozen_time, ip: "8.1.1.100"})
|
39
|
39
|
end
|
40
|
40
|
end
|