ref: refs/heads/master
commit 5213d16c75e0febaa5141c98b400841c0548c0fc
Author: Stefan Schubert
Date: Tue Nov 3 16:42:25 2009 +0100
Code cleanup permission test; Code cleanup of plugin tests (bnc#542658)
---
webservice/lib/tasks/checks.rake | 33 +++++++++++-----
.../plugin_test/functional/plugin_index_test.rb | 38 +++----------------
.../plugin_test/functional/plugin_show_test.rb | 40 +++----------------
webservice/lib/tasks/plugin_test/test_helper.rb | 29 ++++++++++++++
4 files changed, 65 insertions(+), 75 deletions(-)
diff --git a/webservice/lib/tasks/checks.rake b/webservice/lib/tasks/checks.rake
index c2b1911..afa6420 100644
--- a/webservice/lib/tasks/checks.rake
+++ b/webservice/lib/tasks/checks.rake
@@ -105,7 +105,7 @@ task :system_check do
dest_policy = File.join('/usr/share/PolicyKit/policy', policy)
if not File.exists?(dest_policy)
escape "Policy '#{policy}' of plugin '#{plugin}' is not installed",
- "Run \"rake install\" in plugin '#{plugin}'\n or run\nsudo cp #{fname} #{dest_policy}"
+ "Run \"sudo rake install_policies\" in plugin '#{plugin}'\n or run\nsudo cp #{fname} #{dest_policy}"
end
end
@@ -122,6 +122,11 @@ task :system_check do
</match>
</match>
<match user="#{user}">
+ <match action="org.freedesktop.packagekit.package-install">
+ <return result="yes"/>
+ </match>
+ </match>
+ <match user="#{user}">
<match action="org.freedesktop.policykit.read">
<return result="yes"/>
</match>
@@ -132,14 +137,14 @@ EOF
webservice_permissions_ok = false
# get all granted policies
- granted = `polkit-auth --user #{user} --explicit`.split
+ granted = `polkit-auth --user #{user}`.split
# check that the user running the web service has permissions to yast
# scr and others. This can be achieved in 2 ways:
# manually polkit-auth, or as pattern matching in /etc/PolicyKit/PolicyKit.conf
scr_actions = `polkit-action`.split.reject { |item| not item.include?('org.opensuse.yast.scr.') }
- webservice_actions = [ 'org.freedesktop.packagekit.system-update', 'org.freedesktop.packagekit.install', 'org.freedesktop.policykit.read', *scr_actions]
+ webservice_actions = [ 'org.freedesktop.packagekit.system-update', 'org.freedesktop.packagekit.package-install', 'org.freedesktop.policykit.read', *scr_actions]
hint_message = "Use utility script policyKit-rights.rb to grant them all. See http://en.opensuse.org/YaST/Web/Development\nAlternatively, you can add the following to /etc/PolicyKit/PolicyKit.conf config tag section:\n#{policykit_conf}\n"
@@ -219,12 +224,15 @@ EOF
test_version "yast2", (os_version == "11.2")?"2.18.24":"2.17.72"
#
- # plugin test. Each plugin will be tested for a "GET index" call. This call has to return "success"
+ # plugin test. Each plugin will be tested for a "GET show" call OR a "GET index" call. This call should return success.
+ # If not an warning will be reported only.
#
test "all available plugins are working" do
# Disabled, "Dir.glob" is *waaay* too slow
- Dir.glob(File.join(File.dirname(__FILE__), '../../../plugins', "**/*_controller.rb")).each do |controller|
+
+ Dir.glob(File.join(File.dirname(__FILE__), '../../../plugins', "*","app/controllers","*_controller.rb")).each do |controller|
+ # go over all plugin controllers and call "GET show" or "GET index" (if show does not work)
modulename = File.basename(controller, ".rb").split("_").collect { |i| i.capitalize }.join
modulepath = File.dirname(controller).split("/")
# add Namespaces to the modulename.
@@ -237,13 +245,18 @@ EOF
modulename = namespace.capitalize + "::" + modulename
end
end
- ok = system %(cd #{File.dirname(__FILE__)}; export RAILS_PARENT=../../; ruby plugin_test/functional/plugin_index_test.rb --plugin #{modulename} > /dev/null)
+ puts "Checking plugin #{modulename} via HTTP GET requests..."
+ ok = system %(cd #{File.dirname(__FILE__)}; export RAILS_PARENT=../../; ruby plugin_test/functional/plugin_show_test.rb --plugin #{modulename} > /dev/null)
if !ok
- # puts "Trying \"GET show\" cause some plugins do not support \"GET index\"..."
- ok = system %(cd #{File.dirname(__FILE__)}; export RAILS_PARENT=../../; ruby plugin_test/functional/plugin_show_test.rb --plugin #{modulename} > /dev/null)
+# puts "Trying \"GET index\" cause some plugins do not support \"GET show\"..."
+ ok = system %(cd #{File.dirname(__FILE__)}; export RAILS_PARENT=../../; ruby plugin_test/functional/plugin_index_test.rb --plugin #{modulename} > /dev/null)
+ end
+ unless ok
+ warn "plugin #{modulename} does not work correctly.", "Have a look to log/test.log for additional information"
+ else
+ puts "plugin #{modulename} works correctly."
end
- escape "plugin #{modulename} does not work correctly", "try 'export RAILS_PARENT=.; ruby plugin_test/functional/plugin_index_test.rb --plugin #{modulename}' and check the result" unless ok
- end if false
+ end
end
if Error.errors == 0
diff --git a/webservice/lib/tasks/plugin_test/functional/plugin_index_test.rb b/webservice/lib/tasks/plugin_test/functional/plugin_index_test.rb
index 8cfc8ef..c172812 100644
--- a/webservice/lib/tasks/plugin_test/functional/plugin_index_test.rb
+++ b/webservice/lib/tasks/plugin_test/functional/plugin_index_test.rb
@@ -1,35 +1,9 @@
-require 'fileutils'
-require 'getoptlong'
-
-options = GetoptLong.new(
- [ "--plugin", GetoptLong::REQUIRED_ARGUMENT ]
-)
-
-$pluginname = nil
-
-begin
-options.each do |opt, arg|
- case opt
- when "--plugin": $pluginname = arg
- else
- STDERR.puts "Ignoring unrecognized option #{opt}"
- end
-end
-rescue
-end
-
+#
+# This "GET index" request will be called for each plugin.
+# The loop over all available plugins is defined in checks.rake
+#
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
-require 'test/unit'
-require "scr"
-
-class Module
- def recursive_const_get(name)
- name.to_s.split("::").inject(self) do |b, c|
- b.const_get(c)
- end
- end
-end
class PluginIndexTest < ActionController::TestCase
fixtures :accounts
@@ -42,8 +16,8 @@ class PluginIndexTest < ActionController::TestCase
end
test "access index" do
-# get :index
-# assert_response :success
+ get :index
+ assert_response :success
end
end
diff --git a/webservice/lib/tasks/plugin_test/functional/plugin_show_test.rb b/webservice/lib/tasks/plugin_test/functional/plugin_show_test.rb
index e767da4..d62cedb 100644
--- a/webservice/lib/tasks/plugin_test/functional/plugin_show_test.rb
+++ b/webservice/lib/tasks/plugin_test/functional/plugin_show_test.rb
@@ -1,37 +1,11 @@
-require 'fileutils'
-require 'getoptlong'
-
-options = GetoptLong.new(
- [ "--plugin", GetoptLong::REQUIRED_ARGUMENT ]
-)
-
-$pluginname = nil
-
-begin
-options.each do |opt, arg|
- case opt
- when "--plugin": $pluginname = arg
- else
- STDERR.puts "Ignoring unrecognized option #{opt}"
- end
-end
-rescue
-end
-
+#
+# This "GET show" request will be called for each plugin.
+# The loop over all available plugins is defined in checks.rake
+#
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
-require 'test/unit'
-require "scr"
-
-class Module
- def recursive_const_get(name)
- name.to_s.split("::").inject(self) do |b, c|
- b.const_get(c)
- end
- end
-end
-class PluginIndexTest < ActionController::TestCase
+class PluginShowTest < ActionController::TestCase
fixtures :accounts
def setup
puts "Checking #{$pluginname}"
@@ -42,8 +16,8 @@ class PluginIndexTest < ActionController::TestCase
end
test "access show" do
-# get :show
-# assert_response :success
+ get :show
+ assert_response :success
end
end
diff --git a/webservice/lib/tasks/plugin_test/test_helper.rb b/webservice/lib/tasks/plugin_test/test_helper.rb
index bdd209f..152a1d8 100644
--- a/webservice/lib/tasks/plugin_test/test_helper.rb
+++ b/webservice/lib/tasks/plugin_test/test_helper.rb
@@ -8,4 +8,33 @@ unless rails_parent
exit
end
end
+
require File.expand_path(rails_parent + "/test/test_helper")
+require 'fileutils'
+require 'getoptlong'
+require 'test/unit'
+require "scr"
+
+options = GetoptLong.new(
+ [ "--plugin", GetoptLong::REQUIRED_ARGUMENT ]
+)
+
+$pluginname = nil
+begin
+options.each do |opt, arg|
+ case opt
+ when "--plugin": $pluginname = arg
+ else
+ STDERR.puts "Ignoring unrecognized option #{opt}"
+ end
+end
+rescue
+end
+
+class Module
+ def recursive_const_get(name)
+ name.to_s.split("::").inject(self) do |b, c|
+ b.const_get(c)
+ end
+ end
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org