X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/09a2e88c51e5432e607f2a38466e55b4ba15e887..2b8f39b5067103d60f7bc43d26cb2f59126b2a42:/services/api/test/integration/user_sessions_test.rb diff --git a/services/api/test/integration/user_sessions_test.rb b/services/api/test/integration/user_sessions_test.rb index 7a9f9176d3..0497c6a7d5 100644 --- a/services/api/test/integration/user_sessions_test.rb +++ b/services/api/test/integration/user_sessions_test.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class UserSessionsApiTest < ActionDispatch::IntegrationTest @@ -5,7 +9,7 @@ class UserSessionsApiTest < ActionDispatch::IntegrationTest 'https://wb.example.com' end - def mock_auth_with(email: nil, username: nil) + def mock_auth_with(email: nil, username: nil, identity_url: nil) mock = { 'provider' => 'josh_id', 'uid' => 'https://edward.example.com', @@ -18,6 +22,7 @@ class UserSessionsApiTest < ActionDispatch::IntegrationTest } mock['info']['email'] = email unless email.nil? mock['info']['username'] = username unless username.nil? + mock['info']['identity_url'] = identity_url unless identity_url.nil? post('/auth/josh_id/callback', {return_to: client_url}, {'omniauth.auth' => mock}) @@ -36,6 +41,24 @@ class UserSessionsApiTest < ActionDispatch::IntegrationTest assert_equal 'foo', u.username end + test 'existing user login' do + mock_auth_with(identity_url: "https://active-user.openid.local") + u = assigns(:user) + assert_equal 'zzzzz-tpzed-xurymjxw79nv3jz', u.uuid + end + + test 'user redirect_to_user_uuid' do + mock_auth_with(identity_url: "https://redirects-to-active-user.openid.local") + u = assigns(:user) + assert_equal 'zzzzz-tpzed-xurymjxw79nv3jz', u.uuid + end + + test 'user double redirect_to_user_uuid' do + mock_auth_with(identity_url: "https://double-redirects-to-active-user.openid.local") + u = assigns(:user) + assert_equal 'zzzzz-tpzed-xurymjxw79nv3jz', u.uuid + end + test 'create new user during omniauth callback' do mock_auth_with(email: 'edward@example.com') assert_equal(0, @response.redirect_url.index(client_url), @@ -110,7 +133,7 @@ class UserSessionsApiTest < ActionDispatch::IntegrationTest (repos.collect(&:name) + vm_links.collect { |link| link.properties['username'] } ).each do |name| - r = name.match /^(.{#{prefix.length}})(\d+)$/ + r = name.match(/^(.{#{prefix.length}})(\d+)$/) assert_not_nil r, "#{name.inspect} does not match {prefix}\\d+" assert_equal(prefix, r[1], "#{name.inspect} was not {#{prefix.inspect} plus digits}")