Merge branch '14988-wb-rails5-upgrade'
[arvados.git] / services / api / test / functional / arvados / v1 / keep_disks_controller_test.rb
index 57cbd0024e6d4b5170011d3e8ee75511af275106..9da9d01631b820517caabf5bda2229b7666e3d6e 100644 (file)
@@ -1,65 +1,57 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 
 class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
 
-  test "add keep node with admin token" do
-    authorize_with :admin
-    post :ping, {
-      ping_secret: '',          # required by discovery doc, but ignored
-      service_host: '::1',
-      service_port: 55555,
-      service_ssl_flag: false,
-      filesystem_uuid: 'eb1e77a1-db84-4193-b6e6-ca2894f67d5f'
-    }
-    assert_response :success
-    assert_not_nil assigns(:object)
-    new_keep_node = JSON.parse(@response.body)
-    assert_not_nil new_keep_node['uuid']
-    assert_not_nil new_keep_node['ping_secret']
-    assert_not_equal '', new_keep_node['ping_secret']
+  def default_ping_opts
+    {ping_secret: '', service_ssl_flag: false, service_port: 1234}
   end
 
-  test "add keep node with no filesystem_uuid" do
+  test "add keep disk with admin token" do
     authorize_with :admin
-    opts = {
-      ping_secret: '',
-      service_host: '::1',
-      service_port: 55555,
-      service_ssl_flag: false
-    }
-    post :ping, opts
+    post :ping, params: default_ping_opts.
+      merge(filesystem_uuid: 'eb1e77a1-db84-4193-b6e6-ca2894f67d5f')
     assert_response :success
-    assert_not_nil JSON.parse(@response.body)['uuid']
+    assert_not_nil assigns(:object)
+    new_keep_disk = JSON.parse(@response.body)
+    assert_not_nil new_keep_disk['uuid']
+    assert_not_nil new_keep_disk['ping_secret']
+    assert_not_equal '', new_keep_disk['ping_secret']
+  end
 
-    post :ping, opts.merge(filesystem_uuid: '')
-    assert_response :success
-    assert_not_nil JSON.parse(@response.body)['uuid']
+  [
+    {},
+    {filesystem_uuid: ''},
+  ].each do |opts|
+    test "add keep disk with[out] filesystem_uuid #{opts}" do
+      authorize_with :admin
+      post :ping, params: default_ping_opts.merge(opts)
+      assert_response :success
+      assert_not_nil JSON.parse(@response.body)['uuid']
+    end
   end
 
-  test "refuse to add keep node without admin token" do
-    post :ping, {
-      ping_secret: '',
-      service_host: '::1',
-      service_port: 55555,
-      service_ssl_flag: false
-    }
+  test "refuse to add keep disk without admin token" do
+    post :ping, params: default_ping_opts
     assert_response 404
   end
 
-  test "ping from keep node" do
-    post :ping, {
-      uuid: keep_disks(:nonfull).uuid,
-      ping_secret: keep_disks(:nonfull).ping_secret,
-      filesystem_uuid: keep_disks(:nonfull).filesystem_uuid
-    }
+  test "ping keep disk" do
+    post :ping, params: default_ping_opts.
+      merge(id: keep_disks(:nonfull).uuid,
+            ping_secret: keep_disks(:nonfull).ping_secret,
+            filesystem_uuid: keep_disks(:nonfull).filesystem_uuid)
     assert_response :success
     assert_not_nil assigns(:object)
-    keep_node = JSON.parse(@response.body)
-    assert_not_nil keep_node['uuid']
-    assert_not_nil keep_node['ping_secret']
+    keep_disk = JSON.parse(@response.body)
+    assert_not_nil keep_disk['uuid']
+    assert_not_nil keep_disk['ping_secret']
   end
 
-  test "should get index with ping_secret" do
+  test "admin should get index with ping_secret" do
     authorize_with :admin
     get :index
     assert_response :success
@@ -69,13 +61,17 @@ class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
     assert_not_nil items[0]['ping_secret']
   end
 
-  # inactive user does not see any keep disks
-  test "inactive user should get empty index" do
+  # inactive user sees keep disks
+  test "inactive user should get index" do
     authorize_with :inactive
     get :index
     assert_response :success
     items = JSON.parse(@response.body)['items']
-    assert_equal 0, items.size
+    assert_not_equal 0, items.size
+
+    # Check these are still included
+    assert items[0]['service_host']
+    assert items[0]['service_port']
   end
 
   # active user sees non-secret attributes of keep disks
@@ -94,4 +90,13 @@ class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
     end
   end
 
+  test "search keep_services with 'any' operator" do
+    authorize_with :active
+    get :index, params: {
+      where: { any: ['contains', 'o2t1q5w'] }
+    }
+    assert_response :success
+    found = assigns(:objects).collect(&:uuid)
+    assert_equal true, !!found.index('zzzzz-penuu-5w2o2t1q5wy7fhn')
+  end
 end