Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / test / integration / link_account_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'integration_helper'
6 require 'webrick'
7
8 class LinkAccountTest < ActionDispatch::IntegrationTest
9   setup do
10     need_javascript
11   end
12
13   teardown do
14     Rails.configuration.testing_override_login_url = false
15   end
16
17   def start_sso_stub token
18     port = available_port('sso_stub')
19
20     s = WEBrick::HTTPServer.new(
21       :Port => port,
22       :BindAddress => 'localhost',
23       :Logger => WEBrick::Log.new('/dev/null', WEBrick::BasicLog::DEBUG),
24       :AccessLog => [nil,nil]
25     )
26
27     s.mount_proc("/login"){|req, res|
28       res.set_redirect(WEBrick::HTTPStatus::TemporaryRedirect, req.query["return_to"] + "&api_token=#{token}")
29       s.shutdown
30     }
31
32     s.mount_proc("/logout"){|req, res|
33       res.set_redirect(WEBrick::HTTPStatus::TemporaryRedirect, req.query["return_to"])
34     }
35
36     Thread.new do
37       s.start
38     end
39
40     "http://localhost:#{port}/"
41   end
42
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'])
46
47     find("#notifications-menu").click
48     assert_text "active-user@arvados.local"
49
50     find("a", text: "Link account").click
51     find("button", text: "Add another login to this account").click
52
53     find("#notifications-menu").click
54     assert_text "project-viewer@arvados.local"
55
56     find("button", text: "Link accounts").click
57
58     find("#notifications-menu").click
59     assert_text "active-user@arvados.local"
60   end
61
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'])
65
66     find("#notifications-menu").click
67     assert_text "project-viewer@arvados.local"
68
69     find("a", text: "Link account").click
70     find("button", text: "Use this login to access another account").click
71
72     find("#notifications-menu").click
73     assert_text "active-user@arvados.local"
74
75     find("button", text: "Link accounts").click
76
77     find("#notifications-menu").click
78     assert_text "active-user@arvados.local"
79   end
80
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'])
84
85     find("#notifications-menu").click
86     assert_text "active-user@arvados.local"
87
88     find("a", text: "Link account").click
89     find("button", text: "Add another login to this account").click
90
91     find("#notifications-menu").click
92     assert_text "inactive-uninvited-user@arvados.local"
93
94     find("button", text: "Link accounts").click
95
96     find("#notifications-menu").click
97     assert_text "active-user@arvados.local"
98   end
99
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'])
103
104     find("#notifications-menu").click
105     assert_text "active-user@arvados.local"
106
107     find("a", text: "Link account").click
108     find("button", text: "Use this login to access another account").click
109
110     find("#notifications-menu").click
111     assert_text "inactive-uninvited-user@arvados.local"
112
113     assert_text "Cannot link active-user@arvados.local"
114
115     assert find("#link-account-submit")['disabled']
116
117     find("button", text: "Cancel").click
118
119     find("#notifications-menu").click
120     assert_text "active-user@arvados.local"
121   end
122
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'])
126
127     find("#notifications-menu").click
128     assert_text "inactive-uninvited-user@arvados.local"
129
130     assert_text "Already have an account with a different login?"
131
132     find("a", text: "Link this login to your existing account").click
133
134     assert_no_text "Add another login to this account"
135
136     find("button", text: "Use this login to access another account").click
137
138     find("#notifications-menu").click
139     assert_text "active-user@arvados.local"
140
141     find("button", text: "Link accounts").click
142
143     find("#notifications-menu").click
144     assert_text "active-user@arvados.local"
145   end
146
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'])
150
151     find("#notifications-menu").click
152     assert_text "admin@arvados.local"
153
154     find("a", text: "Link account").click
155     find("button", text: "Use this login to access another account").click
156
157     find("#notifications-menu").click
158     assert_text "active-user@arvados.local"
159
160     assert_text "Cannot link admin account admin@arvados.local"
161
162     assert find("#link-account-submit")['disabled']
163
164     find("button", text: "Cancel").click
165
166     find("#notifications-menu").click
167     assert_text "admin@arvados.local"
168   end
169
170 end