Mailinglist Archive: yast-commit (1914 mails)

< Previous Next >
[yast-commit] <rest-service> basesystem : change permission check to exception base, break exception test suite, fixed after introduce rescue handlers
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Thu, 27 Aug 2009 15:45:30 +0200
  • Message-id: <E1Mlezr-00043L-Fo@xxxxxxxxxxxxxxxx>
ref: refs/heads/basesystem
commit acde7888992a38c3e1d59d35bf46d004a14600ef
Author: Josef Reidinger <jreidinger@xxxxxxx>
Date: Thu Aug 27 15:45:30 2009 +0200

change permission check to exception base, break exception test suite,
fixed after introduce rescue handlers
---
webservice/lib/exceptions.rb | 74 +++++++++++++++++++++++++
webservice/test/functional/yast_roles_test.rb | 56 -------------------
webservice/test/unit/yast_roles_test.rb | 56 +++++++++++++++++++
3 files changed, 130 insertions(+), 56 deletions(-)

diff --git a/webservice/lib/exceptions.rb b/webservice/lib/exceptions.rb
new file mode 100644
index 0000000..4e315f7
--- /dev/null
+++ b/webservice/lib/exceptions.rb
@@ -0,0 +1,74 @@
+
+# parent of all rest-service related exception.
+# Main goal is to provide to_xml method to report it in response.
+class BackendException < StandardError
+
+ def to_xml()
+ no_arg_to_xml("GENERAL", "Universal error, should be redefined.")
+ end
+
+ protected
+ #create xml without arguments, so only error type and description
+ def no_arg_to_xml(type,descr)
+ xml = Builder::XmlMarkup.new(options)
+ xml.instruct!
+
+ xml.error do
+ xml.type type
+ xml.description descr
+ end
+
+ end
+
+end
+
+class NoPermissionException < BackendException
+ def initialize(permission,user)
+ @permission = permission
+ @user = user
+ end
+
+ def to_xml
+ xml = Builder::XmlMarkup.new(options)
+ xml.instruct!
+
+ xml.error do
+ xml.type "NO_PERM"
+ xml.description "Permission to allow #{@permission} is not available for
user #{@user}"
+ xml.permission @permission
+ xml.user @user
+ end
+ end
+end
+
+class NotLoggedException < BackendException
+ def initialize()
+ super("No one is logged.")
+ end
+
+ def to_xml
+ no_arg_to_xml("NOT_LOOGED", "No one is logged to rest service.")
+ end
+end
+
+class PolicyKitException < BackendException
+ def initialize(message,user,permission)
+ @message = message
+ @user = user
+ @permission = permission
+ super("Policy kit exception for user #{user} and permission #{permission}:
#{message}.")
+ end
+
+ def to_xml
+ xml = Builder::XmlMarkup.new(options)
+ xml.instruct!
+
+ xml.error do
+ xml.type "POLKIT"
+ xml.description message
+ xml.polkitout @message
+ xml.user @user
+ xml.permission = @permission
+ end
+ end
+end
diff --git a/webservice/test/functional/yast_roles_test.rb
b/webservice/test/functional/yast_roles_test.rb
deleted file mode 100644
index 34a52da..0000000
--- a/webservice/test/functional/yast_roles_test.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
-class CurrentLogin
- attr_reader :login
-
- def initialize login
- @login = login
- end
-end
-
-class YastRolesTest < ActiveSupport::TestCase
- include YastRoles
-
- attr_reader :current_account
-
- def setup
- ENV["RAILS_ENV"] = ""
- @current_account = CurrentLogin.new "root" # be brave
- end
-
- def test_permission_check_trivial
- save = ENV["RAILS_ENV"]
- ENV["RAILS_ENV"] = "test"
- assert permission_check(nil)
- ENV["RAILS_ENV"] = save
- end
-
- def test_permission_check_no_account
- @current_account = nil
- assert !permission_check(nil)
- end
-
- def test_action_nil
- assert !permission_check(nil)
- end
-
- def test_action_dummy
- assert !permission_check("dummy")
- end
-
- def test_polkit_override
- def PolKit.polkit_check(action,login) return :yes if action ==
"test_polkit_override" end
- assert permission_check("test_polkit_override")
- end
-
- def test_role_ok
- def PolKit.polkit_check(action,login) return :yes if login ==
"network_admin" end
- assert permission_check("dummy")
- end
-
- def test_role_not_ok
- @current_account = CurrentLogin.new "nobody"
- def PolKit.polkit_check(action,login) return :yes if login ==
"network_admin" end
- assert !permission_check("dummy")
- end
-end
diff --git a/webservice/test/unit/yast_roles_test.rb
b/webservice/test/unit/yast_roles_test.rb
new file mode 100644
index 0000000..34a52da
--- /dev/null
+++ b/webservice/test/unit/yast_roles_test.rb
@@ -0,0 +1,56 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class CurrentLogin
+ attr_reader :login
+
+ def initialize login
+ @login = login
+ end
+end
+
+class YastRolesTest < ActiveSupport::TestCase
+ include YastRoles
+
+ attr_reader :current_account
+
+ def setup
+ ENV["RAILS_ENV"] = ""
+ @current_account = CurrentLogin.new "root" # be brave
+ end
+
+ def test_permission_check_trivial
+ save = ENV["RAILS_ENV"]
+ ENV["RAILS_ENV"] = "test"
+ assert permission_check(nil)
+ ENV["RAILS_ENV"] = save
+ end
+
+ def test_permission_check_no_account
+ @current_account = nil
+ assert !permission_check(nil)
+ end
+
+ def test_action_nil
+ assert !permission_check(nil)
+ end
+
+ def test_action_dummy
+ assert !permission_check("dummy")
+ end
+
+ def test_polkit_override
+ def PolKit.polkit_check(action,login) return :yes if action ==
"test_polkit_override" end
+ assert permission_check("test_polkit_override")
+ end
+
+ def test_role_ok
+ def PolKit.polkit_check(action,login) return :yes if login ==
"network_admin" end
+ assert permission_check("dummy")
+ end
+
+ def test_role_not_ok
+ @current_account = CurrentLogin.new "nobody"
+ def PolKit.polkit_check(action,login) return :yes if login ==
"network_admin" end
+ assert !permission_check("dummy")
+ end
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >