]> git.openstreetmap.org Git - rails.git/blob - test/unit/oauth_token_test.rb
Don't re-declare lexical variable
[rails.git] / test / unit / oauth_token_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class OauthTokenTest < ActiveSupport::TestCase
4   api_fixtures
5
6   ##
7   # check that after calling invalidate! on a token, it is invalid.
8   def test_token_invalidation
9     tok = OauthToken.new
10     assert_equal false, tok.invalidated?, "Token should be created valid."
11     tok.invalidate!
12     assert_equal true, tok.invalidated?, "Token should now be invalid."
13   end
14
15   ##
16   # check that an authorized token is authorised and can be invalidated
17   def test_token_authorisation
18     tok = RequestToken.create :client_application => client_applications(:oauth_web_app)
19     assert_equal false, tok.authorized?, "Token should be created unauthorised."
20     tok.authorize!(users(:public_user))
21     assert_equal true, tok.authorized?, "Token should now be authorised."
22     tok.invalidate!
23     assert_equal false, tok.authorized?, "Token should now be invalid."
24   end
25
26   ##
27   # test that tokens can't be found unless they're authorised
28   def test_find_token
29     tok = client_applications(:oauth_web_app).create_request_token
30     assert_equal false, tok.authorized?, "Token should be created unauthorised."
31     assert_equal nil, OauthToken.find_token(tok.token), "Shouldn't be able to find unauthorised token"
32     tok.authorize!(users(:public_user))
33     assert_equal true, tok.authorized?, "Token should now be authorised."
34     assert_not_equal nil, OauthToken.find_token(tok.token), "Should be able to find authorised token"
35   end
36
37 end