[ARVADOS] updated: a44040a0cb9948b42b72cbd3598e2af86e1864d2

git at public.curoverse.com git at public.curoverse.com
Wed Aug 20 14:37:37 EDT 2014


Summary of changes:
 services/api/app/models/user.rb      | 19 +++++++++----------
 services/api/test/fixtures/links.yml | 14 ++++++++++++++
 services/api/test/unit/user_test.rb  | 31 ++++++++++++++++++++-----------
 3 files changed, 43 insertions(+), 21 deletions(-)

       via  a44040a0cb9948b42b72cbd3598e2af86e1864d2 (commit)
      from  78b4e097593088a9c3614bf922a13e7eb454ea06 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit a44040a0cb9948b42b72cbd3598e2af86e1864d2
Author: radhika <radhika at curoverse.com>
Date:   Wed Aug 20 14:36:25 2014 -0400

    3153: tests with duplicate username

diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb
index 3c0332d..b15d441 100644
--- a/services/api/app/models/user.rb
+++ b/services/api/app/models/user.rb
@@ -12,8 +12,8 @@ class User < ArvadosModel
   before_update :prevent_inactive_admin
   before_create :check_auto_admin
   after_create :add_system_group_permission_link
-  after_create :send_admin_notifications
   after_create :auto_setup_new_user
+  after_create :send_admin_notifications
   after_update :send_profile_created_notification
 
 
@@ -423,28 +423,27 @@ class User < ArvadosModel
 
   # Automatically setup new user during creation
   def auto_setup_new_user
-    username = self.email.partition('@')[0] if self.email
-
     blacklisted_usernames = Rails.configuration.auto_setup_name_blacklist.split(', ')
 
+    username = self.email.partition('@')[0] if self.email
+
     if !Rails.configuration.auto_setup_new_users ||
        !(/^[_.A-Za-z0-9][-\@_.A-Za-z0-9]*\$?$/.match(self.email)) ||
        blacklisted_usernames.include?(username)
       return true
     else
-      # Derive repo name and username using the string before @ in user's email
-      # If a repo or vm login link with this prefix exists, generate unique string by appending a random number
       username = derive_unique_username username
-
       # setup user
-      setup_repo_vm_links(username, Rails.configuration.auto_setup_new_users_with_vm_uuid, Rails.configuration.default_openid_prefix)
+      setup_repo_vm_links(username, Rails.configuration.auto_setup_new_users_with_vm_uuid,
+                          Rails.configuration.default_openid_prefix)
     end
   end
 
-  # Derive repo name and username using the string before @ in user's email
-  # If a repo or vm login link with this prefix exists, generate unique string by appending a random number
+  # Derive repo name and vm username using the string before @ in user's email
+  # If a repo or vm login link with this username exists,
+  # generate unique string by appending a random number
   def derive_unique_username username
-      # no need to verify if vm login link or repo exists, if they both are not being created
+      # If repo and vm login link are not being created, no need to generate a unique username
       vm_uuid = Rails.configuration.auto_setup_new_users_with_vm_uuid
       if !vm_uuid && !Rails.configuration.auto_setup_new_users_with_repository
         return username
diff --git a/services/api/test/fixtures/links.yml b/services/api/test/fixtures/links.yml
index 4125757..4b71e48 100644
--- a/services/api/test/fixtures/links.yml
+++ b/services/api/test/fixtures/links.yml
@@ -707,3 +707,17 @@ empty_collection_name_in_active_user_home_project:
   head_uuid: d41d8cd98f00b204e9800998ecf8427e+0
   properties: {}
   updated_at: 2014-08-06 22:11:51.242010312 Z
+
+xyz_can_login_to_vm_username_can_login_to_test_vm:
+  uuid: zzzzz-o0j2j-i3n6m98766tmoi4
+  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  created_at: 2014-08-06 22:11:51.242392533 Z
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  modified_at: 2014-08-06 22:11:51.242150425 Z
+  tail_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  link_class: permission
+  name: can_login
+  head_uuid: zzzzz-2x53u-382brsig8rp3064
+  properties: {username: 'xyz_can_login_to_vm'}
+  updated_at: 2014-08-06 22:11:51.242010312 Z
diff --git a/services/api/test/unit/user_test.rb b/services/api/test/unit/user_test.rb
index c0a8cd8..bd450e4 100644
--- a/services/api/test/unit/user_test.rb
+++ b/services/api/test/unit/user_test.rb
@@ -153,10 +153,14 @@ class UserTest < ActiveSupport::TestCase
     [false, [], [], '@example.com', true, true, false],
     [false, [], [], '^^incorrect_format at example.com', true, true, false],
 
-#    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'repeat_username at example.com', true, true, true],
-#    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'repeat_username at example.com', true, false, true],
-#    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'with existing repo name', true, false, true],
-#    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'with existing vm login name', true, false, true],
+    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'foo at example.com', true, true, true],  # existing repository name 'foo'
+    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'foo at example.com', true, false, true],  # existing repository name 'foo'
+    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'foo at example.com', false, true, true],  # existing repository name 'foo'
+    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'foo at example.com', false, false, true],  # existing repository name 'foo', but we are not creating repo or login link
+    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'xyz_can_login_to_vm at example.com', true, true, true], # existing vm login name
+    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'xyz_can_login_to_vm at example.com', true, false, true], # existing vm login name
+    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'xyz_can_login_to_vm at example.com', false, true, true], # existing vm login name
+    [false, 'active-notify at example.com', 'inactive-notify at example.com', 'xyz_can_login_to_vm at example.com', false, false, true], # existing vm login name, but we are not creating repo or login link
   ].each do |active, active_recipients, inactive_recipients, email, auto_setup_vm, auto_setup_repo, valid_email_format|
     test "create new user with auto setup #{email} #{auto_setup_vm} #{auto_setup_repo}" do
       auto_setup_new_users = Rails.configuration.auto_setup_new_users
@@ -458,11 +462,14 @@ class UserTest < ActiveSupport::TestCase
 
       # check repo
       if Rails.configuration.auto_setup_new_users_with_repository
-        repo = Repository.where(name: username).first
-        assert_not_nil repo, 'repository not found'
-        verify_link_exists true, repo[:uuid], user.uuid, 'permission', 'can_manage', nil, nil
-      else
-        verify_link_exists false, nil, user.uuid, 'permission', 'can_manage', nil, nil
+        repos = Repository.where('name like ?', "%#{username}%")
+        assert_not_nil repos, 'repository not found'
+        assert_equal true, repos.any?, 'repository not found'
+        repo_uuids = []
+        repos.each do |repo|
+          repo_uuids << repo[:uuid]
+        end
+        verify_link_exists true, repo_uuids, user.uuid, 'permission', 'can_manage', nil, nil
       end
     end
 
@@ -509,9 +516,11 @@ class UserTest < ActiveSupport::TestCase
                            tail_uuid: tail_uuid,
                            link_class: link_class,
                            name: link_name)
-    assert_equal link_exists, all_links.any?, "Link not found"
+    assert_equal link_exists, all_links.any?, "Link #{'not' if link_exists} found #{property_value}"
     if link_exists && property_name && property_value
-      assert_equal property_value, all_links.first.properties[property_name], 'Property not found in link'
+      all_links.each do |link|
+        assert_equal true, all_links.first.properties[property_name].start_with?(property_value), 'Property not found in link'
+      end
     end
   end
 

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list