Raise error if both uuid and user.email are omitted in input parameters
authorradhika chippada <radhika@radhika.curoverse>
Mon, 24 Mar 2014 12:58:50 +0000 (08:58 -0400)
committerradhika chippada <radhika@radhika.curoverse>
Mon, 24 Mar 2014 12:58:50 +0000 (08:58 -0400)
services/api/app/controllers/arvados/v1/users_controller.rb
services/api/test/functional/arvados/v1/users_controller_test.rb

index 8d722ba4ef318c7f5b6db50f9b524d54825afb36..bf3dda03b72ed77de632f15856db1c63efcd6d64 100644 (file)
@@ -96,6 +96,9 @@ class Arvados::V1::UsersController < ApplicationController
         return render_404_if_no_object
       end
     else
+      if !params[:user]
+        raise ArgumentError.new "Required uuid or email"
+      end
       @object = model_class.new resource_attrs
     end
 
index f1ba9090e45f6df3ef775f493ca6a2a566942d89..fa4676b0ebaa897a4042d6de8f2f43fba734514b 100644 (file)
@@ -100,11 +100,11 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
         nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
   end
 
-  test "create user with bogus uuid, vm and repo as input" do
+  test "setup user with bogus uuid and expect error" do
     authorize_with :admin
 
     post :setup, {
-      uuid: 'not_an_existing_uuid_and_not_email_format',
+      uuid: 'bogus_uuid',
       repo_name: 'test_repo',
       vm_uuid: @vm_uuid,
       openid_prefix: 'https://www.google.com/accounts/o8/id'
@@ -115,6 +115,54 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     assert (response_errors.first.include? 'Path not found'), 'Expected 404'
   end
 
+  test "setup user with bogus uuid in user and expect error" do
+    authorize_with :admin
+
+    post :setup, {
+      user: {uuid: 'bogus_uuid'},
+      repo_name: 'test_repo',
+      vm_uuid: @vm_uuid,
+      openid_prefix: 'https://www.google.com/accounts/o8/id'
+    }
+    response_body = JSON.parse(@response.body)
+    response_errors = response_body['errors']
+    assert_not_nil response_errors, 'Expected error in response'
+    assert (response_errors.first.include? 'RuntimeError: No email found'),
+      'Expected RuntimeError'
+  end
+
+  test "setup user with no uuid and user, expect error" do
+    authorize_with :admin
+
+    post :setup, {
+      #uuid: 'not_an_existing_uuid_and_not_email_format',
+      repo_name: 'test_repo',
+      vm_uuid: @vm_uuid,
+      openid_prefix: 'https://www.google.com/accounts/o8/id'
+    }
+    response_body = JSON.parse(@response.body)
+    response_errors = response_body['errors']
+    assert_not_nil response_errors, 'Expected error in response'
+    assert (response_errors.first.include? 'Required uuid or email'),
+        'Expected ArgumentError'
+  end
+
+  test "setup user with no uuid and email, expect error" do
+    authorize_with :admin
+
+    post :setup, {
+      user: {},
+      repo_name: 'test_repo',
+      vm_uuid: @vm_uuid,
+      openid_prefix: 'https://www.google.com/accounts/o8/id'
+    }
+    response_body = JSON.parse(@response.body)
+    response_errors = response_body['errors']
+    assert_not_nil response_errors, 'Expected error in response'
+    assert (response_errors.first.include? '<RuntimeError: No email found'),
+        'Expected RuntimeError'
+  end
+
   test "invoke setup with existing uuid, vm and repo and verify links" do
     authorize_with :inactive
     get :current
@@ -124,7 +172,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     authorize_with :admin
 
     post :setup, {
-      user: {uuid: inactive_user['uuid']},
+      uuid: inactive_user['uuid'],
       repo_name: 'test_repo',
       vm_uuid: @vm_uuid,
       openid_prefix: 'https://www.google.com/accounts/o8/id'
@@ -148,7 +196,56 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
         @vm_uuid, resp_obj['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
   end
 
-  test "create user with valid email and repo as input" do
+  test "invoke setup with existing uuid in user, verify response" do
+    authorize_with :inactive
+    get :current
+    assert_response :success
+    inactive_user = JSON.parse(@response.body)
+    
+    authorize_with :admin
+
+    post :setup, {
+      user: {uuid: inactive_user['uuid']},
+      openid_prefix: 'https://www.google.com/accounts/o8/id'
+    }
+
+    assert_response :success
+
+    response_items = JSON.parse(@response.body)['items']
+    resp_obj = response_items['user']
+
+    assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
+    assert_equal inactive_user['uuid'], resp_obj['uuid']
+    assert_equal inactive_user['email'], resp_obj['email'], 
+        'expecting inactive user email'
+  end
+
+  test "invoke setup with existing uuid but different email, expect original email" do
+    authorize_with :inactive
+    get :current
+    assert_response :success
+    inactive_user = JSON.parse(@response.body)
+    
+    authorize_with :admin
+
+    post :setup, {
+      uuid: inactive_user['uuid'],
+      user: {email: 'junk_email'},
+      openid_prefix: 'https://www.google.com/accounts/o8/id'
+    }
+
+    assert_response :success
+
+    response_items = JSON.parse(@response.body)['items']
+    resp_obj = response_items['user']
+
+    assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
+    assert_equal inactive_user['uuid'], resp_obj['uuid']
+    assert_equal inactive_user['email'], resp_obj['email'], 
+        'expecting inactive user email'
+  end
+
+  test "setup user with valid email and repo as input" do
     authorize_with :admin
 
     post :setup, {
@@ -166,7 +263,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     verify_num_links @all_links_at_start, 3
   end
 
-  test "create user with valid email, repo and fake vm as input" do
+  test "setup user with fake vm and expect error" do
     authorize_with :admin
 
     post :setup, {
@@ -183,7 +280,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
           'Expected RuntimeError: No vm found for no_such_vm'
   end
 
-  test "create user with valid email, repo and real vm as input" do
+  test "setup user with valid email, repo and real vm as input" do
     authorize_with :admin
 
     post :setup, {
@@ -202,7 +299,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     verify_num_links @all_links_at_start, 4
   end
 
-  test "create user with valid email, no vm and repo as input" do
+  test "setup user with valid email, no vm and repo as input" do
     authorize_with :admin
 
     post :setup, {
@@ -219,7 +316,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     verify_num_links @all_links_at_start, 2
   end
 
-  test "create user with email, first name, repo name and vm uuid" do
+  test "setup user with email, first name, repo name and vm uuid" do
     authorize_with :admin
 
     post :setup, {
@@ -243,7 +340,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     verify_num_links @all_links_at_start, 4
   end
 
-  test "create user twice with email and check two different objects created" do
+  test "setup user twice with email and check two different objects created" do
     authorize_with :admin
 
     post :setup, {
@@ -276,7 +373,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     verify_num_links @all_links_at_start, 4
   end
 
-  test "create user with openid prefix" do
+  test "setup user with openid prefix" do
     authorize_with :admin
 
     post :setup, {
@@ -335,7 +432,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
         'Expected ArgumentError'
   end
 
-  test "create user with user, vm and repo and verify links" do
+  test "setup user with user, vm and repo and verify links" do
     authorize_with :admin
 
     post :setup, {
@@ -375,7 +472,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
         @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
   end
 
-  test "try to create user as non admin user" do
+  test "create user as non admin user and expect error" do
     authorize_with :active
 
     post :create, {
@@ -389,7 +486,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
           'Expected PermissionDeniedError'
   end
 
-  test "try to setup user as non admin user" do
+  test "setup user as non admin user and expect error" do
     authorize_with :active
 
     post :setup, {