1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'integration_helper'
8 class LinkAccountTest < ActionDispatch::IntegrationTest
14 Rails.configuration.testing_override_login_url = false
17 def start_sso_stub token
18 port = available_port('sso_stub')
20 s = WEBrick::HTTPServer.new(
22 :BindAddress => 'localhost',
23 :Logger => WEBrick::Log.new('/dev/null', WEBrick::BasicLog::DEBUG),
24 :AccessLog => [nil,nil]
27 s.mount_proc("/login"){|req, res|
28 res.set_redirect(WEBrick::HTTPStatus::TemporaryRedirect, req.query["return_to"] + "&api_token=#{token}")
32 s.mount_proc("/logout"){|req, res|
33 res.set_redirect(WEBrick::HTTPStatus::TemporaryRedirect, req.query["return_to"])
40 "http://localhost:#{port}/"
43 test "Add another login to this account" do
44 visit page_with_token('active_trustedclient')
45 Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['project_viewer_trustedclient']['api_token'])
47 find("#notifications-menu").click
48 assert_text "active-user@arvados.local"
50 find("a", text: "Link account").click
51 find("button", text: "Add another login to this account").click
53 find("#notifications-menu").click
54 assert_text "project-viewer@arvados.local"
56 find("button", text: "Link accounts").click
58 find("#notifications-menu").click
59 assert_text "active-user@arvados.local"
62 test "Use this login to access another account" do
63 visit page_with_token('project_viewer_trustedclient')
64 Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['active_trustedclient']['api_token'])
66 find("#notifications-menu").click
67 assert_text "project-viewer@arvados.local"
69 find("a", text: "Link account").click
70 find("button", text: "Use this login to access another account").click
72 find("#notifications-menu").click
73 assert_text "active-user@arvados.local"
75 find("button", text: "Link accounts").click
77 find("#notifications-menu").click
78 assert_text "active-user@arvados.local"
81 test "Link login of inactive user to this account" do
82 visit page_with_token('active_trustedclient')
83 Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['inactive_uninvited_trustedclient']['api_token'])
85 find("#notifications-menu").click
86 assert_text "active-user@arvados.local"
88 find("a", text: "Link account").click
89 find("button", text: "Add another login to this account").click
91 find("#notifications-menu").click
92 assert_text "inactive-uninvited-user@arvados.local"
94 find("button", text: "Link accounts").click
96 find("#notifications-menu").click
97 assert_text "active-user@arvados.local"
100 test "Cannot link to inactive user" do
101 visit page_with_token('active_trustedclient')
102 Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['inactive_uninvited_trustedclient']['api_token'])
104 find("#notifications-menu").click
105 assert_text "active-user@arvados.local"
107 find("a", text: "Link account").click
108 find("button", text: "Use this login to access another account").click
110 find("#notifications-menu").click
111 assert_text "inactive-uninvited-user@arvados.local"
113 assert_text "Cannot link active-user@arvados.local"
115 assert find("#link-account-submit")['disabled']
117 find("button", text: "Cancel").click
119 find("#notifications-menu").click
120 assert_text "active-user@arvados.local"
123 test "Inactive user can link to active account" do
124 visit page_with_token('inactive_uninvited_trustedclient')
125 Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['active_trustedclient']['api_token'])
127 find("#notifications-menu").click
128 assert_text "inactive-uninvited-user@arvados.local"
130 assert_text "Already have an account with a different login?"
132 find("a", text: "Link this login to your existing account").click
134 assert_no_text "Add another login to this account"
136 find("button", text: "Use this login to access another account").click
138 find("#notifications-menu").click
139 assert_text "active-user@arvados.local"
141 find("button", text: "Link accounts").click
143 find("#notifications-menu").click
144 assert_text "active-user@arvados.local"
147 test "Admin cannot link to non-admin" do
148 visit page_with_token('admin_trustedclient')
149 Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['active_trustedclient']['api_token'])
151 find("#notifications-menu").click
152 assert_text "admin@arvados.local"
154 find("a", text: "Link account").click
155 find("button", text: "Use this login to access another account").click
157 find("#notifications-menu").click
158 assert_text "active-user@arvados.local"
160 assert_text "Cannot link admin account admin@arvados.local"
162 assert find("#link-account-submit")['disabled']
164 find("button", text: "Cancel").click
166 find("#notifications-menu").click
167 assert_text "admin@arvados.local"