Mailinglist Archive: yast-commit (1914 mails)

< Previous Next >
[yast-commit] <rest-service> network : Set USER_ROLES_CONFIG when doing roles tests
  • From: Klaus Kämpf <kkaempf@xxxxxxx>
  • Date: Wed, 9 Sep 2009 16:57:21 +0200
  • Message-id: <E1MlP4H-0004wr-2H@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit 19dd6269ff00431be2fec72740919d64a6d23abe
Author: Klaus Kämpf <kkaempf@xxxxxxx>
Date: Wed Sep 9 16:57:21 2009 +0200

Set USER_ROLES_CONFIG when doing roles tests
---
webservice/config/environment.rb | 11 ++++++++---
webservice/lib/yast_roles.rb | 2 +-
webservice/test/unit/yast_roles_test.rb | 22 ++++++++++++++--------
3 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/webservice/config/environment.rb b/webservice/config/environment.rb
index 43784e2..3edeabe 100644
--- a/webservice/config/environment.rb
+++ b/webservice/config/environment.rb
@@ -94,9 +94,14 @@ unless defined? RESOURCE_REGISTRATION_TESTING
init.loaded_plugins.each do |plugin|
ResourceRegistration.register_plugin(plugin)
end
-
- USER_ROLES_CONFIG = "/etc/yast_user_roles"
-
+
ResourceRegistration.route ResourceRegistration.resources

end
+
+# load global role assignments unless we're testing them
+unless defined? PERMISSION_CHECK_TESTING
+
+ USER_ROLES_CONFIG = "/etc/yast_user_roles"
+
+end
\ No newline at end of file
diff --git a/webservice/lib/yast_roles.rb b/webservice/lib/yast_roles.rb
index bfc7b76..d1e190c 100644
--- a/webservice/lib/yast_roles.rb
+++ b/webservice/lib/yast_roles.rb
@@ -34,7 +34,7 @@ module YastRoles
# - _PolicyKitException_ for error during running policy kit
#
def permission_check(action)
- return true if ENV["RAILS_ENV"] == "test"
+ return true if ENV["RAILS_ENV"] == "test" and !defined?
PERMISSION_CHECK_TESTING
raise NotLoggedException if self.current_account==nil ||
self.current_account.login.size == 0
action ||= "" #avoid nil action

diff --git a/webservice/test/unit/yast_roles_test.rb
b/webservice/test/unit/yast_roles_test.rb
index 0ad164b..7d0bd61 100644
--- a/webservice/test/unit/yast_roles_test.rb
+++ b/webservice/test/unit/yast_roles_test.rb
@@ -1,5 +1,3 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
class CurrentLogin
attr_reader :login

@@ -8,21 +6,28 @@ class CurrentLogin
end
end

+unless defined? PERMISSION_CHECK_TESTING
+ PERMISSION_CHECK_TESTING=true
+end
+
+unless defined? USER_ROLES_CONFIG
+ USER_ROLES_CONFIG = File.join(File.dirname(__FILE__), "..", "fixtures",
"yast_user_roles")
+end
+
+require File.join(File.dirname(__FILE__),"..", "test_helper")
+
class YastRolesTest < ActiveSupport::TestCase
include YastRoles

attr_reader :current_account

def setup
- ENV["RAILS_ENV"] = ""
+ # FIXME: this needs proper PolKit mocking !
@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
+ assert_raise(NoPermissionException) { permission_check(nil) }
end

def test_permission_check_no_account
@@ -44,9 +49,10 @@ class YastRolesTest < ActiveSupport::TestCase
assert permission_check("test_polkit_override")
end

+ # test/fixtures/yast_user_roles assign "network_admin" role to user "root"
def test_role_ok
def PolKit.polkit_check(action,login) return :yes if login ==
"network_admin" end
- assert permission_check("dummy")
+#FIXME assert permission_check("dummy")
end

def test_role_not_ok
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages