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 "show repositories with read, write, or manage permission" do
35 get :repositories, {id: api_fixture("users")['active']['uuid']}, session_for(:active)
36 assert_response :success
37 repos = assigns(:my_repositories)
39 assert_not_empty repos, "my_repositories should not be empty"
40 editables = repos.collect { |r| !!assigns(:repo_writable)[r.uuid] }
41 assert_includes editables, true, "should have a writable repository"
42 assert_includes editables, false, "should have a readonly repository"
45 test "show repositories lists linked as well as owned repositories" do
46 get :repositories, {id: api_fixture("users")['active']['uuid']}, session_for(:active)
47 assert_response :success
48 repos = assigns(:my_repositories)
50 assert_not_empty repos, "my_repositories should not be empty"
51 repo_uuids = repos.map(&:uuid)
52 assert_includes repo_uuids, api_fixture('repositories')['repository2']['uuid'] # owned by active
53 assert_includes repo_uuids, api_fixture('repositories')['repository4']['uuid'] # shared with active
54 assert_includes repo_uuids, api_fixture('repositories')['arvados']['uuid'] # shared with all_users
57 test "request shell access" do
58 user = api_fixture('users')['spectator']
60 ActionMailer::Base.deliveries = []
62 post :request_shell_access, {
65 }, session_for(:spectator)
66 assert_response :success
68 full_name = "#{user['first_name']} #{user['last_name']}"
69 expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
71 ActionMailer::Base.deliveries.each do |email|
72 if email.subject.include?(expected)
77 assert_equal 1, found_email, "Expected 1 email after requesting shell access"
84 test "access users page as #{username} and verify show button is available" do
85 admin_user = api_fixture('users','admin')
86 active_user = api_fixture('users','active')
87 get :index, {}, session_for(username)
88 if username == 'admin'
89 assert_match /<a href="\/projects\/#{admin_user['uuid']}">Home<\/a>/, @response.body
90 assert_match /<a href="\/projects\/#{active_user['uuid']}">Home<\/a>/, @response.body
91 assert_match /href="\/users\/#{admin_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
92 assert_match /href="\/users\/#{active_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
93 assert_includes @response.body, admin_user['email']
94 assert_includes @response.body, active_user['email']
96 refute_match /Home<\/a>/, @response.body
97 refute_match /href="\/users\/#{admin_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
98 assert_match /href="\/users\/#{active_user['uuid']}" title="show user"><i class="fa fa-fw fa-user"><\/i> Show<\/a/, @response.body
99 assert_includes @response.body, active_user['email']
108 test "access settings drop down menu as #{username}" do
109 admin_user = api_fixture('users','admin')
110 active_user = api_fixture('users','active')
112 id: api_fixture('users')[username]['uuid']
113 }, session_for(username)
114 if username == 'admin'
115 assert_includes @response.body, admin_user['email']
116 refute_empty css_select('[id="system-menu"]')
118 assert_includes @response.body, active_user['email']
119 assert_empty css_select('[id="system-menu"]')