[ARVADOS] created: 195c34017a79a081b7ad666935fb2d4aaab96c14

git at public.curoverse.com git at public.curoverse.com
Fri Aug 22 22:57:30 EDT 2014


        at  195c34017a79a081b7ad666935fb2d4aaab96c14 (commit)


commit 195c34017a79a081b7ad666935fb2d4aaab96c14
Author: Tom Clegg <tom at curoverse.com>
Date:   Fri Aug 22 22:46:53 2014 -0400

    3153: Add integration tests.

diff --git a/services/api/app/controllers/user_sessions_controller.rb b/services/api/app/controllers/user_sessions_controller.rb
index 696ae02..3e79915 100644
--- a/services/api/app/controllers/user_sessions_controller.rb
+++ b/services/api/app/controllers/user_sessions_controller.rb
@@ -57,6 +57,9 @@ class UserSessionsController < ApplicationController
       end
     end
 
+    # For the benefit of functional and integration tests:
+    @user = user
+
     # prevent ArvadosModel#before_create and _update from throwing
     # "unauthorized":
     Thread.current[:user] = user
diff --git a/services/api/test/functional/arvados/v1/links_controller_test.rb b/services/api/test/functional/arvados/v1/links_controller_test.rb
index b131947..4858139 100644
--- a/services/api/test/functional/arvados/v1/links_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/links_controller_test.rb
@@ -118,7 +118,7 @@ class Arvados::V1::LinksControllerTest < ActionController::TestCase
       link_class: 'test',
       name: 'stuff',
       head_uuid: users(:active).uuid,
-      tail_uuid: virtual_machines(:testvm).uuid
+      tail_uuid: virtual_machines(:testvm2).uuid
     }
     authorize_with :active
     post :create, link: link
diff --git a/services/api/test/functional/arvados/v1/users_controller_test.rb b/services/api/test/functional/arvados/v1/users_controller_test.rb
index 1a8e94f..4a9d12d 100644
--- a/services/api/test/functional/arvados/v1/users_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/users_controller_test.rb
@@ -1044,9 +1044,14 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
       assert !repo_perms.any?, "expected all repo_perms deleted"
     end
 
-    vm_login_perms = Link.where(tail_uuid: uuid,
-                              link_class: 'permission',
-                              name: 'can_login').where("head_uuid like ?", VirtualMachine.uuid_like_pattern)
+    vm_login_perms = Link.
+      where(tail_uuid: uuid,
+            link_class: 'permission',
+            name: 'can_login').
+      where("head_uuid like ?",
+            VirtualMachine.uuid_like_pattern).
+      where('uuid <> ?',
+            links(:auto_setup_vm_login_username_can_login_to_test_vm).uuid)
     if expect_vm_perms
       assert vm_login_perms.any?, "expected vm_login_perms"
     else
@@ -1057,9 +1062,9 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
       g[:uuid].match /-f+$/
     end.first
     group_read_perms = Link.where(tail_uuid: uuid,
-                             head_uuid: group[:uuid],
-                             link_class: 'permission',
-                             name: 'can_read')
+                                  head_uuid: group[:uuid],
+                                  link_class: 'permission',
+                                  name: 'can_read')
     if expect_group_perms
       assert group_read_perms.any?, "expected all users group read perms"
     else
@@ -1067,7 +1072,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     end
 
     signed_uuids = Link.where(link_class: 'signature',
-                                  tail_uuid: uuid)
+                              tail_uuid: uuid)
 
     if expect_signatures
       assert signed_uuids.any?, "expected signatures"
diff --git a/services/api/test/integration/user_sessions_test.rb b/services/api/test/integration/user_sessions_test.rb
index 321a5ac..814e6eb 100644
--- a/services/api/test/integration/user_sessions_test.rb
+++ b/services/api/test/integration/user_sessions_test.rb
@@ -1,7 +1,11 @@
 require 'test_helper'
 
 class UserSessionsApiTest < ActionDispatch::IntegrationTest
-  test 'create new user during omniauth callback' do
+  def client_url
+    'https://wb.example.com'
+  end
+
+  def mock_auth_with_email email
     mock = {
       'provider' => 'josh_id',
       'uid' => 'https://edward.example.com',
@@ -10,14 +14,17 @@ class UserSessionsApiTest < ActionDispatch::IntegrationTest
         'name' => 'Edward Example',
         'first_name' => 'Edward',
         'last_name' => 'Example',
-        'email' => 'edward at example.com',
+        'email' => email,
       },
     }
-    client_url = 'https://wb.example.com'
     post('/auth/josh_id/callback',
          {return_to: client_url},
          {'omniauth.auth' => mock})
     assert_response :redirect, 'Did not redirect to client with token'
