Merge branch 'master' into 5189-manage-acct-shows-own-repos
[arvados.git] / apps / workbench / test / controllers / users_controller_test.rb
1 require 'test_helper'
2
3 class UsersControllerTest < ActionController::TestCase
4   test "valid token works in controller test" do
5     get :index, {}, session_for(:active)
6     assert_response :success
7   end
8
9   test "ignore previously valid token (for deleted user), don't crash" do
10     get :activity, {}, session_for(:valid_token_deleted_user)
11     assert_response :redirect
12     assert_match /^#{Rails.configuration.arvados_login_base}/, @response.redirect_url
13     assert_nil assigns(:my_jobs)
14     assert_nil assigns(:my_ssh_keys)
15   end
16
17   test "expired token redirects to api server login" do
18     get :show, {
19       id: api_fixture('users')['active']['uuid']
20     }, session_for(:expired_trustedclient)
21     assert_response :redirect
22     assert_match /^#{Rails.configuration.arvados_login_base}/, @response.redirect_url
23     assert_nil assigns(:my_jobs)
24     assert_nil assigns(:my_ssh_keys)
25   end
26
27   test "show welcome page if no token provided" do
28     get :index, {}
29     assert_response :redirect
30     assert_match /\/users\/welcome/, @response.redirect_url
31   end
32
33   test "show repositories with read, write, or manage permission" do
34     get :manage_account, {}, session_for(:active)
35     assert_response :success
36     repos = assigns(:my_repositories)
37     assert repos
38     assert_not_empty repos, "my_repositories should not be empty"
39     editables = repos.collect { |r| !!assigns(:repo_writable)[r.uuid] }
40     assert_includes editables, true, "should have a writable repository"
41     assert_includes editables, false, "should have a readonly repository"
42   end
43
44   test "show repositories lists linked as well as owned repositories" do
45     get :manage_account, {}, session_for(:active)
46     assert_response :success
47     repos = assigns(:my_repositories)
48     assert repos
49     repo_writables = assigns(:repo_writable)
50     assert_not_empty repo_writables, "repo_writables should not be empty"
51     assert_includes repo_writables, api_fixture('repositories')['repository4']['uuid']  # writable by active
52     assert_includes repo_writables, api_fixture('repositories')['repository2']['uuid']  # owned by active
53   end
54
55   test "request shell access" do
56     user = api_fixture('users')['spectator']
57
58     ActionMailer::Base.deliveries = []
59
60     post :request_shell_access, {
61       id: user['uuid'],
62       format: 'js'
63     }, session_for(:spectator)
64     assert_response :success
65
66     full_name = "#{user['first_name']} #{user['last_name']}"
67     expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
68     found_email = 0
69     ActionMailer::Base.deliveries.each do |email|
70       if email.subject.include?(expected)
71         found_email += 1
72         break
73       end
74     end
75     assert_equal 1, found_email, "Expected 1 email after requesting shell access"
76   end
77 end