15558: Support login to user account by email address
[arvados.git] / services / api / test / functional / application_controller_test.rb
index 27b046e3c2dd2c6947123cbf3bb48321eed7c5c2..175a8f71ea0544e2253754f607a2217a441d63cc 100644 (file)
@@ -24,29 +24,34 @@ class ApplicationControllerTest < ActionController::TestCase
     token_time = token.split('+', 2).first.to_i
     assert_operator(token_time, :>=, @start_stamp, "error token too old")
     assert_operator(token_time, :<=, now_timestamp, "error token too new")
+    json_response['errors'].each do |err|
+      assert_match(/req-[a-z0-9]{20}/, err, "X-Request-Id value missing on error message")
+    end
   end
 
   def check_404(errmsg="Path not found")
     assert_response 404
-    assert_equal([errmsg], json_response['errors'])
+    json_response['errors'].each do |err|
+      assert(err.include?(errmsg), "error message '#{err}' expected to include '#{errmsg}'")
+    end
     check_error_token
   end
 
   test "requesting nonexistent object returns 404 error" do
     authorize_with :admin
-    get(:show, id: BAD_UUID)
+    get(:show, params: {id: BAD_UUID})
     check_404
   end
 
   test "requesting object without read permission returns 404 error" do
     authorize_with :spectator
-    get(:show, id: specimens(:owned_by_active_user).uuid)
+    get(:show, params: {id: specimens(:owned_by_active_user).uuid})
     check_404
   end
 
   test "submitting bad object returns error" do
     authorize_with :spectator
-    post(:create, specimen: {badattr: "badvalue"})
+    post(:create, params: {specimen: {badattr: "badvalue"}})
     assert_response 422
     check_error_token
   end
@@ -77,7 +82,7 @@ class ApplicationControllerTest < ActionController::TestCase
     test "bogus boolean parameter #{bogus.inspect} returns error" do
       @controller = Arvados::V1::GroupsController.new
       authorize_with :active
-      post :create, {
+      post :create, params: {
         group: {},
         ensure_unique_name: bogus
       }
@@ -94,7 +99,7 @@ class ApplicationControllerTest < ActionController::TestCase
       test "boolean parameter #{boolparam.inspect} acceptable" do
         @controller = Arvados::V1::GroupsController.new
         authorize_with :active
-        post :create, {
+        post :create, params: {
           group: {},
           ensure_unique_name: boolparam
         }
@@ -105,7 +110,7 @@ class ApplicationControllerTest < ActionController::TestCase
       test "boolean parameter #{boolparam.inspect} accepted as #{bool.inspect}" do
         @controller = Arvados::V1::GroupsController.new
         authorize_with :active
-        post :create, {
+        post :create, params: {
           group: {
             name: groups(:aproject).name,
             owner_uuid: groups(:aproject).owner_uuid
@@ -116,4 +121,16 @@ class ApplicationControllerTest < ActionController::TestCase
       end
     end
   end
+
+  test "exceptions with backtraces get logged at exception_backtrace key" do
+    Group.stubs(:new).raises(Exception, 'Whoops')
+    Rails.logger.expects(:info).with(any_parameters) do |param|
+      param.include?('Whoops') and param.include?('"exception_backtrace":')
+    end
+    @controller = Arvados::V1::GroupsController.new
+    authorize_with :active
+    post :create, params: {
+      group: {},
+    }
+  end
 end