2 require 'create_superuser_token'
4 class CreateSuperUserTokenTest < ActiveSupport::TestCase
5 include CreateSuperUserToken
7 test "create superuser token twice and expect same resutls" do
8 # Create a token with some string
9 token1 = create_superuser_token 'atesttoken'
11 assert_equal token1, 'atesttoken'
13 # Create token again; this time, we should get the one created earlier
14 token2 = create_superuser_token
16 assert_equal token1, token2
19 test "create superuser token with two different inputs and expect the first both times" do
20 # Create a token with some string
21 token1 = create_superuser_token 'atesttoken'
23 assert_equal token1, 'atesttoken'
25 # Create token again with some other string and expect the existing superuser token back
26 token2 = create_superuser_token 'someothertokenstring'
28 assert_equal token1, token2
31 test "create superuser token twice and expect same results" do
32 # Create a token with some string
33 token1 = create_superuser_token 'atesttoken'
35 assert_equal token1, 'atesttoken'
37 # Create token again with that same superuser token and expect it back
38 token2 = create_superuser_token 'atesttoken'
40 assert_equal token1, token2
43 test "create superuser token and invoke again with some other valid token" do
44 # Create a token with some string
45 token1 = create_superuser_token 'atesttoken'
47 assert_equal token1, 'atesttoken'
49 su_token = api_client_authorizations("system_user").api_token
50 token2 = create_superuser_token su_token
51 assert_equal token2, su_token
54 test "create superuser token, expire it, and create again" do
55 # Create a token with some string
56 token1 = create_superuser_token 'atesttoken'
58 assert_equal token1, 'atesttoken'
60 # Expire this token and call create again; expect a new token created
61 apiClientAuth = ApiClientAuthorization.where(api_token: token1).first
62 Thread.current[:user] = users(:admin)
63 apiClientAuth.update_attributes expires_at: '2000-10-10'
65 token2 = create_superuser_token
67 assert_not_equal token1, token2
70 test "invoke create superuser token with an invalid non-superuser token and expect error" do
71 active_user_token = api_client_authorizations("active").api_token
72 e = assert_raises RuntimeError do
73 create_superuser_token active_user_token
76 assert_equal "Token already exists but is not a superuser token.", e.message