diff --git a/lib/simple_crowd.rb b/lib/simple_crowd.rb index 326e5c7..b7fbb51 100644 --- a/lib/simple_crowd.rb +++ b/lib/simple_crowd.rb @@ -6,6 +6,7 @@ require 'simple_crowd/user' require 'simple_crowd/group' require 'simple_crowd/client' +require 'simple_crowd/client_noop' require 'simple_crowd/cache/null_store' Dir['simple_crowd/mappers/*.rb'].each {|file| require File.basename(file, File.extname(file)) } @@ -42,7 +43,7 @@ def default_crowd_options end def config_file_options @config_file_options ||= begin - (File.exists?('config/crowd.yml') && + (File.exist?('config/crowd.yml') && yml = (YAML.load_file('config/crowd.yml')[ENV["RAILS_ENV"] || "development"] || {}) and yml.symbolize_keys!) || {} end diff --git a/lib/simple_crowd/client.rb b/lib/simple_crowd/client.rb index 3150604..5782ce6 100644 --- a/lib/simple_crowd/client.rb +++ b/lib/simple_crowd/client.rb @@ -4,6 +4,15 @@ class Client attr_reader :options attr_accessor :app_token, :cache_store + def Client.new(options = {}) + if options[:noop] + Rails.logger.warn "CROWD :: NOOP" + SimpleCrowd::ClientNoop.new + else + super(options) + end + end + def initialize options = {} @options = SimpleCrowd.options options yield(@options) if block_given? @@ -161,7 +170,7 @@ def search_users criteria, limit=0, start=0 end soap_restrictions = add_soap_namespace(prepare_search_restrictions(restrictions, limit, start)) users = simple_soap_call :search_principals, soap_restrictions rescue [] - return [] if users.nil? || users[:soap_principal].nil? + return [] if users.nil? || users.empty? || users[:soap_principal].nil? users = users[:soap_principal].is_a?(Array) ? users[:soap_principal] : [users[:soap_principal]] users.map{|u| SimpleCrowd::User.from_soap u} end diff --git a/lib/simple_crowd/client_noop.rb b/lib/simple_crowd/client_noop.rb new file mode 100644 index 0000000..f5b97ba --- /dev/null +++ b/lib/simple_crowd/client_noop.rb @@ -0,0 +1,59 @@ +# Client with NOOP implementations +module SimpleCrowd + class ClientNoop + def get_cookie_info + {} + end + def authenticate_application(name = nil, password = nil) + "NOOP" + end + + def authenticate_user name, password, factors = nil + end + def create_user_token name + end + def invalidate_user_token token + end + def is_valid_user_token? token, factors = nil + end + def find_all_user_names + [] + end + def find_user_by_name name + end + alias_method :find_user_with_attributes_by_name, :find_user_by_name + + def find_user_by_token token + end + def find_username_by_token token + end + def find_user_by_email email + end + def search_users_by_email email + end + def search_users criteria, limit=0, start=0 + [] + end + def add_user user, credential + end + def remove_user name + end + def update_user_credential name, credential, encrypted = false + end + def update_user_attribute user, name, value + end + def update_user user + end + + def is_group_member? group, user + end + def find_group_by_name name + end + def find_all_group_names + [] + end + def find_group_memberships user + [] + end + end +end diff --git a/lib/simple_crowd/mock_client.rb b/lib/simple_crowd/mock_client.rb index 4c0dc9b..c40841b 100644 --- a/lib/simple_crowd/mock_client.rb +++ b/lib/simple_crowd/mock_client.rb @@ -15,6 +15,15 @@ def reset @tokens = [] @groups = [] + def MockClient.new(options = {}) + if options[:noop] + Rails.logger.warn "CROWD :: NOOP" + SimpleCrowd::ClientNoop.new + else + super() + end + end + def get_cookie_info {:secure=>false, :domain=>".twcrowdtest.com"} end diff --git a/lib/simple_crowd/version.rb b/lib/simple_crowd/version.rb index 209c7ae..ad178cd 100644 --- a/lib/simple_crowd/version.rb +++ b/lib/simple_crowd/version.rb @@ -1,3 +1,3 @@ module SimpleCrowd - VERSION = "1.2.2" + VERSION = "1.2.3" end