From 9a124cfd453548bb447df9513f72809a1fba0433 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Fri, 28 Feb 2014 16:29:34 -0800 Subject: [PATCH] Fix jobs.cancel and add integration test. closes #2258 --- .../controllers/arvados/v1/jobs_controller.rb | 1 + .../test/integration/collections_api_test.rb | 4 ---- .../api/test/integration/jobs_api_test.rb | 23 +++++++++++++++++++ services/api/test/test_helper.rb | 6 +++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 services/api/test/integration/jobs_api_test.rb diff --git a/services/api/app/controllers/arvados/v1/jobs_controller.rb b/services/api/app/controllers/arvados/v1/jobs_controller.rb index 6c45f88e61..5c2f5db6cf 100644 --- a/services/api/app/controllers/arvados/v1/jobs_controller.rb +++ b/services/api/app/controllers/arvados/v1/jobs_controller.rb @@ -42,6 +42,7 @@ class Arvados::V1::JobsController < ApplicationController end def cancel + reload_object_before_update @object.update_attributes cancelled_at: Time.now show end diff --git a/services/api/test/integration/collections_api_test.rb b/services/api/test/integration/collections_api_test.rb index 076b2342a2..1ceedd7dd2 100644 --- a/services/api/test/integration/collections_api_test.rb +++ b/services/api/test/integration/collections_api_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class CollectionsApiTest < ActionDispatch::IntegrationTest fixtures :all - def jresponse - @jresponse ||= ActiveSupport::JSON.decode @response.body - end - test "should get index" do get "/arvados/v1/collections", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:active).api_token}"} assert_response :success diff --git a/services/api/test/integration/jobs_api_test.rb b/services/api/test/integration/jobs_api_test.rb new file mode 100644 index 0000000000..1c4e294411 --- /dev/null +++ b/services/api/test/integration/jobs_api_test.rb @@ -0,0 +1,23 @@ +require 'test_helper' + +class JobsApiTest < ActionDispatch::IntegrationTest + fixtures :all + + test "cancel job" do + post "/arvados/v1/jobs/#{jobs(:running).uuid}/cancel", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:active).api_token}"} + assert_response :success + assert_equal "arvados#job", jresponse['kind'] + assert_not_nil jresponse['cancelled_at'] + end + + test "cancel someone else's visible job" do + post "/arvados/v1/jobs/#{jobs(:barbaz).uuid}/cancel", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"} + assert_response 403 + end + + test "cancel someone else's invisible job" do + post "/arvados/v1/jobs/#{jobs(:running).uuid}/cancel", {:format => :json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"} + assert_response 404 + end + +end diff --git a/services/api/test/test_helper.rb b/services/api/test/test_helper.rb index 8c12ffb5df..8e3399523e 100644 --- a/services/api/test/test_helper.rb +++ b/services/api/test/test_helper.rb @@ -20,5 +20,11 @@ class ActiveSupport::TestCase # Add more helper methods to be used by all tests here... end +class ActionDispatch::IntegrationTest + def jresponse + @jresponse ||= ActiveSupport::JSON.decode @response.body + end +end + # Ensure permissions are computed from the test fixtures. User.invalidate_permissions_cache -- 2.39.5