1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class UsersControllerTest < ActionController::TestCase
9 test "valid token works in controller test" do
10 get :index, {}, session_for(:active)
11 assert_response :success
14 test "ignore previously valid token (for deleted user), don't crash" do
15 get :activity, {}, session_for(:valid_token_deleted_user)
16 assert_response :redirect
17 assert_match /^#{Rails.configuration.arvados_login_base}/, @response.redirect_url
18 assert_nil assigns(:my_jobs)
19 assert_nil assigns(:my_ssh_keys)
22 test "expired token redirects to api server login" do
24 id: api_fixture('users')['active']['uuid']
25 }, session_for(:expired_trustedclient)
26 assert_response :redirect
27 assert_match /^#{Rails.configuration.arvados_login_base}/, @response.redirect_url
28 assert_nil assigns(:my_jobs)
29 assert_nil assigns(:my_ssh_keys)
32 test "show welcome page if no token provided" do
34 assert_response :redirect
35 assert_match /\/users\/welcome/, @response.redirect_url
38 test "request shell access" do
39 user = api_fixture('users')['spectator']
41 ActionMailer::Base.deliveries = []
43 post :request_shell_access, {
46 }, session_for(:spectator)
47 assert_response :success
49 full_name = "#{user['first_name']} #{user['last_name']}"
50 expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
52 ActionMailer::Base.deliveries.each do |email|
53 if email.subject.include?(expected)
58 assert_equal 1, found_email, "Expected 1 email after requesting shell access"
65 test "access users page as #{username} and verify show button is available" do
66 admin_user = api_fixture('users','admin')
67 active_user = api_fixture('users','active')
68 get :index, {}, session_for(username)
69 if username == 'admin'
70 assert_match /<a href="\/projects\/#{admin_user['uuid']}">Home<\/a>/, @response.body
71 assert_match /<a href="\/projects\/#{active_user['uuid']}">Home<\/a>/, @response.body
72 assert_match /href="\/users\/#{admin_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
73 assert_match /href="\/users\/#{active_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
74 assert_includes @response.body, admin_user['email']
75 assert_includes @response.body, active_user['email']
77 refute_match /Home<\/a>/, @response.body
78 refute_match /href="\/users\/#{admin_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
79 assert_match /href="\/users\/#{active_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
80 assert_includes @response.body, active_user['email']
89 test "access settings drop down menu as #{username}" do
90 admin_user = api_fixture('users','admin')
91 active_user = api_fixture('users','active')
93 id: api_fixture('users')[username]['uuid']
94 }, session_for(username)
95 if username == 'admin'
96 assert_includes @response.body, admin_user['email']
97 refute_empty css_select('[id="system-menu"]')
99 assert_includes @response.body, active_user['email']
100 assert_empty css_select('[id="system-menu"]')