+  end
+
+  test 'create new user during omniauth callback' do
+    mock_auth_with_email 'edward at example.com'
     assert_equal(0, @response.redirect_url.index(client_url),
                  'Redirected to wrong address after succesful login: was ' +
                  @response.redirect_url + ', expected ' + client_url + '[...]')
@@ -25,4 +32,77 @@ class UserSessionsApiTest < ActionDispatch::IntegrationTest
                    'Expected api_token in query string of redirect url ' +
                    @response.redirect_url)
   end
+
+  # Test various combinations of auto_setup configuration and email
+  # address provided during a new user's first session setup.
+  [{result: :nope, email: nil, cfg: {auto: true, repo: true, vm: true}},
+   {result: :yup, email: nil, cfg: {auto: true}},
+   {result: :nope, email: '@example.com', cfg: {auto: true, repo: true, vm: true}},
+   {result: :yup, email: '@example.com', cfg: {auto: true}},
+   {result: :nope, email: 'root@', cfg: {auto: true, repo: true, vm: true}},
+   {result: :nope, email: 'root@', cfg: {auto: true, repo: true}},
+   {result: :nope, email: 'root@', cfg: {auto: true, vm: true}},
+   {result: :yup, email: 'root@', cfg: {auto: true}},
+   {result: :nope, email: 'gitolite@', cfg: {auto: true, repo: true}},
+   {result: :nope, email: '*_*@', cfg: {auto: true, vm: true}},
+   {result: :yup, email: 'toor@', cfg: {auto: true, vm: true, repo: true}},
+   {result: :yup, email: 'foo@', cfg: {auto: true, vm: true},
+     uniqprefix: 'foo'},
+   {result: :yup, email: 'foo@', cfg: {auto: true, repo: true},
+     uniqprefix: 'foo'},
+   {result: :yup, email: 'auto_setup_vm_login@', cfg: {auto: true, repo: true},
+     uniqprefix: 'auto_setup_vm_login'},
+   ].each do |testcase|
+    test "user auto-activate #{testcase.inspect}" do
+      # Configure auto_setup behavior according to testcase[:cfg]
+      Rails.configuration.auto_setup_new_users = testcase[:cfg][:auto]
+      Rails.configuration.auto_setup_new_users_with_vm_uuid =
+        (testcase[:cfg][:vm] ? virtual_machines(:testvm).uuid : false)
+      Rails.configuration.auto_setup_new_users_with_repository =
+        testcase[:cfg][:repo]
+
+      mock_auth_with_email testcase[:email]
+      u = assigns(:user)
+      vm_links = Link.where('link_class=? and tail_uuid=? and head_uuid like ?',
+                            'permission', u.uuid,
+                            '%-' + VirtualMachine.uuid_prefix + '-%')
+      repo_links = Link.where('link_class=? and tail_uuid=? and head_uuid like ?',
+                              'permission', u.uuid,
+                              '%-' + Repository.uuid_prefix + '-%')
+      repos = Repository.where('uuid in (?)', repo_links.collect(&:head_uuid))
+      case u[:result]
+      when :nope
+        assert_equal false, u.is_invited, "should not have been set up"
+        assert_empty vm_links, "should not have VM login permission"
+        assert_empty repo_links, "should not have repo permission"
+      when :yup
+        assert_equal true, u.is_invited
+        if testcase[:cfg][:vm]
+          assert_equal 1, vm_links.count, "wrong number of VM perm links"
+        else
+          assert_empty vm_links, "should not have VM login permission"
+        end
+        if testcase[:cfg][:repo]
+          assert_equal 1, repo_links.count, "wrong number of repo perm links"
+          assert_equal 1, repos.count, "wrong number of repos"
+          assert_equal 'can_manage', repo_links.first.name, "wrong perm type"
+        else
+          assert_empty repo_links, "should not have repo permission"
+        end
+      end
+      if (prefix = testcase[:uniqprefix])
+        # This email address conflicts with a test fixture. Make sure
+        # every VM login and repository name got digits added to make
+        # it unique.
+        (repos.collect(&:name) +
+         vm_links.collect { |link| link.properties['username'] }
+         ).each do |name|
+          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}")
+        end
+      end
+    end
+  end
 end
diff --git a/services/api/test/test_helper.rb b/services/api/test/test_helper.rb
index 47c6b61..caf3e09 100644
--- a/services/api/test/test_helper.rb
+++ b/services/api/test/test_helper.rb
@@ -48,6 +48,12 @@ class ActiveSupport::TestCase
     Thread.current[:api_client_uuid] = nil
     Thread.current[:api_client] = nil
     Thread.current[:user] = nil
+    # Restore configuration settings changed during tests
+    $application_config.each do |k,v|
+      if k.match /^[^.]*$/
+        Rails.configuration.send (k + '='), v
+      end
+    end
   end
 
   def set_user_from_auth(auth_name)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list