4533: Add more tests for disabling reset feature in config file.
authorTom Clegg <tom@curoverse.com>
Tue, 18 Nov 2014 15:08:35 +0000 (10:08 -0500)
committerTom Clegg <tom@curoverse.com>
Tue, 18 Nov 2014 15:29:09 +0000 (10:29 -0500)
services/api/test/functional/database_controller_test.rb
services/api/test/integration/database_reset_test.rb [new file with mode: 0644]
services/api/test/test_helper.rb

index 7909e60b0cf3089f54f35cb0559abd4f74c73185..1953aa1034169dc62aaffdea78361e810dcf934a 100644 (file)
@@ -3,6 +3,12 @@ require 'test_helper'
 class DatabaseControllerTest < ActionController::TestCase
   include CurrentApiClient
 
+  teardown do
+    restore_configuration
+    # We made configuration changes here that affect routing.
+    Rails.application.reload_routes!
+  end
+
   test "reset fails with non-admin token" do
     authorize_with :active
     post :reset
@@ -18,6 +24,15 @@ class DatabaseControllerTest < ActionController::TestCase
     ENV['RAILS_ENV'] = env_was
   end
 
+  test "reset fails when not configured" do
+    Rails.configuration.enable_remote_database_reset = false
+    Rails.application.reload_routes!
+    authorize_with :admin
+    assert_raise ActionController::RoutingError do
+      post :reset
+    end
+  end
+
   test "reset succeeds with admin token" do
     new_uuid = nil
     act_as_system_user do
diff --git a/services/api/test/integration/database_reset_test.rb b/services/api/test/integration/database_reset_test.rb
new file mode 100644 (file)
index 0000000..84f8a19
--- /dev/null
@@ -0,0 +1,21 @@
+require 'test_helper'
+
+class DatabaseResetTest < ActionDispatch::IntegrationTest
+  teardown do
+    restore_configuration
+    # We made configuration changes here that affect routing.
+    Rails.application.reload_routes!
+  end
+
+  test "reset fails when not configured" do
+    Rails.configuration.enable_remote_database_reset = false
+    Rails.application.reload_routes!
+    post '/database/reset', {}, auth(:admin)
+    assert_response 404
+  end
+
+  test "reset fails with non-admin token" do
+    post '/database/reset', {}, auth(:active)
+    assert_response 403
+  end
+end
index d59b44926fa88a857ce10b34eaca1b4a5d3cc769..216dd2d02d9ebaf3ab7b9fcd4345ad05bd374c9f 100644 (file)
@@ -49,6 +49,10 @@ class ActiveSupport::TestCase
     Thread.current[:api_client_uuid] = nil
     Thread.current[:api_client] = nil
     Thread.current[:user] = nil
+    restore_configuration
+  end
+
+  def restore_configuration
     # Restore configuration settings changed during tests
     $application_config.each do |k,v|
       if k.match /^[^.]*$/