Mailinglist Archive: yast-commit (883 mails)

< Previous Next >
[yast-commit] <rest-service> master : make USER_ROLES_CONFIG testable
  • From: Klaus Kämpf <kkaempf@xxxxxxx>
  • Date: Mon, 6 Jul 2009 15:28:58 +0200
  • Message-id: <E1MNoGl-0006YM-05@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 500d048e45762e02547093ced9560efc909d8572
Author: Klaus Kämpf <kkaempf@xxxxxxx>
Date: Mon Jul 6 15:28:58 2009 +0200

make USER_ROLES_CONFIG testable

- move definition to config/environment.rb
- point to test/fixtures on testing
- use this in lib/yast_roles.rb
- add missing newline at end of dist/yast_user_roles
---
dist/yast_user_roles | 2 +-
webservice/config/environment.rb | 45 +++++++++++++++++------------
webservice/lib/yast_roles.rb | 5 +--
webservice/test/fixtures/yast_user_roles | 11 +++++++
4 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/dist/yast_user_roles b/dist/yast_user_roles
index b67cb78..c3f16aa 100644
--- a/dist/yast_user_roles
+++ b/dist/yast_user_roles
@@ -8,4 +8,4 @@
#
# Format: <user> <role 1>,<role 2>,...<role n>
#
-root schubi
\ No newline at end of file
+root schubi
diff --git a/webservice/config/environment.rb b/webservice/config/environment.rb
index da2a212..d375e74 100644
--- a/webservice/config/environment.rb
+++ b/webservice/config/environment.rb
@@ -10,9 +10,6 @@
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

-# load lib/resource_registration.rb
-require "resource_registration"
-
init = Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified
here.
# Application configuration should go into files in config/initializers
@@ -76,22 +73,32 @@ init = Rails::Initializer.run do |config|
config.plugin_paths << File.join(RAILS_ROOT, '..', 'plugins') if RAILS_ENV
== "development"
end

-$stderr.puts __FILE__
+# load lib/resource_registration.rb
+require "resource_registration"

-if RAILS_ENV == "test"
- class TestPlugin
- def directory
- "test/resource_fixtures/good"
+case RAILS_ENV
+ when "test"
+ class TestPlugin
+ def directory
+ "test/resource_fixtures/good"
+ end
+ end
+ ResourceRegistration.register_plugin TestPlugin.new
+
+ USER_ROLES_CONFIG = "test/fixtures/yast_user_roles"
+
+ when "development", "production"
+ $stderr.puts "Registering plugin resources"
+ init.loaded_plugins.each do |plugin|
+ ResourceRegistration.register_plugin(plugin)
end
- end
- ResourceRegistration.register_plugin TestPlugin.new
- ResourceRegistration.route ResourceRegistration.resources
-elsif RAILS_ENV == "development" or RAILS_ENV == "production"
- $stderr.puts "Registering plugin resources"
- init.loaded_plugins.each do |plugin|
- ResourceRegistration.register_plugin(plugin)
- end
- ResourceRegistration.route ResourceRegistration.resources
-else
- $stderr.puts "No ResourceRegistration triggered"
+
+ USER_ROLES_CONFIG = "/etc/yast_user_roles"
+
+ else
+ $stderr.puts "No ResourceRegistration triggered"
+
end
+
+ResourceRegistration.route ResourceRegistration.resources
+
diff --git a/webservice/lib/yast_roles.rb b/webservice/lib/yast_roles.rb
index 0cd00a2..5f0f201 100644
--- a/webservice/lib/yast_roles.rb
+++ b/webservice/lib/yast_roles.rb
@@ -1,14 +1,11 @@
module YastRoles
-
- # FIXME: move this to test/ if RAILS_ENV == 'test'
- USER_ROLES_CONFIG = "/etc/yast_user_roles"

require 'polkit'
include PolKit

private
def user_roles(user)
- return session['services'] unless session['user_roles'].nil?
+ return session['services'] if session['user_roles']

return [] unless File.exists?(USER_ROLES_CONFIG)

diff --git a/webservice/test/fixtures/yast_user_roles
b/webservice/test/fixtures/yast_user_roles
new file mode 100644
index 0000000..1ab4bec
--- /dev/null
+++ b/webservice/test/fixtures/yast_user_roles
@@ -0,0 +1,11 @@
+#
+# file : test/fixtures/yast_user_roles
+#
+# This file describes roles of a user accounts for the YaST Webservice
+# "user accounts": System account which is accessable e.g. via PAM.
+# "roles" : Describes user accounts for which policies have
+# been generated
+#
+# Format: <user> <role 1>,<role 2>,...<role n>
+#
+test network_admin,update_admin
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages