ref: refs/heads/master
commit 08ab80a2724bc7f804ff9105b33f465625b20e37
Author: Ladislav Slezak
Date: Wed Aug 12 13:19:28 2009 +0200
system plugin - reboot/shutdown only when the input is valid
---
.../system/app/controllers/system_controller.rb | 10 +++++++-
.../test/functional/system_controller_test.rb | 21 ++++++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/plugins/system/app/controllers/system_controller.rb b/plugins/system/app/controllers/system_controller.rb
index f3dfbd3..a00959a 100644
--- a/plugins/system/app/controllers/system_controller.rb
+++ b/plugins/system/app/controllers/system_controller.rb
@@ -21,6 +21,9 @@ class SystemController < ApplicationController
@system = System.instance
+ do_reboot = false
+ do_shutdown = false
+
# do the action
root.each do |k, v|
@@ -40,15 +43,18 @@ class SystemController < ApplicationController
if v['active'] == true and @system.actions[k.to_sym][:active] == false
case k
when 'reboot'
- @system.reboot
+ do_reboot = true
when 'shutdown'
- @system.shutdown
+ do_shutdown = true
else
render ErrorResult.error(404, 2, "internal error - unknown action requested") and return
end
end
end
+ if do_reboot then @system.reboot end
+ if do_shutdown then @system.shutdown end
+
show
end
diff --git a/plugins/system/test/functional/system_controller_test.rb b/plugins/system/test/functional/system_controller_test.rb
index 52599b0..b7e7829 100644
--- a/plugins/system/test/functional/system_controller_test.rb
+++ b/plugins/system/test/functional/system_controller_test.rb
@@ -31,6 +31,27 @@ class SystemControllerTest < ActionController::TestCase
(ret_hash['actions']['shutdown']['active'] == true or ret_hash['actions']['shutdown']['active'] == false)
end
+ test "don't change status on error" do
+ ret = get :show
+ # success (200 OK)
+ assert_response :success
+
+ orig = Hash.from_xml(ret.body)
+
+ puts "orig:"
+ pp orig
+
+ put :update, :actions => {:shutdown => {:active => true}, :zzzzzz => {}}
+ assert_response :missing
+
+ ret = get :show
+ # success (200 OK)
+ assert_response :success
+
+ assert orig == Hash.from_xml(ret.body)
+ end
+
+
test "request reboot" do
ret = put :update, :actions => {:reboot => {:active => true}}
assert_response :success
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org