1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'integration_helper'
7 class UserSettingsMenuTest < ActionDispatch::IntegrationTest
12 # test user settings menu
13 def verify_user_settings_menu user
15 within('.navbar-fixed-top') do
16 page.find("#notifications-menu").click
17 within('.dropdown-menu') do
18 assert_selector 'a', text: 'Virtual machines'
19 assert_selector 'a', text: 'Repositories'
20 assert_selector 'a', text: 'Current token'
21 assert_selector 'a', text: 'SSH keys'
22 find('a', text: 'SSH keys').click
26 # now in SSH Keys page
27 assert page.has_text?('Add new SSH key'), 'No text - Add SSH key'
28 add_and_verify_ssh_key
30 within('.navbar-fixed-top') do
31 page.find("#notifications-menu").click
32 within('.dropdown-menu') do
33 assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
39 def add_and_verify_ssh_key
40 click_link 'Add new SSH key'
42 within '.modal-content' do
43 assert page.has_text?('Public Key'), 'No text - Public Key'
44 assert page.has_button?('Cancel'), 'No button - Cancel'
45 assert page.has_button?('Submit'), 'No button - Submit'
47 page.find_field('public_key').set 'first test with an incorrect ssh key value'
49 assert_text 'Public key does not appear to be a valid ssh-rsa or dsa public key'
51 public_key_str = api_fixture('authorized_keys')['active']['public_key']
52 page.find_field('public_key').set public_key_str
53 page.find_field('name').set 'added_in_test'
55 assert_text 'Public key already exists in the database, use a different key.'
57 new_key = SSHKey.generate
58 page.find_field('public_key').set new_key.ssh_public_key
59 page.find_field('name').set 'added_in_test'
63 # key must be added. look for it in the refreshed page
64 assert_text 'added_in_test'
68 ['inactive', api_fixture('users')['inactive']],
69 ['inactive_uninvited', api_fixture('users')['inactive_uninvited']],
70 ['active', api_fixture('users')['active']],
71 ['admin', api_fixture('users')['admin']],
72 ].each do |token, user|
73 test "test user settings menu for user #{token}" do
74 visit page_with_token(token)
75 verify_user_settings_menu user
79 test "pipeline notification shown even though public pipelines exist" do
80 skip "created_by doesn't work that way"
81 Rails.configuration.Users.AnonymousUserToken = api_fixture('api_client_authorizations')['anonymous']['api_token']
82 visit page_with_token 'job_reader'
83 click_link 'notifications-menu'
84 assert_selector 'a', text: 'Click here to learn how to run an Arvados Crunch pipeline'
88 ['job_reader', :ssh, :pipeline],
90 ].each do |user, *expect|
91 test "user settings menu for #{user} with notifications #{expect.inspect}" do
92 Rails.configuration.Users.AnonymousUserToken = ""
93 visit page_with_token(user)
94 click_link 'notifications-menu'
95 if expect.include? :ssh
96 assert_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
97 click_link('Click here to set up an SSH public key for use with Arvados')
98 assert_selector('a', text: 'Add new SSH key')
100 add_and_verify_ssh_key
102 # No more SSH notification
103 click_link 'notifications-menu'
104 assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
106 assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
107 assert_no_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
110 if expect.include? :pipeline
111 assert_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
116 test "verify repositories for active user" do
117 visit page_with_token('active',"/repositories")
119 repos = [[api_fixture('repositories')['foo'], true],
120 [api_fixture('repositories')['repository3'], false],
121 [api_fixture('repositories')['repository4'], false],
122 [api_fixture('repositories')['arvados'], false]]
124 repos.each do |(repo, owned)|
125 within('tr', text: repo['name']+'.git') do
126 assert_text repo['name']
127 assert_selector 'a', text:'Show'
129 assert_not_nil first('.glyphicon-trash')
131 assert_nil first('.glyphicon-trash')
137 test "request shell access" do
138 ActionMailer::Base.deliveries = []
139 visit page_with_token('spectator', "/users/#{api_fixture('users')['spectator']['uuid']}/virtual_machines")
140 assert_text 'You do not have access to any virtual machines'
141 click_link 'Send request for shell access'
143 # Button text changes to "sending...", then back to normal. In the
144 # test suite we can't depend on confirming the "sending..." state
145 # before it goes back to normal, though.
146 ## assert_selector 'a', text: 'Sending request...'
147 assert_selector 'a', text: 'Send request for shell access'
148 assert_text 'A request for shell access was sent'
150 # verify that the email was sent
151 user = api_fixture('users')['spectator']
152 full_name = "#{user['first_name']} #{user['last_name']}"
153 expected = "Shell account request from #{full_name} (#{user['email']}, #{user['uuid']})"
155 ActionMailer::Base.deliveries.each do |email|
156 if email.subject.include?(expected)
160 assert_equal 1, found_email, "Expected email after requesting shell access"
162 # Revisit the page and verify the request sent message along with
163 # the request button.
164 within('.navbar-fixed-top') do
165 page.find("#notifications-menu").click
166 within('.dropdown-menu') do
167 find('a', text: 'Virtual machines').click
170 assert_text 'You do not have access to any virtual machines.'
171 assert_text 'A request for shell access was sent on '
172 assert_selector 'a', text: 'Send request for shell access'
175 test "create new repository" do
176 visit page_with_token("active_trustedclient")
177 within('.navbar-fixed-top') do
178 page.find("#notifications-menu").click
179 within('.dropdown-menu') do
180 assert_selector 'a', text: 'Repositories'
181 find('a', text: 'Repositories').click
184 click_on "Add new repository"
185 within ".modal-dialog" do
186 fill_in "Name", with: "workbenchtest"
189 assert_text ":active/workbenchtest.git"
190 assert_match /git@git.*:active\/workbenchtest.git/, page.text
191 assert_match /#{Rails.configuration.Services.GitHTTP.ExternalURL.to_s}\/active\/workbenchtest.git/, page.text
195 ['virtual_machines', nil, 'Host name', 'testvm2.shell'],
196 ['/repositories', 'Add new repository', 'It may take a minute or two before you can clone your new repository.', 'active/foo'],
197 ['/current_token', nil, 'HISTIGNORE=$HISTIGNORE', 'ARVADOS_API_TOKEN=3kg6k6lzmp9kj5'],
198 ['ssh_keys', 'Add new SSH key', 'Click here to learn about SSH keys in Arvados.', 'active'],
199 ].each do |page_name, button_name, look_for, content|
200 test "test user settings menu for page #{page_name}" do
201 if page_name == '/current_token' || page_name == '/repositories'
202 visit page_with_token('active', page_name)
204 visit page_with_token('active', "/users/#{api_fixture('users')['active']['uuid']}/#{page_name}")
207 assert page.has_text? content
209 assert_selector 'a', text: button_name
210 find('a', text: button_name).click
213 assert page.has_text? look_for
218 ['virtual_machines', 'You do not have access to any virtual machines.'],
219 ['/repositories', api_fixture('repositories')['arvados']['name']],
220 ['/current_token', 'HISTIGNORE=$HISTIGNORE'],
221 ['ssh_keys', 'You have not yet set up an SSH public key for use with Arvados.'],
222 ].each do |page_name, look_for|
223 test "test user settings menu for page #{page_name} when page is empty" do
224 if page_name == '/current_token' || page_name == '/repositories'
225 visit page_with_token('user1_with_load', page_name)
227 visit page_with_token('admin', "/users/#{api_fixture('users')['user1_with_load']['uuid']}/#{page_name}")
230 assert page.has_text? look_for
231 if page_name == '/repositories'
232 assert_equal 1, page.all('a[data-original-title="show repository"]').count