From 2bfc24e6eb5cbd51bbb2717cd70b02a25b008ae5 Mon Sep 17 00:00:00 2001 From: radhika chippada Date: Mon, 24 Mar 2014 08:58:50 -0400 Subject: [PATCH] Raise error if both uuid and user.email are omitted in input parameters --- .../arvados/v1/users_controller.rb | 3 + .../arvados/v1/users_controller_test.rb | 123 ++++++++++++++++-- 2 files changed, 113 insertions(+), 13 deletions(-) diff --git a/services/api/app/controllers/arvados/v1/users_controller.rb b/services/api/app/controllers/arvados/v1/users_controller.rb index 8d722ba4ef..bf3dda03b7 100644 --- a/services/api/app/controllers/arvados/v1/users_controller.rb +++ b/services/api/app/controllers/arvados/v1/users_controller.rb @@ -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 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 f1ba9090e4..fa4676b0eb 100644 --- a/services/api/test/functional/arvados/v1/users_controller_test.rb +++ b/services/api/test/functional/arvados/v1/users_controller_test.rb @@ -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? '