3 class UsersControllerTest < ActionController::TestCase
5 test "valid token works in controller test" do
6 get :index, {}, session_for(:active)
7 assert_response :success
10 test "ignore previously valid token (for deleted user), don't crash" do
11 get :activity, {}, session_for(:valid_token_deleted_user)
12 assert_response :redirect
13 assert_match /^#{Rails.configuration.arvados_login_base}/, @response.redirect_url
14 assert_nil assigns(:my_jobs)
15 assert_nil assigns(:my_ssh_keys)
18 test "expired token redirects to api server login" do
20 id: api_fixture('users')['active']['uuid']
21 }, session_for(:expired_trustedclient)
22 assert_response :redirect
23 assert_match /^#{Rails.configuration.arvados_login_base}/, @response.redirect_url
24 assert_nil assigns(:my_jobs)
25 assert_nil assigns(:my_ssh_keys)
28 test "show welcome page if no token provided" do
30 assert_response :redirect
31 assert_match /\/users\/welcome/, @response.redirect_url
34 test "request shell access" do
35 user = api_fixture('users')['spectator']
37 ActionMailer::Base.deliveries = []
39 post :request_shell_access, {
42 }, session_for(:spectator)
43 assert_response :success
45 full_name = "#{user['first_name']} #{user['last_name']}"
46 expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
48 ActionMailer::Base.deliveries.each do |email|
49 if email.subject.include?(expected)
54 assert_equal 1, found_email, "Expected 1 email after requesting shell access"
61 test "access users page as #{username} and verify show button is available" do
62 admin_user = api_fixture('users','admin')
63 active_user = api_fixture('users','active')
64 get :index, {}, session_for(username)
65 if username == 'admin'
66 assert_match /<a href="\/projects\/#{admin_user['uuid']}">Home<\/a>/, @response.body
67 assert_match /<a href="\/projects\/#{active_user['uuid']}">Home<\/a>/, @response.body
68 assert_match /href="\/users\/#{admin_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
69 assert_match /href="\/users\/#{active_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
70 assert_includes @response.body, admin_user['email']
71 assert_includes @response.body, active_user['email']
73 refute_match /Home<\/a>/, @response.body
74 refute_match /href="\/users\/#{admin_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
75 assert_match /href="\/users\/#{active_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
76 assert_includes @response.body, active_user['email']
85 test "access settings drop down menu as #{username}" do
86 admin_user = api_fixture('users','admin')
87 active_user = api_fixture('users','active')
89 id: api_fixture('users')[username]['uuid']
90 }, session_for(username)
91 if username == 'admin'
92 assert_includes @response.body, admin_user['email']
93 refute_empty css_select('[id="system-menu"]')
95 assert_includes @response.body, active_user['email']
96 assert_empty css_select('[id="system-menu"]')