Merge branch '3118-docker-fixes'
[arvados.git] / services / api / test / functional / application_controller_test.rb
1 require 'test_helper'
2
3 class ApplicationControllerTest < ActionController::TestCase
4   BAD_UUID = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
5
6   def now_timestamp
7     Time.now.utc.to_i
8   end
9
10   setup do
11     # These tests are meant to check behavior in ApplicationController.
12     # We instantiate a small concrete controller for convenience.
13     @controller = Arvados::V1::SpecimensController.new
14     @start_stamp = now_timestamp
15   end
16
17   def check_error_token
18     token = json_response['error_token']
19     assert_not_nil token
20     token_time = token.split('+', 2).first.to_i
21     assert_operator(token_time, :>=, @start_stamp, "error token too old")
22     assert_operator(token_time, :<=, now_timestamp, "error token too new")
23   end
24
25   def check_404(errmsg="Path not found")
26     assert_response 404
27     assert_equal([errmsg], json_response['errors'])
28     check_error_token
29   end
30
31   test "requesting nonexistent object returns 404 error" do
32     authorize_with :admin
33     get(:show, id: BAD_UUID)
34     check_404
35   end
36
37   test "requesting object without read permission returns 404 error" do
38     authorize_with :spectator
39     get(:show, id: specimens(:owned_by_active_user).uuid)
40     check_404
41   end
42
43   test "submitting bad object returns error" do
44     authorize_with :spectator
45     post(:create, specimen: {badattr: "badvalue"})
46     assert_response 422
47     check_error_token
48   end
49 end