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, params: {}, session: session_for(:active)
11 assert_response :success
14 test "ignore previously valid token (for deleted user), don't crash" do
15 get :activity, params: {}, session: session_for(:valid_token_deleted_user)
16 assert_response :redirect
17 assert_match /^#{Rails.configuration.Services.Controller.ExternalURL}\/login/, @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: session_for(:expired_trustedclient)
26 assert_response :redirect
27 assert_match /^#{Rails.configuration.Services.Controller.ExternalURL}\/login/, @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
33 get :index, params: {}
34 assert_response :redirect
35 assert_match /\/users\/welcome/, @response.redirect_url
38 test "'log in as user' feature uses a v2 token" do
40 id: api_fixture('users')['active']['uuid']
41 }, session: session_for('admin_trustedclient')
42 assert_response :redirect
43 assert_match /api_token=v2%2F/, @response.redirect_url
46 test "request shell access" do
47 user = api_fixture('users')['spectator']
49 ActionMailer::Base.deliveries = []
51 post :request_shell_access, params: {
54 }, session: session_for(:spectator)
55 assert_response :success
57 full_name = "#{user['first_name']} #{user['last_name']}"
58 expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
60 ActionMailer::Base.deliveries.each do |email|
61 if email.subject.include?(expected)
66 assert_equal 1, found_email, "Expected 1 email after requesting shell access"
73 test "access users page as #{username} and verify show button is available" do
74 admin_user = api_fixture('users','admin')
75 active_user = api_fixture('users','active')
76 get :index, params: {}, session: session_for(username)
77 if username == 'admin'
78 assert_match /<a href="\/projects\/#{admin_user['uuid']}">Home<\/a>/, @response.body
79 assert_match /<a href="\/projects\/#{active_user['uuid']}">Home<\/a>/, @response.body
80 assert_match /href="\/users\/#{admin_user['uuid']}"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
81 assert_match /href="\/users\/#{active_user['uuid']}"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
82 assert_includes @response.body, admin_user['email']
83 assert_includes @response.body, active_user['email']
85 refute_match /Home<\/a>/, @response.body
86 refute_match /href="\/users\/#{admin_user['uuid']}"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
87 assert_match /href="\/users\/#{active_user['uuid']}"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
88 assert_includes @response.body, active_user['email']
97 test "access settings drop down menu as #{username}" do
98 admin_user = api_fixture('users','admin')
99 active_user = api_fixture('users','active')
101 id: api_fixture('users')[username]['uuid']
102 }, session: session_for(username)
103 if username == 'admin'
104 assert_includes @response.body, admin_user['email']
105 refute_empty css_select('[id="system-menu"]')
107 assert_includes @response.body, active_user['email']
108 assert_empty css_select('[id="system-menu"]')