From 1203435f4b4499566fdaf88be2ebd2cd12f8bbfb Mon Sep 17 00:00:00 2001 From: Dominik Steiner Date: Wed, 13 May 2020 06:12:08 -0600 Subject: [PATCH 1/5] thinkwell/yolk#81 : use SimpleCrowd::ClientNoop when options[:disabled] --- lib/simple_crowd/client.rb | 4 +++ lib/simple_crowd/client_noop.rb | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 lib/simple_crowd/client_noop.rb diff --git a/lib/simple_crowd/client.rb b/lib/simple_crowd/client.rb index 317e11e..6228896 100644 --- a/lib/simple_crowd/client.rb +++ b/lib/simple_crowd/client.rb @@ -4,6 +4,10 @@ class Client attr_reader :options attr_accessor :app_token, :cache_store + def Client.new(options = {}) + options[:disabled] ? SimpleCrowd::ClientNoop.new : super + end + def initialize options = {} @options = SimpleCrowd.options options yield(@options) if block_given? diff --git a/lib/simple_crowd/client_noop.rb b/lib/simple_crowd/client_noop.rb new file mode 100644 index 0000000..110c2b5 --- /dev/null +++ b/lib/simple_crowd/client_noop.rb @@ -0,0 +1,56 @@ +# 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 + end +end From e49931b6104031aab02822f01881763977ec85ba Mon Sep 17 00:00:00 2001 From: Dominik Steiner Date: Wed, 13 May 2020 09:13:01 -0600 Subject: [PATCH 2/5] thinkwell/yolk#81 : rename config.disabled to config.noop --- lib/simple_crowd.rb | 1 + lib/simple_crowd/client.rb | 7 ++++++- lib/simple_crowd/client_noop.rb | 3 +++ lib/simple_crowd/mock_client.rb | 9 +++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/simple_crowd.rb b/lib/simple_crowd.rb index 326e5c7..0547725 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)) } diff --git a/lib/simple_crowd/client.rb b/lib/simple_crowd/client.rb index 6228896..2d21648 100644 --- a/lib/simple_crowd/client.rb +++ b/lib/simple_crowd/client.rb @@ -5,7 +5,12 @@ class Client attr_accessor :app_token, :cache_store def Client.new(options = {}) - options[:disabled] ? SimpleCrowd::ClientNoop.new : super + if options[:noop] + Rails.logger.warn "CROWD :: NOOP" + SimpleCrowd::ClientNoop.new + else + super(options) + end end def initialize options = {} diff --git a/lib/simple_crowd/client_noop.rb b/lib/simple_crowd/client_noop.rb index 110c2b5..f5b97ba 100644 --- a/lib/simple_crowd/client_noop.rb +++ b/lib/simple_crowd/client_noop.rb @@ -52,5 +52,8 @@ def find_group_by_name name 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 bceae81..3e0fa4d 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 From fe2a170aaa778afeeaade554927b650ca06ed8be Mon Sep 17 00:00:00 2001 From: Dominik Steiner Date: Mon, 12 Feb 2024 06:03:12 +0100 Subject: [PATCH 3/5] thinkwell/yolk#78 : fix File.exists? to File.exist? --- lib/simple_crowd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simple_crowd.rb b/lib/simple_crowd.rb index 0547725..b7fbb51 100644 --- a/lib/simple_crowd.rb +++ b/lib/simple_crowd.rb @@ -43,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 From 3a7833c000533f00506eac0bccbf601682b63461 Mon Sep 17 00:00:00 2001 From: Dominik Steiner Date: Thu, 15 Feb 2024 04:52:56 +0100 Subject: [PATCH 4/5] check for users.empty? in #search_users to fix TypeError --- lib/simple_crowd/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simple_crowd/client.rb b/lib/simple_crowd/client.rb index f046115..5782ce6 100644 --- a/lib/simple_crowd/client.rb +++ b/lib/simple_crowd/client.rb @@ -170,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 From 7119751dd05b412823a2162341add2383934bd80 Mon Sep 17 00:00:00 2001 From: Dominik Steiner Date: Fri, 16 Feb 2024 21:47:01 +0100 Subject: [PATCH 5/5] thinkwell/yolk#78 : bump version --- lib/simple_crowd/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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