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.Workbench1.ExternalURL}users\/welcome/, @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
23 assert Rails.configuration.Login.Test.Enable
25 id: api_fixture('users')['active']['uuid']
26 }, session: session_for(:expired_trustedclient)
27 assert_response :redirect
28 assert_match /^#{Rails.configuration.Services.Workbench1.ExternalURL}users\/welcome/, @response.redirect_url
29 assert_nil assigns(:my_jobs)
30 assert_nil assigns(:my_ssh_keys)
33 test "show welcome page if no token provided" do
34 get :index, params: {}
35 assert_response :redirect
36 assert_match /\/users\/welcome/, @response.redirect_url
39 test "'log in as user' feature uses a v2 token" do
41 id: api_fixture('users')['active']['uuid']
42 }, session: session_for('admin_trustedclient')
43 assert_response :redirect
44 assert_match /api_token=v2%2F/, @response.redirect_url
47 test "request shell access" do
48 user = api_fixture('users')['spectator']
50 ActionMailer::Base.deliveries = []
52 post :request_shell_access, params: {
55 }, session: session_for(:spectator)
56 assert_response :success
58 full_name = "#{user['first_name']} #{user['last_name']}"
59 expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
61 ActionMailer::Base.deliveries.each do |email|
62 if email.subject.include?(expected)
67 assert_equal 1, found_email, "Expected 1 email after requesting shell access"
74 test "access users page as #{username} and verify show button is available" do
75 admin_user = api_fixture('users','admin')
76 active_user = api_fixture('users','active')
77 get :index, params: {}, session: session_for(username)
78 if username == 'admin'
79 assert_match /<a href="\/projects\/#{admin_user['uuid']}">Home<\/a>/, @response.body
80 assert_match /<a href="\/projects\/#{active_user['uuid']}">Home<\/a>/, @response.body
81 assert_match /href="\/users\/#{admin_user['uuid']}"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
82 assert_match /href="\/users\/#{active_user['uuid']}"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
83 assert_includes @response.body, admin_user['email']
84 assert_includes @response.body, active_user['email']
86 refute_match /Home<\/a>/, @response.body
87 refute_match /href="\/users\/#{admin_user['uuid']}"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
88 assert_match /href="\/users\/#{active_user['uuid']}"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
89 assert_includes @response.body, active_user['email']
98 test "access settings drop down menu as #{username}" do
99 admin_user = api_fixture('users','admin')
100 active_user = api_fixture('users','active')
102 id: api_fixture('users')[username]['uuid']
103 }, session: session_for(username)
104 if username == 'admin'
105 assert_includes @response.body, admin_user['email']
106 refute_empty css_select('[id="system-menu"]')
108 assert_includes @response.body, active_user['email']
109 assert_empty css_select('[id="system-menu"]')