4019: More tests for error cases
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Wed, 13 Dec 2017 15:01:38 +0000 (10:01 -0500)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Wed, 13 Dec 2017 15:01:38 +0000 (10:01 -0500)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

services/api/lib/record_filters.rb
services/api/test/functional/arvados/v1/filters_test.rb

index 50837e18672444f27c4d04bb011ac5c1022f620b..dc427c12c1f82cfc76d8b53a13ad1d7b8a88c032 100644 (file)
@@ -66,8 +66,8 @@ module RecordFilters
         col = model_class.columns.select { |c| c.name == subproperty[0] }.first
 
         if subproperty.length == 2
-          if col.type != :jsonb
-            raise ArgumentError.new("Invalid attribute '#{subproperty[0]}' for operator '#{operator}' in filter")
+          if col.nil? or col.type != :jsonb
+            raise ArgumentError.new("Invalid attribute '#{subproperty[0]}' for subproperty filter")
           end
 
           if subproperty[1][0] == "<" and subproperty[1][-1] == ">"
index 4c14d230d02cf6a351ef2f5a69377d8794d311dc..ef120b1ca86b79ff54b028fc3c1cf6c5a5e6806a 100644 (file)
@@ -230,6 +230,41 @@ class Arvados::V1::FiltersTest < ActionController::TestCase
       filters: [ ['properties.prop1', 'exists', nil] ]
     }
     assert_response 422
+    assert_match(/Invalid operand '' for 'exists' must be true or false/,
+                 json_response['errors'].join(' '))
+  end
+
+  test "jsonb checks column exists" do
+    @controller = Arvados::V1::CollectionsController.new
+    authorize_with :admin
+    get :index, {
+      filters: [ ['puppies.prop1', '=', 'value1'] ]
+    }
+    assert_response 422
+    assert_match(/Invalid attribute 'puppies' for subproperty filter/,
+                 json_response['errors'].join(' '))
+  end
+
+  test "jsonb checks column is valid" do
+    @controller = Arvados::V1::CollectionsController.new
+    authorize_with :admin
+    get :index, {
+      filters: [ ['name.prop1', '=', 'value1'] ]
+    }
+    assert_response 422
+    assert_match(/Invalid attribute 'name' for subproperty filter/,
+                 json_response['errors'].join(' '))
+  end
+
+  test "jsonb invalid operator" do
+    @controller = Arvados::V1::CollectionsController.new
+    authorize_with :admin
+    get :index, {
+      filters: [ ['properties.prop1', '###', 'value1'] ]
+    }
+    assert_response 422
+    assert_match(/Invalid operator for subproperty search '###'/,
+                 json_response['errors'].join(' '))
   end
 
   test "replication_desired = 2" do