Merge branch '14328-watch-docker-ps'
[arvados.git] / services / api / test / integration / user_sessions_test.rb
index a46a4d1bc29c0e25992f6424bb4f50b919020229..0497c6a7d56294ae3d0841db5acd8ef9a441d809 100644 (file)
@@ -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),