18183: When the user unsetup api endpoint is hit, any tokens owned by
authorWard Vandewege <ward@curii.com>
Wed, 27 Oct 2021 19:05:00 +0000 (15:05 -0400)
committerWard Vandewege <ward@curii.com>
Wed, 27 Oct 2021 19:56:09 +0000 (15:56 -0400)
       the user should be deleted.

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

services/api/app/models/user.rb
services/api/test/integration/users_test.rb

index 2e862d3ae6ba047584f7650af29fa4a44d1af107..366c03e309ca6f54c0ef5bd2ad9f3aa331c592ea 100644 (file)
@@ -300,6 +300,12 @@ SELECT target_uuid, perm_level
     Link.where(link_class: 'signature',
                      tail_uuid: self.uuid).destroy_all
 
+    # delete tokens for this user
+    ApiClientAuthorization.where(user_id: self.id).destroy_all
+    # delete ssh keys for this user
+    AuthorizedKey.where(owner_uuid: self.uuid).destroy_all
+    AuthorizedKey.where(authorized_user_uuid: self.uuid).destroy_all
+
     # delete user preferences (including profile)
     self.prefs = {}
 
index b24ddc5a52c02c495b14f9871763411fa4ccbea8..81168e15b7b43b134036717bbe9f427b9f0de0be 100644 (file)
@@ -198,6 +198,13 @@ class UsersTest < ActionDispatch::IntegrationTest
 
     verify_link_existence created['uuid'], created['email'], true, true, true, true, false
 
+    # create a token
+    token = act_as_system_user do
+      ApiClientAuthorization.create!(user: User.find_by_uuid(created['uuid']), api_client: ApiClient.all.first).api_token
+    end
+
+    assert_equal 1, ApiClientAuthorization.where(user_id: User.find_by_uuid(created['uuid']).id).size, 'expected token not found'
+
     post "/arvados/v1/users/#{created['uuid']}/unsetup", params: {}, headers: auth(:admin)
 
     assert_response :success
@@ -205,6 +212,7 @@ class UsersTest < ActionDispatch::IntegrationTest
     created2 = json_response
     assert_not_nil created2['uuid'], 'expected uuid for the newly created user'
     assert_equal created['uuid'], created2['uuid'], 'expected uuid not found'
+    assert_equal 0, ApiClientAuthorization.where(user_id: User.find_by_uuid(created['uuid']).id).size, 'token should have been deleted by user unsetup'
 
     verify_link_existence created['uuid'], created['email'], false, false, false, false, false
   end