1 require 'integration_helper'
3 class UserManageAccountTest < ActionDispatch::IntegrationTest
8 # test manage_account page
9 def verify_manage_account user
11 within('.navbar-fixed-top') do
12 find('a', text: "#{user['email']}").click
13 within('.dropdown-menu') do
14 find('a', text: 'Manage account').click
18 # now in manage account page
19 assert page.has_text?('Virtual Machines'), 'No text - Virtual Machines'
20 assert page.has_text?('Repositories'), 'No text - Repositories'
21 assert page.has_text?('SSH Keys'), 'No text - SSH Keys'
22 assert page.has_text?('Current Token'), 'No text - Current Token'
23 assert page.has_text?('The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados'), 'No text - Arvados API token'
24 add_and_verify_ssh_key
25 verify_repositories user
27 within('.navbar-fixed-top') do
28 find('a', text: "#{user['email']}").click
29 within('.dropdown-menu') do
30 assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
36 def add_and_verify_ssh_key
37 click_link 'Add new SSH key'
39 within '.modal-content' do
40 assert page.has_text?('Public Key'), 'No text - Public Key'
41 assert page.has_button?('Cancel'), 'No button - Cancel'
42 assert page.has_button?('Submit'), 'No button - Submit'
44 page.find_field('public_key').set 'first test with an incorrect ssh key value'
46 assert page.has_text?('Public key does not appear to be a valid ssh-rsa or dsa public key'), 'No text - Public key does not appear to be a valid'
48 public_key_str = api_fixture('authorized_keys')['active']['public_key']
49 page.find_field('public_key').set public_key_str
50 page.find_field('name').set 'added_in_test'
52 assert page.has_text?('Public key already exists in the database, use a different key.'), 'No text - Public key already exists'
54 new_key = SSHKey.generate
55 page.find_field('public_key').set new_key.ssh_public_key
56 page.find_field('name').set 'added_in_test'
60 # key must be added. look for it in the refreshed page
61 assert page.has_text?('added_in_test'), 'No text - added_in_test'
64 def verify_repositories user
65 Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token']
66 repo_links = Link.filter([['head_uuid', 'is_a', 'arvados#repository'],
67 ['tail_uuid', '=', user['uuid']],
68 ['link_class', '=', 'permission']])
69 repos = Repository.where uuid: repo_links.collect(&:head_uuid)
72 repositories[repo.uuid] = repo
76 repo_links.each do |link|
77 if link.name.in? ['can_write','can_manage']
78 repo_writables[link.head_uuid] = link.name
82 repo_links.each do |link|
83 if repo_writables[link.head_uuid] == 'can_manage'
84 assert_selector 'a', text: repositories[link.head_uuid]['name']
85 within('tr', text: repositories[link.head_uuid]['fetch_url']) do
86 assert_text 'writable'
89 assert_no_selector 'a', text: repositories[link.head_uuid]['name']
90 assert_text repositories[link.head_uuid]['name']
91 within('tr', text: repositories[link.head_uuid]['fetch_url']) do
92 assert_text 'read-only'
99 ['inactive', api_fixture('users')['inactive']],
100 ['inactive_uninvited', api_fixture('users')['inactive_uninvited']],
101 ['active', api_fixture('users')['active']],
102 ['admin', api_fixture('users')['admin']],
103 ].each do |token, user|
104 test "test manage account for user #{token}" do
105 visit page_with_token(token)
106 verify_manage_account user
111 ['inactive_but_signed_user_agreement', true],
113 ].each do |user, notifications|
114 test "test manage account for #{user} with notifications #{notifications}" do
115 visit page_with_token(user)
116 click_link 'notifications-menu'
118 assert_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
119 assert_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
120 click_link('Click here to set up an SSH public key for use with Arvados')
121 assert_selector('a', text: 'Add new SSH key')
123 add_and_verify_ssh_key
125 # No more SSH notification
126 click_link 'notifications-menu'
127 assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
128 assert_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')
130 assert_no_selector('a', text: 'Click here to set up an SSH public key for use with Arvados')
131 assert_no_selector('a', text: 'Click here to learn how to run an Arvados Crunch pipeline')