From codesite-noreply at google.com Tue Jun 3 23:11:12 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Tue, 03 Jun 2008 20:11:12 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r725 - trunk/examples/al-admin/vendor/plugins/exception_notification Message-ID: <0016e64ed9c8bd825f044ece9405@google.com> Author: koutou Date: Tue Jun 3 20:10:22 2008 New Revision: 725 Removed: trunk/examples/al-admin/vendor/plugins/exception_notification/ Log: * remove temporarily. From codesite-noreply at google.com Tue Jun 3 23:15:13 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Tue, 03 Jun 2008 20:15:13 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r726 - in trunk/examples/al-admin/vendor/plugins/exception_notification: . lib test views views/e... Message-ID: <001636458c86166393044ecea34b@google.com> Author: koutou Date: Tue Jun 3 20:13:28 2008 New Revision: 726 Added: trunk/examples/al-admin/vendor/plugins/exception_notification/ (props changed) trunk/examples/al-admin/vendor/plugins/exception_notification/README trunk/examples/al-admin/vendor/plugins/exception_notification/init.rb trunk/examples/al-admin/vendor/plugins/exception_notification/lib/ trunk/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifiable.rb trunk/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier.rb trunk/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier_helper.rb trunk/examples/al-admin/vendor/plugins/exception_notification/test/ trunk/examples/al-admin/vendor/plugins/exception_notification/test/exception_notifier_helper_test.rb trunk/examples/al-admin/vendor/plugins/exception_notification/test/test_helper.rb trunk/examples/al-admin/vendor/plugins/exception_notification/views/ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_backtrace.rhtml trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_inspect_model.rhtml trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_session.rhtml trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_title.rhtml trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/exception_notification.rhtml Log: * re-import exception notification plugin by piston. Added: trunk/examples/al-admin/vendor/plugins/exception_notification/README ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/README Tue Jun 3 20:13:28 2008 @@ -0,0 +1,111 @@ += Exception Notifier Plugin for Rails + +The Exception Notifier plugin provides a mailer object and a default set of +templates for sending email notifications when errors occur in a Rails +application. The plugin is configurable, allowing programmers to specify: + +* the sender address of the email +* the recipient addresses +* the text used to prefix the subject line + +The email includes information about the current request, session, and +environment, and also gives a backtrace of the exception. + +== Usage + +First, include the ExceptionNotifiable mixin in whichever controller you want +to generate error emails (typically ApplicationController): + + class ApplicationController < ActionController::Base + include ExceptionNotifiable + ... + end + +Then, specify the email recipients in your environment: + + ExceptionNotifier.exception_recipients = %w(joe at schmoe.com bill at schmoe.com) + +And that's it! The defaults take care of the rest. + +== Configuration + +You can tweak other values to your liking, as well. In your environment file, +just set any or all of the following values: + + # defaults to exception.notifier at default.com + ExceptionNotifier.sender_address = + %("Application Error" ) + + # defaults to "[ERROR] " + ExceptionNotifier.email_prefix = "[APP] " + +Email notifications will only occur when the IP address is determined not to +be local. You can specify certain addresses to always be local so that you'll +get a detailed error instead of the generic error page. You do this in your +controller (or even per-controller): + + consider_local "64.72.18.143", "14.17.21.25" + +You can specify subnet masks as well, so that all matching addresses are +considered local: + + consider_local "64.72.18.143/24" + +The address "127.0.0.1" is always considered local. If you want to completely +reset the list of all addresses (for instance, if you wanted "127.0.0.1" to +NOT be considered local), you can simply do, somewhere in your controller: + + local_addresses.clear + +== Customization + +By default, the notification email includes four parts: request, session, +environment, and backtrace (in that order). You can customize how each of those +sections are rendered by placing a partial named for that part in your +app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has +access to the following variables: + +* @controller: the controller that caused the error +* @request: the current request object +* @exception: the exception that was raised +* @host: the name of the host that made the request +* @backtrace: a sanitized version of the exception's backtrace +* @rails_root: a sanitized version of RAILS_ROOT +* @data: a hash of optional data values that were passed to the notifier +* @sections: the array of sections to include in the email + +You can reorder the sections, or exclude sections completely, by altering the +ExceptionNotifier.sections variable. You can even add new sections that +describe application-specific data--just add the section's name to the list +(whereever you'd like), and define the corresponding partial. Then, if your +new section requires information that isn't available by default, make sure +it is made available to the email using the exception_data macro: + + class ApplicationController < ActionController::Base + ... + protected + exception_data :additional_data + + def additional_data + { :document => @document, + :person => @person } + end + ... + end + +In the above case, @document and @person would be made available to the email +renderer, allowing your new section(s) to access and display them. See the +existing sections defined by the plugin for examples of how to write your own. + +== Advanced Customization + +By default, the email notifier will only notify on critical errors. For +ActiveRecord::RecordNotFound and ActionController::UnknownAction, it will +simply render the contents of your public/404.html file. Other exceptions +will render public/500.html and will send the email notification. If you want +to use different rules for the notification, you will need to implement your +own rescue_action_in_public method. You can look at the default implementation +in ExceptionNotifiable for an example of how to go about that. + + +Copyright (c) 2005 Jamis Buck, released under the MIT license \ No newline at end of file Added: trunk/examples/al-admin/vendor/plugins/exception_notification/init.rb ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/init.rb Tue Jun 3 20:13:28 2008 @@ -0,0 +1 @@ +require "action_mailer" Added: trunk/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifiable.rb ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifiable.rb Tue Jun 3 20:13:28 2008 @@ -0,0 +1,99 @@ +require 'ipaddr' + +# Copyright (c) 2005 Jamis Buck +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +module ExceptionNotifiable + def self.included(target) + target.extend(ClassMethods) + end + + module ClassMethods + def consider_local(*args) + local_addresses.concat(args.flatten.map { |a| IPAddr.new(a) }) + end + + def local_addresses + addresses = read_inheritable_attribute(:local_addresses) + unless addresses + addresses = [IPAddr.new("127.0.0.1")] + write_inheritable_attribute(:local_addresses, addresses) + end + addresses + end + + def exception_data(deliverer=self) + if deliverer == self + read_inheritable_attribute(:exception_data) + else + write_inheritable_attribute(:exception_data, deliverer) + end + end + + def exceptions_to_treat_as_404 + exceptions = [ActiveRecord::RecordNotFound, + ActionController::UnknownController, + ActionController::UnknownAction] + exceptions << ActionController::RoutingError if ActionController.const_defined?(:RoutingError) + exceptions + end + end + + private + + def local_request? + remote = IPAddr.new(request.remote_ip) + !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil? + end + + def render_404 + respond_to do |type| + type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" } + type.all { render :nothing => true, :status => "404 Not Found" } + end + end + + def render_500 + respond_to do |type| + type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" } + type.all { render :nothing => true, :status => "500 Error" } + end + end + + def rescue_action_in_public(exception) + case exception + when *self.class.exceptions_to_treat_as_404 + render_404 + + else + render_500 + + deliverer = self.class.exception_data + data = case deliverer + when nil then {} + when Symbol then send(deliverer) + when Proc then deliverer.call(self) + end + + ExceptionNotifier.deliver_exception_notification(exception, self, + request, data) + end + end +end Added: trunk/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier.rb ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier.rb Tue Jun 3 20:13:28 2008 @@ -0,0 +1,66 @@ +require 'pathname' + +# Copyright (c) 2005 Jamis Buck +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +class ExceptionNotifier < ActionMailer::Base + @@sender_address = %("Exception Notifier" ) + cattr_accessor :sender_address + + @@exception_recipients = [] + cattr_accessor :exception_recipients + + @@email_prefix = "[ERROR] " + cattr_accessor :email_prefix + + @@sections = %w(request session environment backtrace) + cattr_accessor :sections + + self.template_root = "#{File.dirname(__FILE__)}/../views" + + def self.reloadable?() false end + + def exception_notification(exception, controller, request, data={}) + content_type "text/plain" + + subject "#{email_prefix}#{controller.controller_name}##{controller.action_name} (#{exception.class}) #{exception.message.inspect}" + + recipients exception_recipients + from sender_address + + body data.merge({ :controller => controller, :request => request, + :exception => exception, :host => (request.env["HTTP_X_FORWARDED_HOST"] || request.env["HTTP_HOST"]), + :backtrace => sanitize_backtrace(exception.backtrace), + :rails_root => rails_root, :data => data, + :sections => sections }) + end + + private + + def sanitize_backtrace(trace) + re = Regexp.new(/^#{Regexp.escape(rails_root)}/) + trace.map { |line| Pathname.new(line.gsub(re, "[RAILS_ROOT]")).cleanpath.to_s } + end + + def rails_root + @rails_root ||= Pathname.new(RAILS_ROOT).cleanpath.to_s + end + +end Added: trunk/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier_helper.rb ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier_helper.rb Tue Jun 3 20:13:28 2008 @@ -0,0 +1,78 @@ +require 'pp' + +# Copyright (c) 2005 Jamis Buck +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +module ExceptionNotifierHelper + VIEW_PATH = "views/exception_notifier" + APP_PATH = "#{RAILS_ROOT}/app/#{VIEW_PATH}" + PARAM_FILTER_REPLACEMENT = "[FILTERED]" + + def render_section(section) + RAILS_DEFAULT_LOGGER.info("rendering section #{section.inspect}") + summary = render_overridable(section).strip + unless summary.blank? + title = render_overridable(:title, :locals => { :title => section }).strip + "#{title}\n\n#{summary.gsub(/^/, " ")}\n\n" + end + end + + def render_overridable(partial, options={}) + if File.exist?(path = "#{APP_PATH}/_#{partial}.rhtml") + render(options.merge(:file => path, :use_full_path => false)) + elsif File.exist?(path = "#{File.dirname(__FILE__)}/../#{VIEW_PATH}/_#{partial}.rhtml") + render(options.merge(:file => path, :use_full_path => false)) + else + "" + end + end + + def inspect_model_object(model, locals={}) + render_overridable(:inspect_model, + :locals => { :inspect_model => model, + :show_instance_variables => true, + :show_attributes => true }.merge(locals)) + end + + def inspect_value(value) + len = 512 + result = object_to_yaml(value).gsub(/\n/, "\n ").strip + result = result[0,len] + "... (#{result.length-len} bytes more)" if result.length > len+20 + result + end + + def object_to_yaml(object) + object.to_yaml.sub(/^---\s*/m, "") + end + + def exclude_raw_post_parameters? + @controller && @controller.respond_to?(:filter_parameters) + end + + def filter_sensitive_post_data_parameters(parameters) + exclude_raw_post_parameters? ? @controller.filter_parameters(parameters) : parameters + end + + def filter_sensitive_post_data_from_env(env_key, env_value) + return env_value unless exclude_raw_post_parameters? + return PARAM_FILTER_REPLACEMENT if (env_key =~ /RAW_POST_DATA/i) + return @controller.filter_parameters({env_key => env_value}).values[0] + end +end Added: trunk/examples/al-admin/vendor/plugins/exception_notification/test/exception_notifier_helper_test.rb ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/test/exception_notifier_helper_test.rb Tue Jun 3 20:13:28 2008 @@ -0,0 +1,61 @@ +require 'test_helper' +require 'exception_notifier_helper' + +class ExceptionNotifierHelperTest < Test::Unit::TestCase + + class ExceptionNotifierHelperIncludeTarget + include ExceptionNotifierHelper + end + + def setup + @helper = ExceptionNotifierHelperIncludeTarget.new + end + + # No controller + + def test_should_not_exclude_raw_post_parameters_if_no_controller + assert !@helper.exclude_raw_post_parameters? + end + + # Controller, no filtering + + class ControllerWithoutFilterParameters; end + + def test_should_not_filter_env_values_for_raw_post_data_keys_if_controller_can_not_filter_parameters + stub_controller(ControllerWithoutFilterParameters.new) + assert @helper.filter_sensitive_post_data_from_env("RAW_POST_DATA", "secret").include?("secret") + end + def test_should_not_exclude_raw_post_parameters_if_controller_can_not_filter_parameters + stub_controller(ControllerWithoutFilterParameters.new) + assert !@helper.exclude_raw_post_parameters? + end + def test_should_return_params_if_controller_can_not_filter_parameters + stub_controller(ControllerWithoutFilterParameters.new) + assert_equal :params, @helper.filter_sensitive_post_data_parameters(:params) + end + + # Controller with filtering + + class ControllerWithFilterParameters + def filter_parameters(params); :filtered end + end + + def test_should_filter_env_values_for_raw_post_data_keys_if_controller_can_filter_parameters + stub_controller(ControllerWithFilterParameters.new) + assert !@helper.filter_sensitive_post_data_from_env("RAW_POST_DATA", "secret").include?("secret") + assert @helper.filter_sensitive_post_data_from_env("SOME_OTHER_KEY", "secret").include?("secret") + end + def test_should_exclude_raw_post_parameters_if_controller_can_filter_parameters + stub_controller(ControllerWithFilterParameters.new) + assert @helper.exclude_raw_post_parameters? + end + def test_should_delegate_param_filtering_to_controller_if_controller_can_filter_parameters + stub_controller(ControllerWithFilterParameters.new) + assert_equal :filtered, @helper.filter_sensitive_post_data_parameters(:params) + end + + private + def stub_controller(controller) + @helper.instance_variable_set(:@controller, controller) + end +end \ No newline at end of file Added: trunk/examples/al-admin/vendor/plugins/exception_notification/test/test_helper.rb ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/test/test_helper.rb Tue Jun 3 20:13:28 2008 @@ -0,0 +1,7 @@ +require 'test/unit' +require 'rubygems' +require 'active_support' + +$:.unshift File.join(File.dirname(__FILE__), '../lib') + +RAILS_ROOT = '.' unless defined?(RAILS_ROOT) Added: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_backtrace.rhtml ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_backtrace.rhtml Tue Jun 3 20:13:28 2008 @@ -0,0 +1 @@ +<%= @backtrace.join "\n" %> Added: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml Tue Jun 3 20:13:28 2008 @@ -0,0 +1,7 @@ +<% max = @request.env.keys.max { |a,b| a.length <=> b.length } -%> +<% @request.env.keys.sort.each do |key| -%> +* <%= "%-*s: %s" % [max.length, key, filter_sensitive_post_data_from_env(key, @request.env[key].to_s.strip)] %> +<% end -%> + +* Process: <%= $$ %> +* Server : <%= `hostname -s`.chomp %> Added: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_inspect_model.rhtml ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_inspect_model.rhtml Tue Jun 3 20:13:28 2008 @@ -0,0 +1,16 @@ +<% if show_attributes -%> +[attributes] +<% attrs = inspect_model.attributes -%> +<% max = attrs.keys.max { |a,b| a.length <=> b.length } -%> +<% attrs.keys.sort.each do |attr| -%> +* <%= "%*-s: %s" % [max.length, attr, object_to_yaml(attrs[attr]).gsub(/\n/, "\n ").strip] %> +<% end -%> +<% end -%> + +<% if show_instance_variables -%> +[instance variables] +<% inspect_model.instance_variables.sort.each do |variable| -%> +<%- next if variable == "@attributes" -%> +* <%= variable %>: <%= inspect_value(inspect_model.instance_variable_get(variable)) %> +<% end -%> +<% end -%> Added: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml Tue Jun 3 20:13:28 2008 @@ -0,0 +1,4 @@ +* URL : <%= @request.protocol %><%= @host %><%= @request.request_uri %> +* IP address: <%= @request.env["HTTP_X_FORWARDED_FOR"] || @request.env["REMOTE_ADDR"] %> +* Parameters: <%= filter_sensitive_post_data_parameters(@request.parameters).inspect %> +* Rails root: <%= @rails_root %> Added: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_session.rhtml ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_session.rhtml Tue Jun 3 20:13:28 2008 @@ -0,0 +1,2 @@ +* session id: <%= @request.session.instance_variable_get(:@session_id).inspect %> +* data: <%= PP.pp(@request.session.instance_variable_get(:@data),"").gsub(/\n/, "\n ").strip %> Added: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_title.rhtml ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_title.rhtml Tue Jun 3 20:13:28 2008 @@ -0,0 +1,3 @@ +------------------------------- +<%= title.to_s.humanize %>: +------------------------------- Added: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/exception_notification.rhtml ============================================================================== --- (empty file) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/exception_notification.rhtml Tue Jun 3 20:13:28 2008 @@ -0,0 +1,6 @@ +A <%= @exception.class %> occurred in <%= @controller.controller_name %>#<%= @controller.action_name %>: + + <%= @exception.message %> + <%= @backtrace.first %> + +<%= @sections.map { |section| render_section(section) }.join %> From codesite-noreply at google.com Tue Jun 3 23:19:13 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Tue, 03 Jun 2008 20:19:13 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r727 - trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier Message-ID: <001636456fe669ecb6044eceb17f@google.com> Author: koutou Date: Tue Jun 3 20:16:54 2008 New Revision: 727 Modified: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml Log: * fix wrong format. Modified: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml ============================================================================== --- trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml (original) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml Tue Jun 3 20:16:54 2008 @@ -1,6 +1,6 @@ <% max = @request.env.keys.max { |a,b| a.length <=> b.length } -%> <% @request.env.keys.sort.each do |key| -%> -* <%= "%-*s: %s" % [max.length, key, filter_sensitive_post_data_from_env(key, @request.env[key].to_s.strip)] %> +* <%= "%*-s: %s" % [max.length, key, filter_sensitive_post_data_from_env(key, @request.env[key].to_s.strip)] %> <% end -%> * Process: <%= $$ %> From codesite-noreply at google.com Wed Jun 4 03:38:50 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 04 Jun 2008 00:38:50 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r728 - trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier Message-ID: <000e0cd10604e183c7044ed251a0@google.com> Author: koutou Date: Wed Jun 4 00:38:23 2008 New Revision: 728 Modified: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml Log: * revert the previous change. Modified: trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml ============================================================================== --- trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml (original) +++ trunk/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml Wed Jun 4 00:38:23 2008 @@ -1,6 +1,6 @@ <% max = @request.env.keys.max { |a,b| a.length <=> b.length } -%> <% @request.env.keys.sort.each do |key| -%> -* <%= "%*-s: %s" % [max.length, key, filter_sensitive_post_data_from_env(key, @request.env[key].to_s.strip)] %> +* <%= "%-*s: %s" % [max.length, key, filter_sensitive_post_data_from_env(key, @request.env[key].to_s.strip)] %> <% end -%> * Process: <%= $$ %> From codesite-noreply at google.com Wed Jun 4 10:16:10 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 04 Jun 2008 07:16:10 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r729 - in trunk: lib/active_ldap test Message-ID: <000e0cd2dec6d202ca044ed7de18@google.com> Author: koutou Date: Wed Jun 4 07:15:53 2008 New Revision: 729 Modified: trunk/lib/active_ldap/base.rb trunk/test/test_base.rb Log: * work attribute_present? for unknown attribute. Modified: trunk/lib/active_ldap/base.rb ============================================================================== --- trunk/lib/active_ldap/base.rb (original) +++ trunk/lib/active_ldap/base.rb Wed Jun 4 07:15:53 2008 @@ -1021,6 +1021,7 @@ # Return the value of the attribute called by method_missing? def get_attribute(name, force_array=false) name, value = get_attribute_before_type_cast(name, force_array) + return value if name.nil? attribute = schema.attribute(name) type_cast(attribute, value) end Modified: trunk/test/test_base.rb ============================================================================== --- trunk/test/test_base.rb (original) +++ trunk/test/test_base.rb Wed Jun 4 07:15:53 2008 @@ -6,6 +6,7 @@ include AlTestUtils priority :must + priority :normal def test_save_with_changes make_temporary_user do |user, password| user.cn += "!!!" @@ -19,7 +20,6 @@ end end - priority :normal def test_normalize_dn_attribute make_ou("Ous") ou_class = Class.new(ActiveLdap::Base) @@ -592,6 +592,12 @@ assert(user.attribute_present?(:sn)) user.sn = [nil] assert(!user.attribute_present?(:sn)) + end + end + + def test_attribute_present_with_unknown_attribute + make_temporary_user do |user, password| + assert(!user.attribute_present?(:unknown_attribute)) end end From codesite-noreply at google.com Wed Jun 4 10:20:11 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 04 Jun 2008 07:20:11 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r730 - trunk Message-ID: <000e0cd172ee32350d044ed7ed92@google.com> Author: koutou Date: Wed Jun 4 07:20:04 2008 New Revision: 730 Modified: trunk/README Log: * add Matt Mencel entry to thanks list. Thanks!!! Modified: trunk/README ============================================================================== --- trunk/README (original) +++ trunk/README Wed Jun 4 07:20:04 2008 @@ -108,3 +108,4 @@ * David Morton: An API improvement idea. * Lennon Day-Reynolds: Bug reports. * Tilo: A bug report. +* Matt Mencel: A bug report. From codesite-noreply at google.com Fri Jun 6 08:52:18 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 06 Jun 2008 05:52:18 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r731 - trunk/lib/active_ldap Message-ID: <00163646d5f097b41e044efeeea1@google.com> Author: koutou Date: Fri Jun 6 05:51:59 2008 New Revision: 731 Modified: trunk/lib/active_ldap/base.rb trunk/lib/active_ldap/operations.rb Log: * add ActiveLdap::Base#.to_ldif_record. Modified: trunk/lib/active_ldap/base.rb ============================================================================== --- trunk/lib/active_ldap/base.rb (original) +++ trunk/lib/active_ldap/base.rb Fri Jun 6 05:51:59 2008 @@ -763,8 +763,12 @@ end end - def to_ldif + def to_ldif_record super(dn, @data) + end + + def to_ldif + Ldif.new([to_ldif_record]).to_s end def to_xml(options={}) Modified: trunk/lib/active_ldap/operations.rb ============================================================================== --- trunk/lib/active_ldap/operations.rb (original) +++ trunk/lib/active_ldap/operations.rb Fri Jun 6 05:51:59 2008 @@ -333,9 +333,12 @@ ldif.to_s end + def to_ldif_record(dn, attributes) + Ldif::Record.new(dn, attributes) + end + def to_ldif(dn, attributes) - record = Ldif::Record.new(dn, attributes) - Ldif.new([record]).to_s + Ldif.new([to_ldif_record(dn, attributes)]).to_s end def load(ldif, options={}) From codesite-noreply at google.com Fri Jun 6 08:56:19 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 06 Jun 2008 05:56:19 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r732 - trunk/test Message-ID: <001636458c86f4b21e044efefcc3@google.com> Author: koutou Date: Fri Jun 6 05:53:17 2008 New Revision: 732 Modified: trunk/test/test_validation.rb Log: * normalize compared values. Modified: trunk/test/test_validation.rb ============================================================================== --- trunk/test/test_validation.rb (original) +++ trunk/test/test_validation.rb Fri Jun 6 05:53:17 2008 @@ -33,8 +33,9 @@ assert(user.save) user = user.class.find(user.dn) - assert_equal([{"lang-ja" => "???"}, {"lang-en" => "User"}], - user.display_name) + assert_equal([{"lang-ja" => "???"}, + {"lang-en" => "User"}].sort_by {|hash| hash.keys.first}, + user.display_name.sort_by {|hash| hash.keys.first}) end end From codesite-noreply at google.com Fri Jun 6 09:42:27 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 06 Jun 2008 06:42:27 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r733 - trunk/lib/active_ldap Message-ID: <000e0cd243baf15dd9044effa156@google.com> Author: koutou Date: Fri Jun 6 06:41:29 2008 New Revision: 733 Modified: trunk/lib/active_ldap/base.rb Log: * improve inspected result. Modified: trunk/lib/active_ldap/base.rb ============================================================================== --- trunk/lib/active_ldap/base.rb (original) +++ trunk/lib/active_ldap/base.rb Fri Jun 6 06:41:29 2008 @@ -435,7 +435,52 @@ dn_attribute end + def inspect + if self == Base + super + else + class_names = [] + must = [] + may = [] + class_names = classes.collect do |object_class| + must.concat(object_class.must) + may.concat(object_class.may) + object_class.name + end + detail = ["objectClass:<#{class_names.join(', ')}>", + "must:<#{inspect_attributes(must)}>", + "may:<#{inspect_attributes(may)}>"].join(", ") + "#{super}(#{detail})" + end + end + private + def inspect_attributes(attributes) + inspected_attribute_names = {} + attributes.collect do |attribute| + if inspected_attribute_names.has_key?(attribute.name) + nil + else + inspected_attribute_names[attribute.name] = true + inspect_attribute(attribute) + end + end.compact.join(', ') + end + + def inspect_attribute(attribute) + syntax = attribute.syntax + result = "#{attribute.name}" + if syntax and !syntax.description.blank? + result << ": #{syntax.description}" + end + properties = [] + properties << "read-only" if attribute.read_only? + properties << "binary" if attribute.binary? + properties << "binary-required" if attribute.binary_required? + result << "(#{properties.join(', ')})" unless properties.empty? + result + end + def validate_ldap_mapping_options(options) options.assert_valid_keys(VALID_LDAP_MAPPING_OPTIONS) end @@ -898,18 +943,36 @@ end def inspect - abbreviate_instance_variables do - super - end + object_classes = entry_attribute.object_classes + inspected_object_classes = object_classes.collect do |object_class| + object_class.name + end.join(', ') + must_attributes = must.collect(&:name).sort.join(', ') + may_attributes = may.collect(&:name).sort.join(', ') + inspected_attributes = attribute_names.sort.collect do |name| + inspect_attribute(name) + end.join(', ') + result = "\#<#{self.class} objectClass:<#{inspected_object_classes}>, " + result << "must:<#{must_attributes}>, may:<#{may_attributes}>, " + result << "#{inspected_attributes}>" + result end - def pretty_print(q) - abbreviate_instance_variables do - q.pp_object(self) + private + def inspect_attribute(name) + values = get_attribute(name, true) + values.collect do |value| + if value.is_a?(String) and value.length > 50 + "#{value[0, 50]}...".inspect + elsif value.is_a?(Date) || value.is_a?(Time) + "#{value.to_s(:db)}" + else + value.inspect + end end + "#{name}: #{values.inspect}" end - private def attribute_name_resolvable_without_connection? @entry_attribute and @local_entry_attribute end @@ -920,26 +983,6 @@ def local_entry_attribute @local_entry_attribute ||= connection.entry_attribute([]) - end - - def abbreviate_instance_variables - @abbreviating ||= nil - connection, @connection = @connection, nil - schema, @schema = @schema, nil - entry_attribute, @entry_attribute = @entry_attribute, nil - local_entry_attribute, @local_entry_attribute = @local_entry_attribute, nil - real_names, @real_names = @real_names, nil - unless @abbreviating - @abbreviating = true - end - yield - ensure - @connection = connection - @schema = schema - @entry_attribute = entry_attribute - @local_entry_attribute = local_entry_attribute - @real_names = real_names - @abbreviating = false end def extract_object_class(attributes) From codesite-noreply at google.com Wed Jun 11 09:36:05 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 11 Jun 2008 06:36:05 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r734 - in trunk/lib: . active_ldap Message-ID: <001636e0a511652980044f642047@google.com> Author: koutou Date: Wed Jun 11 06:35:52 2008 New Revision: 734 Modified: trunk/lib/active_ldap.rb trunk/lib/active_ldap/associations.rb trunk/lib/active_ldap/base.rb trunk/lib/active_ldap/entry_attribute.rb Log: * don't use Inflector and Dependencies to support ActiveSupport 2.1.0. Modified: trunk/lib/active_ldap.rb ============================================================================== --- trunk/lib/active_ldap.rb (original) +++ trunk/lib/active_ldap.rb Wed Jun 11 06:35:52 2008 @@ -917,8 +917,14 @@ require_gem_if_need.call("active_support", "activesupport") -if Dependencies.respond_to?(:load_paths) - Dependencies.load_paths << File.expand_path(File.dirname(__FILE__)) +if ActiveSupport.const_defined?(:Dependencies) + dependencies = ActiveSupport::Dependencies +else + dependencies = Dependencies +end + +if dependencies.respond_to?(:load_paths) + dependencies.load_paths << File.expand_path(File.dirname(__FILE__)) end module ActiveLdap Modified: trunk/lib/active_ldap/associations.rb ============================================================================== --- trunk/lib/active_ldap/associations.rb (original) +++ trunk/lib/active_ldap/associations.rb Wed Jun 11 06:35:52 2008 @@ -44,7 +44,7 @@ # def belongs_to(association_id, options={}) validate_belongs_to_options(options) - klass = options[:class] || Inflector.classify(association_id) + klass = options[:class] || association_id.to_s.classify foreign_key = options[:foreign_key] primary_key = options[:primary_key] many = options[:many] @@ -96,8 +96,8 @@ # :wrap => "memberUid" # Group#memberUid def has_many(association_id, options = {}) validate_has_many_options(options) - klass = options[:class] || Inflector.classify(association_id) - foreign_key = options[:foreign_key] || association_id.to_s + "_id" + klass = options[:class] || association_id.to_s.classify + foreign_key = options[:foreign_key] || "#{association_id}_id" primary_key = options[:primary_key] set_associated_class(association_id, klass) Modified: trunk/lib/active_ldap/base.rb ============================================================================== --- trunk/lib/active_ldap/base.rb (original) +++ trunk/lib/active_ldap/base.rb Wed Jun 11 06:35:52 2008 @@ -526,7 +526,7 @@ end dn_attribute || "cn" else - Inflector.underscore(Inflector.demodulize(name)) + name.demodulize.underscore end end @@ -534,7 +534,7 @@ if name.empty? nil else - "ou=#{Inflector.pluralize(Inflector.demodulize(name))}" + "ou=#{name.demodulize.pluralize}" end end end @@ -745,7 +745,7 @@ # Add available attributes to the methods def methods(inherited_too=true) target_names = entry_attribute.all_names - target_names -= ['objectClass', Inflector.underscore('objectClass')] + target_names -= ['objectClass', 'objectClass'.underscore] super + target_names.uniq.collect do |x| [x, "#{x}=", "#{x}?", "#{x}_before_type_cast"] end.flatten @@ -817,7 +817,7 @@ end def to_xml(options={}) - root = options[:root] || Inflector.underscore(self.class.name) + root = options[:root] || self.class.name.underscore result = "<#{root}>\n" result << " #{dn}\n" normalize_data(@data).sort_by {|key, values| key}.each do |key, values| Modified: trunk/lib/active_ldap/entry_attribute.rb ============================================================================== --- trunk/lib/active_ldap/entry_attribute.rb (original) +++ trunk/lib/active_ldap/entry_attribute.rb Wed Jun 11 06:35:52 2008 @@ -45,7 +45,7 @@ return nil if @names.empty? and @aliases.empty? name = name.to_s real_name = @names[name] - real_name ||= @aliases[Inflector.underscore(name)] + real_name ||= @aliases[name.underscore] if real_name real_name elsif allow_normalized_name @@ -70,7 +70,7 @@ @schemata[real_name] = attribute ([real_name] + attribute.aliases).each do |name| @names[name] = real_name - @aliases[Inflector.underscore(name)] = real_name + @aliases[name.underscore] = real_name @normalized_names[normalize_attribute_name(name)] = real_name end end From codesite-noreply at google.com Wed Jun 11 10:51:23 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 11 Jun 2008 07:51:23 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r735 - in trunk: . test Message-ID: <000e0cd13932a71d79044f652d03@google.com> Author: koutou Date: Wed Jun 11 07:51:01 2008 New Revision: 735 Modified: trunk/ (props changed) trunk/test/al-test-utils.rb trunk/test/run-test.rb Log: * use extended test-unit not test-unit-ext. Modified: trunk/test/al-test-utils.rb ============================================================================== --- trunk/test/al-test-utils.rb (original) +++ trunk/test/al-test-utils.rb Wed Jun 11 07:51:01 2008 @@ -1,5 +1,4 @@ require 'test/unit' -require 'test-unit-ext' require 'erb' require 'yaml' Modified: trunk/test/run-test.rb ============================================================================== --- trunk/test/run-test.rb (original) +++ trunk/test/run-test.rb Wed Jun 11 07:51:01 2008 @@ -3,16 +3,15 @@ $KCODE = 'u' require 'yaml' -require "test/unit" base_dir = File.expand_path(File.dirname(__FILE__)) top_dir = File.expand_path(File.join(base_dir, "..")) $LOAD_PATH.unshift(File.join(top_dir, "lib")) $LOAD_PATH.unshift(File.join(top_dir, "test")) -$LOAD_PATH.unshift(File.join(top_dir, "test-unit-ext", "lib")) -require 'test-unit-ext' -Test::Unit::TestSuite.priority_mode = true +$LOAD_PATH.unshift(File.join(top_dir, "test-unit", "lib")) +require "test/unit" +ARGV.unshift("--priority-mode") test_file = "test/test_*.rb" Dir.glob(test_file) do |file| From codesite-noreply at google.com Wed Jun 11 10:57:24 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 11 Jun 2008 07:57:24 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r736 - trunk Message-ID: <000e0cd259b82d63af044f6543b9@google.com> Author: koutou Date: Wed Jun 11 07:57:02 2008 New Revision: 736 Modified: trunk/CHANGES Log: * add 1.0.1 entry. Modified: trunk/CHANGES ============================================================================== --- trunk/CHANGES (original) +++ trunk/CHANGES Wed Jun 11 07:57:02 2008 @@ -1,3 +1,12 @@ +1.0.1: + * Fixed GetText integration. + * Fixed ActiveLdap::Base.find with ActiveLdap::DN. (Reported by Jeremy Pruitt) + * Supported ActiveLdap::Base#attribute_present? with nonexistence attribute. + (Reported by Matt Mencel) + * Added ActiveLdap::Base#.to_ldif_record. + * Improved inspect. + * Supported ActiveSupport 2.1.0. + 1.0.0: * Fixed GSSAPI auth failure. [#18764] (Reported by Lennon Day-Reynolds) * Supported Symbol as :dn_attribute_value. [#18921] (Requested by Nobody) From codesite-noreply at google.com Wed Jun 11 11:01:24 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 11 Jun 2008 08:01:24 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r737 - trunk/lib/active_ldap Message-ID: <000e0cd172ee827283044f65518b@google.com> Author: koutou Date: Wed Jun 11 08:01:04 2008 New Revision: 737 Modified: trunk/lib/active_ldap/ldif.rb trunk/lib/active_ldap/user_password.rb Log: * remove deprecated "require 'base64'". Modified: trunk/lib/active_ldap/ldif.rb ============================================================================== --- trunk/lib/active_ldap/ldif.rb (original) +++ trunk/lib/active_ldap/ldif.rb Wed Jun 11 08:01:04 2008 @@ -1,5 +1,4 @@ require "strscan" -require "base64" require "uri" require "open-uri" @@ -117,7 +116,7 @@ def read_base64_value value = @scanner.scan(/[a-zA-Z0-9\+\/=]+/u) return nil if value.nil? - Base64.decode64(value).chomp + value.unpack("m")[0].chomp end def read_external_file Modified: trunk/lib/active_ldap/user_password.rb ============================================================================== --- trunk/lib/active_ldap/user_password.rb (original) +++ trunk/lib/active_ldap/user_password.rb Wed Jun 11 08:01:04 2008 @@ -1,5 +1,4 @@ require 'English' -require 'base64' require 'md5' require 'sha1' From codesite-noreply at google.com Wed Jun 11 11:14:28 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 11 Jun 2008 08:14:28 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r738 - trunk/lib/active_ldap/adapter Message-ID: <0016364179013d8d65044f65807e@google.com> Author: koutou Date: Wed Jun 11 08:14:09 2008 New Revision: 738 Modified: trunk/lib/active_ldap/adapter/jndi.rb Log: * fix a missing argument bug. Modified: trunk/lib/active_ldap/adapter/jndi.rb ============================================================================== --- trunk/lib/active_ldap/adapter/jndi.rb (original) +++ trunk/lib/active_ldap/adapter/jndi.rb Wed Jun 11 08:14:09 2008 @@ -82,7 +82,7 @@ :name => "modify: RDN", :dn => dn, :new_rdn => new_rdn, :delete_old_rdn => delete_old_rdn, } - execute(:modify_rdn, dn, new_rdn, delete_old_rdn) + execute(:modify_rdn, info, dn, new_rdn, delete_old_rdn) end end From codesite-noreply at google.com Thu Jun 12 07:39:51 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Thu, 12 Jun 2008 04:39:51 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r739 - trunk/test Message-ID: <000e0cd20f6e85a705044f769ee8@google.com> Author: koutou Date: Thu Jun 12 04:38:59 2008 New Revision: 739 Modified: trunk/test/command.rb Log: * use Object.respond_to?(:java) to detect JRuby. Modified: trunk/test/command.rb ============================================================================== --- trunk/test/command.rb (original) +++ trunk/test/command.rb Thu Jun 12 04:38:59 2008 @@ -32,7 +32,7 @@ if args.any? {|x| x.nil?} raise ArgumentError, "args has nil: #{args.inspect}" end - return java_run(cmd, *args, &block) unless Kernel.respond_to?(:fork) + return java_run(cmd, *args, &block) unless Object.respond_to?(:java) in_r, in_w = IO.pipe out_r, out_w = IO.pipe pid = exit_status = nil From codesite-noreply at google.com Thu Jun 12 07:43:13 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Thu, 12 Jun 2008 04:43:13 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r740 - trunk/test Message-ID: <0016e64ca7d6913e23044f76aa79@google.com> Author: koutou Date: Thu Jun 12 04:39:48 2008 New Revision: 740 Modified: trunk/test/command.rb Log: * fix a typo. Modified: trunk/test/command.rb ============================================================================== --- trunk/test/command.rb (original) +++ trunk/test/command.rb Thu Jun 12 04:39:48 2008 @@ -32,7 +32,7 @@ if args.any? {|x| x.nil?} raise ArgumentError, "args has nil: #{args.inspect}" end - return java_run(cmd, *args, &block) unless Object.respond_to?(:java) + return java_run(cmd, *args, &block) if Object.respond_to?(:java) in_r, in_w = IO.pipe out_r, out_w = IO.pipe pid = exit_status = nil From codesite-noreply at google.com Thu Jun 12 07:47:14 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Thu, 12 Jun 2008 04:47:14 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r741 - trunk/test Message-ID: <0016e64ca7d6ebd3ef044f76b85b@google.com> Author: koutou Date: Thu Jun 12 04:42:55 2008 New Revision: 741 Modified: trunk/test/test_validation.rb Log: * fix a typo. Modified: trunk/test/test_validation.rb ============================================================================== --- trunk/test/test_validation.rb (original) +++ trunk/test/test_validation.rb Thu Jun 12 04:42:55 2008 @@ -19,7 +19,7 @@ 1) % {:fn => la_("objectClass")} message = format % loc_("person") else - message = "ObjectClass has excluded value: person" + message = "objectClass has excluded value: person" end assert_equal([message], user.errors.full_messages) end From codesite-noreply at google.com Thu Jun 12 08:05:18 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Thu, 12 Jun 2008 05:05:18 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r742 - trunk/test Message-ID: <000e0cd174889006e9044f76f9e3@google.com> Author: koutou Date: Thu Jun 12 05:04:41 2008 New Revision: 742 Modified: trunk/test/test_usermod-lang-add.rb Log: * sort result. Modified: trunk/test/test_usermod-lang-add.rb ============================================================================== --- trunk/test/test_usermod-lang-add.rb (original) +++ trunk/test/test_usermod-lang-add.rb Thu Jun 12 05:04:41 2008 @@ -40,7 +40,8 @@ user = @user_class.find(name) assert_equal(name, user.uid) - assert_equal([cn, {'lang-en-us' => cn}], user.cn) + assert_equal([cn, {'lang-en-us' => cn}].sort_by(&:inspect), + user.cn.sort_by(&:inspect)) assert_equal(uid.to_i, user.uid_number) assert_equal(uid.to_i, user.gid_number) assert_equal(uid.to_s, user.uid_number_before_type_cast) From codesite-noreply at google.com Thu Jun 12 08:36:22 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Thu, 12 Jun 2008 05:36:22 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r743 - trunk/test Message-ID: <000e0cd32b3eaeffb6044f7768ec@google.com> Author: koutou Date: Thu Jun 12 05:35:41 2008 New Revision: 743 Modified: trunk/test/test_dn.rb trunk/test/test_ldif.rb Log: * add magic comment. Modified: trunk/test/test_dn.rb ============================================================================== --- trunk/test/test_dn.rb (original) +++ trunk/test/test_dn.rb Thu Jun 12 05:35:41 2008 @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + require 'al-test-utils' class TestDN < Test::Unit::TestCase Modified: trunk/test/test_ldif.rb ============================================================================== --- trunk/test/test_ldif.rb (original) +++ trunk/test/test_ldif.rb Thu Jun 12 05:35:41 2008 @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + require 'al-test-utils' class TestLDIF < Test::Unit::TestCase From codesite-noreply at google.com Fri Jun 13 19:23:53 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 16:23:53 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r744 - trunk/test Message-ID: <000e0cd2bd0036588e044f9492c7@google.com> Author: koutou Date: Fri Jun 13 16:23:28 2008 New Revision: 744 Modified: trunk/test/test_associations.rb Log: * add delete test. Modified: trunk/test/test_associations.rb ============================================================================== --- trunk/test/test_associations.rb (original) +++ trunk/test/test_associations.rb Fri Jun 13 16:23:28 2008 @@ -21,6 +21,20 @@ reloaded_group = @group_class.find(group.cn) assert_equal([user1, user2].collect(&:cn).sort, reloaded_group.members.collect(&:cn).sort) + + user1.groups = [] + assert(user1.save) + assert_equal([], user1.groups.collect(&:cn)) + reloaded_group = @group_class.find(group.cn) + assert_equal([user2].collect(&:cn).sort, + reloaded_group.members.collect(&:cn).sort) + + user2.groups.delete(reloaded_group) + assert(user2.save) + assert_equal([], user2.groups.collect(&:cn)) + reloaded_group = @group_class.find(group.cn) + assert_equal([].collect(&:cn).sort, + reloaded_group.members.collect(&:cn).sort) end end end From codesite-noreply at google.com Fri Jun 13 20:28:11 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 17:28:11 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r745 - in trunk: . lib/active_ldap/association test Message-ID: <00163646d7ec2a6110044f957876@google.com> Author: koutou Date: Fri Jun 13 17:27:06 2008 New Revision: 745 Modified: trunk/README trunk/lib/active_ldap/association/belongs_to_many.rb trunk/test/test_associations.rb Log: * fix a bug that belongs_to :many with DN value can't be deleted. Reported by CultureSpy. Thanks!!! Modified: trunk/README ============================================================================== --- trunk/README (original) +++ trunk/README Fri Jun 13 17:27:06 2008 @@ -109,3 +109,4 @@ * Lennon Day-Reynolds: Bug reports. * Tilo: A bug report. * Matt Mencel: A bug report. +* CultureSpy: A bug report. Modified: trunk/lib/active_ldap/association/belongs_to_many.rb ============================================================================== --- trunk/lib/active_ldap/association/belongs_to_many.rb (original) +++ trunk/lib/active_ldap/association/belongs_to_many.rb Fri Jun 13 17:27:06 2008 @@ -17,7 +17,11 @@ def delete_entries(entries) entries.each do |entry| old_value = entry[@options[:many], true] - new_value = old_value - @owner[@options[:foreign_key_name], true] + foreign_key_name = @options[:foreign_key_name] + if foreign_key_name == "dn" + old_value = dn_values_to_string_values(old_value) + end + new_value = old_value - @owner[foreign_key_name, true] new_value = new_value.uniq.sort if old_value != new_value entry[@options[:many]] = new_value @@ -36,6 +40,16 @@ end options = find_options(:filter => [:or, *components]) foreign_class.find(:all, options) + end + + def dn_values_to_string_values(values) + values.collect do |value| + if value.is_a?(DN) + value.to_s + else + value + end + end end end end Modified: trunk/test/test_associations.rb ============================================================================== --- trunk/test/test_associations.rb (original) +++ trunk/test/test_associations.rb Fri Jun 13 17:27:06 2008 @@ -4,6 +4,46 @@ include AlTestUtils priority :must + def test_belongs_to_many_with_dn_value + @user_class.has_many :references, :wrap => "seeAlso", :primary_key => "dn" + @user_class.set_associated_class(:references, @group_class) + @group_class.belongs_to :related_users, :many => "seeAlso", + :foreign_key => "dn" + @group_class.set_associated_class(:related_users, @user_class) + make_temporary_group do |group| + make_temporary_user do |user1,| + make_temporary_user do |user2,| + make_temporary_user do |user3,| + entries = [group, user1, user2, user3] + + group.related_users = [user1, user2] + group, user1, user2, user3 = reload_entries(*entries) + assert_references([[group], [group], []], + [user1, user2, user3]) + assert_related_users([user1, user2], group) + + group.related_users << user3 + group, user1, user2, user3 = reload_entries(*entries) + assert_references([[group], [group], [group]], + [user1, user2, user3]) + assert_related_users([user1, user2, user3], group) + + group.related_users.delete(user1) + group, user1, user2, user3 = reload_entries(*entries) + assert_references([[], [group], [group]], + [user1, user2, user3]) + assert_related_users([user2, user3], group) + + group.related_users = [] + group, user1, user2, user3 = reload_entries(*entries) + assert_references([[], [], []], + [user1, user2, user3]) + assert_related_users([], group) + end + end + end + end + end priority :normal def test_belongs_to_many_with_dn_key @@ -14,27 +54,29 @@ make_temporary_group do |group| make_temporary_user do |user1,| make_temporary_user do |user2,| - group.members = [user1, user2] - assert(group.save) - assert_equal([group.cn], user1.groups.collect(&:cn)) - assert_equal([group.cn], user2.groups.collect(&:cn)) - reloaded_group = @group_class.find(group.cn) - assert_equal([user1, user2].collect(&:cn).sort, - reloaded_group.members.collect(&:cn).sort) - - user1.groups = [] - assert(user1.save) - assert_equal([], user1.groups.collect(&:cn)) - reloaded_group = @group_class.find(group.cn) - assert_equal([user2].collect(&:cn).sort, - reloaded_group.members.collect(&:cn).sort) - - user2.groups.delete(reloaded_group) - assert(user2.save) - assert_equal([], user2.groups.collect(&:cn)) - reloaded_group = @group_class.find(group.cn) - assert_equal([].collect(&:cn).sort, - reloaded_group.members.collect(&:cn).sort) + make_temporary_user do |user3,| + entries = [group, user1, user2, user3] + + user1.groups << group + group, user1, user2, user3 = reload_entries(*entries) + assert_groups([[group], [], []], [user1, user2, user3]) + assert_members([user1], group) + + user2.groups = [group] + group, user1, user2, user3 = reload_entries(*entries) + assert_groups([[group], [group], []], [user1, user2, user3]) + assert_members([user1, user2], group) + + user1.groups = [] + group, user1, user2, user3 = reload_entries(*entries) + assert_groups([[], [group], []], [user1, user2, user3]) + assert_members([user2], group) + + user2.groups.delete(group) + group, user1, user2, user3 = reload_entries(*entries) + assert_groups([[], [], []], [user1, user2, user3]) + assert_members([], group) + end end end end @@ -365,5 +407,43 @@ end end end + end + + private + def reload_entries(*entries) + entries.collect do |entry| + entry.class.find(entry[entry.dn_attribute]) + end + end + + def assert_groups_relation(expected_groups_values, entries, relation_name) + expected_groups_values = expected_groups_values.collect do |groups| + groups.collect(&:cn).sort + end + actual_groups_values = entries.collect do |entry| + entry.send(relation_name).collect(&:cn).sort + end + assert_equal(expected_groups_values, actual_groups_values) + end + + def assert_users_relation(expected_users, group, relation_name) + assert_equal(expected_users.collect(&:cn).sort, + group.send(relation_name).collect(&:cn).sort) + end + + def assert_references(expected_groups_values, users) + assert_groups_relation(expected_groups_values, users, :references) + end + + def assert_related_users(expected_users, group) + assert_users_relation(expected_users, group, :related_users) + end + + def assert_groups(expected_groups_values, users) + assert_groups_relation(expected_groups_values, users, :groups) + end + + def assert_members(expected_users, group) + assert_users_relation(expected_users, group, :members) end end From codesite-noreply at google.com Fri Jun 13 20:32:12 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 17:32:12 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r746 - trunk/lib/active_ldap/association Message-ID: <000e0cd20d8682da9a044f95861e@google.com> Author: koutou Date: Fri Jun 13 17:30:41 2008 New Revision: 746 Modified: trunk/lib/active_ldap/association/belongs_to_many.rb Log: * normalize DN to string. Modified: trunk/lib/active_ldap/association/belongs_to_many.rb ============================================================================== --- trunk/lib/active_ldap/association/belongs_to_many.rb (original) +++ trunk/lib/active_ldap/association/belongs_to_many.rb Fri Jun 13 17:30:41 2008 @@ -6,7 +6,11 @@ private def insert_entry(entry) old_value = entry[@options[:many], true] - new_value = old_value + @owner[@options[:foreign_key_name], true] + foreign_key_name = @options[:foreign_key_name] + if foreign_key_name == "dn" + old_value = dn_values_to_string_values(old_value) + end + new_value = old_value + @owner[foreign_key_name, true] new_value = new_value.uniq.sort if old_value != new_value entry[@options[:many]] = new_value From codesite-noreply at google.com Fri Jun 13 20:36:12 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 17:36:12 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r747 - trunk/test Message-ID: <000e0cd14b66d711e6044f959476@google.com> Author: koutou Date: Fri Jun 13 17:31:32 2008 New Revision: 747 Modified: trunk/test/test_reflection.rb Log: * don't use Inflector directly. Modified: trunk/test/test_reflection.rb ============================================================================== --- trunk/test/test_reflection.rb (original) +++ trunk/test/test_reflection.rb Fri Jun 13 17:31:32 2008 @@ -96,9 +96,7 @@ make_temporary_user do |user, password| attributes = user.must.collect(&:name) + user.may.collect(&:name) attributes -= ["objectClass"] - attributes = attributes.collect do |x| - Inflector.underscore(x) - end + attributes = attributes.collect(&:underscore) assert_equal([], attributes - user.methods) assert_equal([], attributes - user.methods(false)) @@ -115,9 +113,7 @@ user.remove_class("inetOrgPerson") attributes = user.must.collect(&:name) + user.may.collect(&:name) attributes -= ["objectClass"] - attributes = attributes.collect do |x| - Inflector.underscore(x) - end + attributes = attributes.collect(&:underscore) assert_equal([], attributes - user.methods) assert_equal([], attributes - user.methods(false)) From codesite-noreply at google.com Fri Jun 13 20:42:13 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 17:42:13 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r748 - in trunk: lib/active_ldap/association test Message-ID: <000e0cd28d765846ab044f95aa47@google.com> Author: koutou Date: Fri Jun 13 17:41:48 2008 New Revision: 748 Modified: trunk/lib/active_ldap/association/belongs_to_many.rb trunk/lib/active_ldap/association/collection.rb trunk/lib/active_ldap/association/has_many_wrap.rb trunk/test/test_associations.rb Log: * fix bugs related DN and associations. Modified: trunk/lib/active_ldap/association/belongs_to_many.rb ============================================================================== --- trunk/lib/active_ldap/association/belongs_to_many.rb (original) +++ trunk/lib/active_ldap/association/belongs_to_many.rb Fri Jun 13 17:41:48 2008 @@ -45,16 +45,6 @@ options = find_options(:filter => [:or, *components]) foreign_class.find(:all, options) end - - def dn_values_to_string_values(values) - values.collect do |value| - if value.is_a?(DN) - value.to_s - else - value - end - end - end end end end Modified: trunk/lib/active_ldap/association/collection.rb ============================================================================== --- trunk/lib/active_ldap/association/collection.rb (original) +++ trunk/lib/active_ldap/association/collection.rb Fri Jun 13 17:41:48 2008 @@ -78,6 +78,16 @@ result && self end + + def dn_values_to_string_values(values) + values.collect do |value| + if value.is_a?(DN) + value.to_s + else + value + end + end + end end end end Modified: trunk/lib/active_ldap/association/has_many_wrap.rb ============================================================================== --- trunk/lib/active_ldap/association/has_many_wrap.rb (original) +++ trunk/lib/active_ldap/association/has_many_wrap.rb Fri Jun 13 17:41:48 2008 @@ -9,7 +9,11 @@ private def insert_entry(entry) old_value = @owner[@options[:wrap], true] - new_value = (old_value + entry[primary_key, true]).uniq.sort + _primary_key = primary_key + if _primary_key == "dn" + old_value = dn_values_to_string_values(old_value) + end + new_value = (old_value + entry[_primary_key, true]).uniq.sort if old_value != new_value @owner[@options[:wrap]] = new_value @owner.save @@ -18,7 +22,11 @@ def delete_entries(entries) old_value = @owner[@options[:wrap], true] - new_value = old_value - entries.collect {|entry| entry[primary_key]} + _primary_key = primary_key + if _primary_key == "dn" + old_value = dn_values_to_string_values(old_value) + end + new_value = old_value - entries.collect {|entry| entry[_primary_key]} new_value = new_value.uniq.sort if old_value != new_value @owner[@options[:wrap]] = new_value Modified: trunk/test/test_associations.rb ============================================================================== --- trunk/test/test_associations.rb (original) +++ trunk/test/test_associations.rb Fri Jun 13 17:41:48 2008 @@ -4,6 +4,45 @@ include AlTestUtils priority :must + def test_has_many_wrap_with_dn_value + @user_class.has_many :references, :wrap => "seeAlso", :primary_key => "dn" + @user_class.set_associated_class(:references, @group_class) + @group_class.belongs_to :related_users, :many => "seeAlso", + :foreign_key => "dn" + @group_class.set_associated_class(:related_users, @user_class) + make_temporary_user do |user,| + make_temporary_group do |group1| + make_temporary_group do |group2| + make_temporary_group do |group3| + entries = [user, group1, group2, group3] + + user.references << group1 + user, group1, group2, group3 = reload_entries(*entries) + assert_references([[group1]], [user]) + assert_related_users([user], group1) + assert_related_users([], group2) + assert_related_users([], group3) + + user.references = [group2, group3] + user, group1, group2, group3 = reload_entries(*entries) + assert_references([[group2, group3]], [user]) + assert_related_users([], group1) + assert_related_users([user], group2) + assert_related_users([user], group3) + + user.references.delete(group2) + user, group1, group2, group3 = reload_entries(*entries) + assert_references([[group3]], [user]) + assert_related_users([], group1) + assert_related_users([], group2) + assert_related_users([user], group3) + end + end + end + end + end + + priority :normal def test_belongs_to_many_with_dn_value @user_class.has_many :references, :wrap => "seeAlso", :primary_key => "dn" @user_class.set_associated_class(:references, @group_class) @@ -45,7 +84,6 @@ end end - priority :normal def test_belongs_to_many_with_dn_key @user_class.belongs_to :groups, :many => "memberUid", :foreign_key => "dn" @user_class.set_associated_class(:groups, @group_class) From codesite-noreply at google.com Fri Jun 13 20:49:14 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 17:49:14 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r749 - trunk/lib/active_ldap Message-ID: <000e0cd14b666ce58e044f95c339@google.com> Author: koutou Date: Fri Jun 13 17:48:57 2008 New Revision: 749 Modified: trunk/lib/active_ldap/connection.rb Log: * use Object.respond_to?(:java) not defined?(java). Modified: trunk/lib/active_ldap/connection.rb ============================================================================== --- trunk/lib/active_ldap/connection.rb (original) +++ trunk/lib/active_ldap/connection.rb Fri Jun 13 17:48:57 2008 @@ -191,7 +191,7 @@ end def guess_available_adapter - defined?(java) ? "jndi" : "ldap" + Object.respond_to?(:java) ? "jndi" : "ldap" end end From codesite-noreply at google.com Fri Jun 13 20:53:15 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 17:53:15 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r750 - trunk/test Message-ID: <000e0cd2e756c6a4f1044f95d130@google.com> Author: koutou Date: Fri Jun 13 17:52:51 2008 New Revision: 750 Modified: trunk/test/test_reflection.rb Log: * don't use Inflector directly. Modified: trunk/test/test_reflection.rb ============================================================================== --- trunk/test/test_reflection.rb (original) +++ trunk/test/test_reflection.rb Fri Jun 13 17:52:51 2008 @@ -102,7 +102,7 @@ normalize_attributes_list = Proc.new do |*attributes_list| attributes_list.collect do |attrs| - attrs.collect {|x| Inflector.underscore(x)} + attrs.collect(&:underscore) end end assert_methods_with_only_required_classes(user, attributes, @@ -119,7 +119,7 @@ normalize_attributes_list = Proc.new do |*attributes_list| attributes_list.collect do |attrs| - attrs.collect {|x| Inflector.underscore(x)} + attrs.collect(&:underscore) end end assert_methods_with_only_required_classes(user, attributes, From codesite-noreply at google.com Fri Jun 13 21:08:15 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 18:08:15 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r751 - trunk/test Message-ID: <001636e1fbd1773e8d044f9607a8@google.com> Author: koutou Date: Fri Jun 13 18:07:26 2008 New Revision: 751 Modified: trunk/test/al-test-utils.rb Log: * don't instantiate when deleting user. Modified: trunk/test/al-test-utils.rb ============================================================================== --- trunk/test/al-test-utils.rb (original) +++ trunk/test/al-test-utils.rb Fri Jun 13 18:07:26 2008 @@ -289,9 +289,10 @@ yield(uid) ensure if @user_class.exists?(uid) - user = @user_class.find(uid) - user.remove_connection - @user_class.delete(user.dn) + @user_class.search(:value => uid) do |dn, attribute| + @user_class.remove_connection(dn) + @user_class.delete(dn) + end end end From codesite-noreply at google.com Fri Jun 13 21:24:16 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 18:24:16 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r752 - trunk/lib/active_ldap/adapter Message-ID: <000e0cd2dde0bba8fb044f964015@google.com> Author: koutou Date: Fri Jun 13 18:23:33 2008 New Revision: 752 Modified: trunk/lib/active_ldap/adapter/jndi_connection.rb Log: * reconnect to ensure binding. Modified: trunk/lib/active_ldap/adapter/jndi_connection.rb ============================================================================== --- trunk/lib/active_ldap/adapter/jndi_connection.rb (original) +++ trunk/lib/active_ldap/adapter/jndi_connection.rb Fri Jun 13 18:23:33 2008 @@ -168,6 +168,7 @@ if password context.add_to_environment(Context::SECURITY_CREDENTIALS, password) end + context.reconnect(nil) @context = context end From codesite-noreply at google.com Fri Jun 13 21:31:17 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 18:31:17 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r753 - trunk/lib/active_ldap/adapter Message-ID: <000e0cd14b66ceef51044f9659c9@google.com> Author: koutou Date: Fri Jun 13 18:30:33 2008 New Revision: 753 Modified: trunk/lib/active_ldap/adapter/jndi_connection.rb Log: * use blank?. Modified: trunk/lib/active_ldap/adapter/jndi_connection.rb ============================================================================== --- trunk/lib/active_ldap/adapter/jndi_connection.rb (original) +++ trunk/lib/active_ldap/adapter/jndi_connection.rb Fri Jun 13 18:30:33 2008 @@ -103,7 +103,7 @@ controls = SearchControls.new controls.search_scope = scope - if attrs && !attrs.empty? + unless attrs.blank? controls.returning_attributes = attrs.to_java(:string) end From codesite-noreply at google.com Fri Jun 13 21:54:19 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 13 Jun 2008 18:54:19 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r754 - trunk Message-ID: <000e0cd2401c2fa4dd044f96acd2@google.com> Author: koutou Date: Fri Jun 13 18:53:58 2008 New Revision: 754 Modified: trunk/CHANGES Log: * updated 1.0.1 entry. Modified: trunk/CHANGES ============================================================================== --- trunk/CHANGES (original) +++ trunk/CHANGES Fri Jun 13 18:53:58 2008 @@ -1,6 +1,7 @@ 1.0.1: * Fixed GetText integration. * Fixed ActiveLdap::Base.find with ActiveLdap::DN. (Reported by Jeremy Pruitt) + * Fixed associated bugs. (Reported by CultureSpy) * Supported ActiveLdap::Base#attribute_present? with nonexistence attribute. (Reported by Matt Mencel) * Added ActiveLdap::Base#.to_ldif_record. From codesite-noreply at google.com Sat Jun 14 09:48:36 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sat, 14 Jun 2008 06:48:36 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r755 - trunk/lib/active_ldap Message-ID: <00163646d64eade53a044fa0a6f5@google.com> Author: koutou Date: Sat Jun 14 06:47:42 2008 New Revision: 755 Modified: trunk/lib/active_ldap/ldif.rb Log: * fix to_ldif failure for non-string attribute value. Modified: trunk/lib/active_ldap/ldif.rb ============================================================================== --- trunk/lib/active_ldap/ldif.rb (original) +++ trunk/lib/active_ldap/ldif.rb Sat Jun 14 06:47:42 2008 @@ -32,6 +32,7 @@ module_function def encode(name, value) + value = value.to_s if !value.is_a?(String) or !value.nil? return "#{name}:\n" if value.blank? result = "#{name}:" From codesite-noreply at google.com Sat Jun 14 10:05:38 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sat, 14 Jun 2008 07:05:38 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r756 - trunk/test Message-ID: <00163645923c98d824044fa0e333@google.com> Author: koutou Date: Sat Jun 14 07:04:52 2008 New Revision: 756 Modified: trunk/test/run-test.rb trunk/test/test_ldif.rb Log: * remove duplicated test. Modified: trunk/test/run-test.rb ============================================================================== --- trunk/test/run-test.rb (original) +++ trunk/test/run-test.rb Sat Jun 14 07:04:52 2008 @@ -1,5 +1,7 @@ #!/usr/bin/env ruby +$VERBOSE = true + $KCODE = 'u' require 'yaml' Modified: trunk/test/test_ldif.rb ============================================================================== --- trunk/test/test_ldif.rb (original) +++ trunk/test/test_ldif.rb Sat Jun 14 07:04:52 2008 @@ -564,6 +564,55 @@ - EOL + assert_ldif_to_s(<<-EOL, ldif_source) +version: 1 +dn: cn=Fiona Jensen,ou=Marketing,dc=airius,dc=com +changetype: add +cn: Fiona Jensen +objectclass: organizationalPerson +objectclass: person +objectclass: top +sn: Jensen +telephonenumber: +1 408 555 1212 +uid: fiona + +dn: cn=Robert Jensen,ou=Marketing,dc=airius,dc=com +changetype: delete + +dn: cn=Paul Jensen,ou=Product Development,dc=airius,dc=com +changetype: modrdn +newrdn: cn=Paula Jensen +deleteoldrdn: 1 + +dn: ou=PD Accountants,ou=Product Development,dc=airius,dc=com +changetype: modrdn +newrdn: ou=Product Development Accountants +deleteoldrdn: 0 +newsuperior: ou=Accounting,dc=airius,dc=com + +dn: cn=Paula Jensen,ou=Product Development,dc=airius,dc=com +changetype: modify +add: postaladdress +postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086 +- +delete: description +- +replace: telephonenumber +telephonenumber: +1 408 555 1234 +telephonenumber: +1 408 555 5678 +- +delete: facsimiletelephonenumber +facsimiletelephonenumber: +1 408 555 9876 +- + +dn: cn=Ingrid Jensen,ou=Product Support,dc=airius,dc=com +changetype: modify +replace: postaladdress +- +delete: description +- +EOL + change_attributes_add = { "dn" => "cn=Fiona Jensen,ou=Marketing,dc=airius,dc=com", "objectclass" => ["top", "person", "organizationalPerson"], @@ -665,120 +714,6 @@ end assert_equal(operations.collect {|operation| [true, operation]}, actual) - end - - def test_multi_change_type_records - ldif_source = <<-EOL -version: 1 -# Add a new entry -dn: cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com -changetype: add -objectclass: top -objectclass: person -objectclass: organizationalPerson -cn: Fiona Jensen -sn: Jensen -uid: fiona -telephonenumber: +1 408 555 1212 - -# Delete an existing entry -dn: cn=Robert Jensen, ou=Marketing, dc=airius, dc=com -changetype: delete - -# Modify an entry's relative distinguished name -dn: cn=Paul Jensen, ou=Product Development, dc=airius, dc=com -changetype: modrdn -newrdn: cn=Paula Jensen -deleteoldrdn: 1 - -# Rename an entry and move all of its children to a new location in -# the directory tree (only implemented by LDAPv3 servers). -dn: ou=PD Accountants, ou=Product Development, dc=airius, dc=com -changetype: modrdn -newrdn: ou=Product Development Accountants -deleteoldrdn: 0 -newsuperior: ou=Accounting, dc=airius, dc=com - -# Modify an entry: add an additional value to the postaladdress -# attribute, completely delete the description attribute, replace -# the telephonenumber attribute with two values, and delete a specific -# value from the facsimiletelephonenumber attribute -dn: cn=Paula Jensen, ou=Product Development, dc=airius, dc=com -changetype: modify -add: postaladdress -postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086 -- -delete: description -- -replace: telephonenumber -telephonenumber: +1 408 555 1234 -telephonenumber: +1 408 555 5678 -- -delete: facsimiletelephonenumber -facsimiletelephonenumber: +1 408 555 9876 -- - -# Modify an entry: replace the postaladdress attribute with an empty -# set of values (which will cause the attribute to be removed), and -# delete the entire description attribute. Note that the first will -# always succeed, while the second will only succeed if at least -# one value for the description attribute is present. -dn: cn=Ingrid Jensen, ou=Product Support, dc=airius, dc=com -changetype: modify -replace: postaladdress -- -delete: description -- -EOL - - assert_ldif_to_s(<<-EOL, ldif_source) -version: 1 -dn: cn=Fiona Jensen,ou=Marketing,dc=airius,dc=com -changetype: add -cn: Fiona Jensen -objectclass: organizationalPerson -objectclass: person -objectclass: top -sn: Jensen -telephonenumber: +1 408 555 1212 -uid: fiona - -dn: cn=Robert Jensen,ou=Marketing,dc=airius,dc=com -changetype: delete - -dn: cn=Paul Jensen,ou=Product Development,dc=airius,dc=com -changetype: modrdn -newrdn: cn=Paula Jensen -deleteoldrdn: 1 - -dn: ou=PD Accountants,ou=Product Development,dc=airius,dc=com -changetype: modrdn -newrdn: ou=Product Development Accountants -deleteoldrdn: 0 -newsuperior: ou=Accounting,dc=airius,dc=com - -dn: cn=Paula Jensen,ou=Product Development,dc=airius,dc=com -changetype: modify -add: postaladdress -postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086 -- -delete: description -- -replace: telephonenumber -telephonenumber: +1 408 555 1234 -telephonenumber: +1 408 555 5678 -- -delete: facsimiletelephonenumber -facsimiletelephonenumber: +1 408 555 9876 -- - -dn: cn=Ingrid Jensen,ou=Product Support,dc=airius,dc=com -changetype: modify -replace: postaladdress -- -delete: description -- -EOL end def test_modify_record From codesite-noreply at google.com Sat Jun 14 10:10:38 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sat, 14 Jun 2008 07:10:38 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r757 - trunk/lib/active_ldap Message-ID: <0016364585e87f90ef044fa0f5cf@google.com> Author: koutou Date: Sat Jun 14 07:10:10 2008 New Revision: 757 Modified: trunk/lib/active_ldap/validations.rb Log: * don't discard old method. Modified: trunk/lib/active_ldap/validations.rb ============================================================================== --- trunk/lib/active_ldap/validations.rb (original) +++ trunk/lib/active_ldap/validations.rb Sat Jun 14 07:10:10 2008 @@ -13,6 +13,8 @@ end include ActiveRecord::Validations class << self + alias_method :human_attribute_name_active_record, + :human_attribute_name alias_method :human_attribute_name, :human_attribute_name_active_ldap unless method_defined?(:human_attribute_name_with_gettext) From codesite-noreply at google.com Sat Jun 14 10:14:40 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sat, 14 Jun 2008 07:14:40 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r758 - trunk/lib/active_ldap Message-ID: <0016e64af356e0595b044fa103e2@google.com> Author: koutou Date: Sat Jun 14 07:12:00 2008 New Revision: 758 Modified: trunk/lib/active_ldap/ldif.rb Log: * initialize @sub_scanner as nil. Modified: trunk/lib/active_ldap/ldif.rb ============================================================================== --- trunk/lib/active_ldap/ldif.rb (original) +++ trunk/lib/active_ldap/ldif.rb Sat Jun 14 07:12:00 2008 @@ -480,6 +480,7 @@ def initialize(source) @source = source @scanner = StringScanner.new(@source) + @sub_scanner = nil @sub_scanner = next_segment || StringScanner.new("") end From codesite-noreply at google.com Sat Jun 14 10:18:40 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sat, 14 Jun 2008 07:18:40 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r759 - trunk/test Message-ID: <0016e64ca7d636bb00044fa1128a@google.com> Author: koutou Date: Sat Jun 14 07:15:54 2008 New Revision: 759 Modified: trunk/test/test_associations.rb Log: * suppress warnings. Modified: trunk/test/test_associations.rb ============================================================================== --- trunk/test/test_associations.rb (original) +++ trunk/test/test_associations.rb Sat Jun 14 07:15:54 2008 @@ -85,9 +85,9 @@ end def test_belongs_to_many_with_dn_key - @user_class.belongs_to :groups, :many => "memberUid", :foreign_key => "dn" + @user_class.belongs_to :dn_groups, :many => "memberUid", :foreign_key => "dn" @user_class.set_associated_class(:groups, @group_class) - @group_class.has_many :members, :wrap => "memberUid", :primary_key => "dn" + @group_class.has_many :dn_members, :wrap => "memberUid", :primary_key => "dn" @group_class.set_associated_class(:members, @user_class) make_temporary_group do |group| make_temporary_user do |user1,| @@ -95,25 +95,25 @@ make_temporary_user do |user3,| entries = [group, user1, user2, user3] - user1.groups << group + user1.dn_groups << group group, user1, user2, user3 = reload_entries(*entries) - assert_groups([[group], [], []], [user1, user2, user3]) - assert_members([user1], group) + assert_dn_groups([[group], [], []], [user1, user2, user3]) + assert_dn_members([user1], group) - user2.groups = [group] + user2.dn_groups = [group] group, user1, user2, user3 = reload_entries(*entries) - assert_groups([[group], [group], []], [user1, user2, user3]) - assert_members([user1, user2], group) + assert_dn_groups([[group], [group], []], [user1, user2, user3]) + assert_dn_members([user1, user2], group) - user1.groups = [] + user1.dn_groups = [] group, user1, user2, user3 = reload_entries(*entries) - assert_groups([[], [group], []], [user1, user2, user3]) - assert_members([user2], group) + assert_dn_groups([[], [group], []], [user1, user2, user3]) + assert_dn_members([user2], group) - user2.groups.delete(group) + user2.dn_groups.delete(group) group, user1, user2, user3 = reload_entries(*entries) - assert_groups([[], [], []], [user1, user2, user3]) - assert_members([], group) + assert_dn_groups([[], [], []], [user1, user2, user3]) + assert_dn_members([], group) end end end @@ -477,11 +477,11 @@ assert_users_relation(expected_users, group, :related_users) end - def assert_groups(expected_groups_values, users) - assert_groups_relation(expected_groups_values, users, :groups) + def assert_dn_groups(expected_groups_values, users) + assert_groups_relation(expected_groups_values, users, :dn_groups) end - def assert_members(expected_users, group) - assert_users_relation(expected_users, group, :members) + def assert_dn_members(expected_users, group) + assert_users_relation(expected_users, group, :dn_members) end end From codesite-noreply at google.com Sat Jun 14 10:22:41 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sat, 14 Jun 2008 07:22:41 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r760 - trunk/test Message-ID: <0016e64beb5488edd8044fa12007@google.com> Author: koutou Date: Sat Jun 14 07:16:38 2008 New Revision: 760 Modified: trunk/test/test_associations.rb Log: * follow up the previous commit. Modified: trunk/test/test_associations.rb ============================================================================== --- trunk/test/test_associations.rb (original) +++ trunk/test/test_associations.rb Sat Jun 14 07:16:38 2008 @@ -86,9 +86,9 @@ def test_belongs_to_many_with_dn_key @user_class.belongs_to :dn_groups, :many => "memberUid", :foreign_key => "dn" - @user_class.set_associated_class(:groups, @group_class) + @user_class.set_associated_class(:dn_groups, @group_class) @group_class.has_many :dn_members, :wrap => "memberUid", :primary_key => "dn" - @group_class.set_associated_class(:members, @user_class) + @group_class.set_associated_class(:dn_members, @user_class) make_temporary_group do |group| make_temporary_user do |user1,| make_temporary_user do |user2,| From codesite-noreply at google.com Sat Jun 14 10:28:41 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sat, 14 Jun 2008 07:28:41 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r761 - in trunk: lib/active_ldap/action_controller rails/plugin/active_ldap Message-ID: <0016e64ca7d607db3a044fa136ec@google.com> Author: koutou Date: Sat Jun 14 07:27:37 2008 New Revision: 761 Added: trunk/lib/active_ldap/action_controller/ trunk/lib/active_ldap/action_controller/ldap_benchmarking.rb Modified: trunk/rails/plugin/active_ldap/init.rb Log: * modularize LDAP benchmarking. Added: trunk/lib/active_ldap/action_controller/ldap_benchmarking.rb ============================================================================== --- (empty file) +++ trunk/lib/active_ldap/action_controller/ldap_benchmarking.rb Sat Jun 14 07:27:37 2008 @@ -0,0 +1,36 @@ +module ActiveLdap + module ActionController + module LdapBenchmarking + def self.included(base) + base.class_eval do + alias_method_chain :render, :active_ldap_benchmark + alias_method_chain :rendering_runtime, :active_ldap + end + end + + protected + def render_with_active_ldap_benchmark(*args, &block) + if logger + @ldap_runtime_before_render = ActiveLdap::Base.reset_runtime + result = render_without_active_ldap_benchmark(*args, &block) + @ldap_runtime_after_render = ActiveLdap::Base.reset_runtime + @rendering_runtime -= @ldap_runtime_after_render + result + else + render_without_active_ldap_benchmark(*args, &block) + end + end + + private + def rendering_runtime_with_active_ldap(runtime) + result = rendering_runtime_without_active_ldap(runtime) + ldap_runtime = ActiveLdap::Base.reset_runtime + ldap_runtime += @ldap_runtime_before_render || 0 + ldap_runtime += @ldap_runtime_after_render || 0 + ldap_percentage = ldap_runtime * 100 / runtime + result + (" | LDAP: %.5f (%d%%)" % [ldap_runtime, ldap_percentage]) + end + end + end +end + Modified: trunk/rails/plugin/active_ldap/init.rb ============================================================================== --- trunk/rails/plugin/active_ldap/init.rb (original) +++ trunk/rails/plugin/active_ldap/init.rb Sat Jun 14 07:27:37 2008 @@ -1,7 +1,7 @@ require_library_or_gem 'active_ldap' ActiveLdap::Base.logger ||= RAILS_DEFAULT_LOGGER -required_version = ["0", "10", "0"] +required_version = ["1", "0", "0"] if (ActiveLdap::VERSION.split(".") <=> required_version) < 0 ActiveLdap::Base.class_eval do format = _("You need ActiveLdap %s or later") @@ -25,40 +25,9 @@ include ActiveLdap::Helper end +require 'active_ldap/action_controller/ldap_benchmarking' module ::ActionController - module LdapBenchmarking - def self.included(base) - base.class_eval do - alias_method_chain :render, :active_ldap_benchmark - alias_method_chain :rendering_runtime, :active_ldap - end - end - - protected - def render_with_active_ldap_benchmark(*args, &block) - if logger - @ldap_runtime_before_render = ActiveLdap::Base.reset_runtime - result = render_without_active_ldap_benchmark(*args, &block) - @ldap_runtime_after_render = ActiveLdap::Base.reset_runtime - @rendering_runtime -= @ldap_runtime_after_render - result - else - render_without_active_ldap_benchmark(*args, &block) - end - end - - private - def rendering_runtime_with_active_ldap(runtime) - result = rendering_runtime_without_active_ldap(runtime) - ldap_runtime = ActiveLdap::Base.reset_runtime - ldap_runtime += @ldap_runtime_before_render || 0 - ldap_runtime += @ldap_runtime_after_render || 0 - ldap_percentage = ldap_runtime * 100 / runtime - result + (" | LDAP: %.5f (%d%%)" % [ldap_runtime, ldap_percentage]) - end - end - class Base - include LdapBenchmarking + include ActiveLdap::ActionController::LdapBenchmarking end end From codesite-noreply at google.com Sat Jun 14 20:51:49 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sat, 14 Jun 2008 17:51:49 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r762 - in trunk: lib/active_ldap test Message-ID: <00163645923c851539044fa9eacf@google.com> Author: koutou Date: Sat Jun 14 17:51:21 2008 New Revision: 762 Modified: trunk/lib/active_ldap/base.rb trunk/lib/active_ldap/ldif.rb trunk/test/test_base.rb Log: * use normalize_data not to_s. Modified: trunk/lib/active_ldap/base.rb ============================================================================== --- trunk/lib/active_ldap/base.rb (original) +++ trunk/lib/active_ldap/base.rb Sat Jun 14 17:51:21 2008 @@ -809,7 +809,7 @@ end def to_ldif_record - super(dn, @data) + super(dn, normalize_data(@data)) end def to_ldif Modified: trunk/lib/active_ldap/ldif.rb ============================================================================== --- trunk/lib/active_ldap/ldif.rb (original) +++ trunk/lib/active_ldap/ldif.rb Sat Jun 14 17:51:21 2008 @@ -32,7 +32,6 @@ module_function def encode(name, value) - value = value.to_s if !value.is_a?(String) or !value.nil? return "#{name}:\n" if value.blank? result = "#{name}:" Modified: trunk/test/test_base.rb ============================================================================== --- trunk/test/test_base.rb (original) +++ trunk/test/test_base.rb Sat Jun 14 17:51:21 2008 @@ -6,6 +6,16 @@ include AlTestUtils priority :must + def test_to_ldif + make_temporary_group do |group,| + assert_to_ldif(group) + + group.gidNumber += 1 + group.description = ["Description", {"en" => "Description(en)"}] + assert_to_ldif(group) + end + end + priority :normal def test_save_with_changes make_temporary_user do |user, password| @@ -661,5 +671,13 @@ end yield modify_called + end + + def assert_to_ldif(entry) + records = ActiveLdap::LDIF.parse(entry.to_ldif).records + parsed_entries = records.collect do |record| + entry.class.send(:instantiate, [record.dn, record.attributes]) + end + assert_equal([entry], parsed_entries) end end From codesite-noreply at google.com Sun Jun 15 11:48:47 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sun, 15 Jun 2008 08:48:47 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r763 - in trunk: . examples/al-admin/po/en examples/al-admin/po/ja examples/al-admin/po/nl po/en ... Message-ID: <000e0cd1748859227c044fb67209@google.com> Author: wad Date: Sun Jun 15 08:48:07 2008 New Revision: 763 Modified: trunk/README trunk/examples/al-admin/po/en/al-admin.po trunk/examples/al-admin/po/ja/al-admin.po trunk/examples/al-admin/po/nl/al-admin.po trunk/po/en/active-ldap.po trunk/po/ja/active-ldap.po Log: bring all versions up to 1.0.1 Modified: trunk/README ============================================================================== --- trunk/README (original) +++ trunk/README Sun Jun 15 08:48:07 2008 @@ -29,7 +29,6 @@ NOTES * Only GSSAPI SASL support exists due to Ruby/LDAP limitations - * The API is subject to change as this package slowly approaches 1.0.0 INSTALL Modified: trunk/examples/al-admin/po/en/al-admin.po ============================================================================== --- trunk/examples/al-admin/po/en/al-admin.po (original) +++ trunk/examples/al-admin/po/en/al-admin.po Sun Jun 15 08:48:07 2008 @@ -5,7 +5,7 @@ # msgid "" msgstr "" -"Project-Id-Version: AL Admin 1.0.0\n" +"Project-Id-Version: AL Admin 1.0.1\n" "POT-Creation-Date: 2008-02-09 14:25+0900\n" "PO-Revision-Date: 2007-08-19 09:44+0900\n" "Last-Translator: Kouhei Sutou \n" Modified: trunk/examples/al-admin/po/ja/al-admin.po ============================================================================== --- trunk/examples/al-admin/po/ja/al-admin.po (original) +++ trunk/examples/al-admin/po/ja/al-admin.po Sun Jun 15 08:48:07 2008 @@ -5,7 +5,7 @@ # msgid "" msgstr "" -"Project-Id-Version: AL Admin 1.0.0\n" +"Project-Id-Version: AL Admin 1.0.1\n" "POT-Creation-Date: 2008-02-09 14:25+0900\n" "PO-Revision-Date: 2007-11-04 16:02+0900\n" "Last-Translator: Kouhei Sutou \n" Modified: trunk/examples/al-admin/po/nl/al-admin.po ============================================================================== --- trunk/examples/al-admin/po/nl/al-admin.po (original) +++ trunk/examples/al-admin/po/nl/al-admin.po Sun Jun 15 08:48:07 2008 @@ -6,7 +6,7 @@ # Ace Suares , 2007,2008. msgid "" msgstr "" -"Project-Id-Version: AL Admin 1.0.0\n" +"Project-Id-Version: AL Admin 1.0.1\n" "POT-Creation-Date: 2008-02-09 14:25+0900\n" "PO-Revision-Date: 2007-08-24 22:03+0900\n" "Last-Translator: Ace Suares \n" Modified: trunk/po/en/active-ldap.po ============================================================================== --- trunk/po/en/active-ldap.po (original) +++ trunk/po/en/active-ldap.po Sun Jun 15 08:48:07 2008 @@ -5,7 +5,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Ruby/ActiveLdap 1.0.0\n" +"Project-Id-Version: Ruby/ActiveLdap 1.0.1\n" "POT-Creation-Date: 2008-02-10 22:36+0900\n" "PO-Revision-Date: 2007-08-19 09:49+0900\n" "Last-Translator: Kouhei Sutou \n" Modified: trunk/po/ja/active-ldap.po ============================================================================== --- trunk/po/ja/active-ldap.po (original) +++ trunk/po/ja/active-ldap.po Sun Jun 15 08:48:07 2008 @@ -5,7 +5,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Ruby/ActiveLdap 1.0.0\n" +"Project-Id-Version: Ruby/ActiveLdap 1.0.1\n" "POT-Creation-Date: 2008-02-10 22:36+0900\n" "PO-Revision-Date: 2008-02-10 22:37+0900\n" "Last-Translator: Kouhei Sutou \n" From codesite-noreply at google.com Sun Jun 15 11:52:48 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Sun, 15 Jun 2008 08:52:48 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r764 - tags/r1.0.1 Message-ID: <000e0cd147e6b00b85044fb68079@google.com> Author: wad Date: Sun Jun 15 08:48:21 2008 New Revision: 764 Added: tags/r1.0.1/ - copied from r763, /trunk/ Log: New release tag From codesite-noreply at google.com Tue Jun 17 08:42:55 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Tue, 17 Jun 2008 05:42:55 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r765 - trunk/benchmark Message-ID: <000e0cd16e504f21c3044fdc15a4@google.com> Author: koutou Date: Tue Jun 17 05:42:06 2008 New Revision: 765 Modified: trunk/benchmark/bench-al.rb Log: * benchmark Ruby/LDAP and Net::LDAP backend. Modified: trunk/benchmark/bench-al.rb ============================================================================== --- trunk/benchmark/bench-al.rb (original) +++ trunk/benchmark/bench-al.rb Tue Jun 17 05:42:06 2008 @@ -33,19 +33,41 @@ :classes => ['posixAccount', 'person'] end -# === search_al -# -def search_al +class ALUserLdap < ALUser +end +ALUserLdap.establish_connection(config.merge(:adapter => "ldap")) + +class ALUserNetLdap < ALUser +end +ALUserNetLdap.establish_connection(config.merge(:adapter => "net-ldap")) + +def search_al_ldap count = 0 - ALUser.find(:all).each do |e| + ALUserLdap.find(:all).each do |e| count += 1 end count -end # -- search_al +end -def search_al_without_object_creation +def search_al_net_ldap count = 0 - ALUser.search.each do |e| + ALUserNetLdap.find(:all).each do |e| + count += 1 + end + count +end + +def search_al_ldap_without_object_creation + count = 0 + ALUserLdap.search.each do |e| + count += 1 + end + count +end + +def search_al_net_ldap_without_object_creation + count = 0 + ALUserNetLdap.search.each do |e| count += 1 end count @@ -161,6 +183,7 @@ dumped_data = ActiveLdap::Base.dump(:scope => :sub) ActiveLdap::Base.delete_all(nil, :scope => :sub) populate + puts end # Standard connection @@ -168,18 +191,33 @@ ldap_conn = ldap_connection net_ldap_conn = net_ldap_connection - al_count = 0 - al_count_without_object_creation = 0 + al_ldap_count = 0 + al_net_ldap_count = 0 + al_ldap_count_without_object_creation = 0 + al_net_ldap_count_without_object_creation = 0 ldap_count = 0 net_ldap_count = 0 Benchmark.bmbm(20) do |x| [1].each do |n| GC.start - x.report("%3dx: AL" % n) {n.times {al_count = search_al}} + x.report("%3dx: AL(LDAP)" % n) do + n.times {al_ldap_count = search_al_ldap} + end + GC.start + x.report("%3dx: AL(Net::LDAP)" % n) do + n.times {al_net_ldap_count = search_al_net_ldap} + end GC.start - x.report("%3dx: AL(No Obj)" % n) do + x.report("%3dx: AL(LDAP: No Obj)" % n) do + n.times do + al_ldap_count_without_object_creation = + search_al_ldap_without_object_creation + end + end + x.report("%3dx: AL(Net::LDAP: No Obj)" % n) do n.times do - al_count_without_object_creation = search_al_without_object_creation + al_net_ldap_count_without_object_creation = + search_al_net_ldap_without_object_creation end end GC.start @@ -196,13 +234,22 @@ end end end - puts(_("Entries processed by Ruby/ActiveLdap: %d") % al_count) - puts(_("Entries processed by Ruby/ActiveLdap (without object creation): " \ - "%d") % al_count_without_object_creation) + + puts + puts(_("Entries processed by Ruby/ActiveLdap + LDAP: %d") % al_ldap_count) + puts(_("Entries processed by Ruby/ActiveLdap + Net::LDAP: %d") % \ + al_net_ldap_count) + puts(_("Entries processed by Ruby/ActiveLdap + LDAP: " \ + "(without object creation): %d") % \ + al_ldap_count_without_object_creation) + puts(_("Entries processed by Ruby/ActiveLdap + Net::LDAP: " \ + "(without object creation): %d") % \ + al_net_ldap_count_without_object_creation) puts(_("Entries processed by Ruby/LDAP: %d") % ldap_count) puts(_("Entries processed by Net::LDAP: %d") % net_ldap_count) ensure if do_populate + puts puts(_("Cleaning...")) ActiveLdap::Base.delete_all(nil, :scope => :sub) ActiveLdap::Base.load(dumped_data) From codesite-noreply at google.com Tue Jun 17 09:25:33 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Tue, 17 Jun 2008 06:25:33 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r767 - in trunk: lib/active_ldap test Message-ID: <000e0cd16e50c44c7f044fdcad58@google.com> Author: koutou Date: Tue Jun 17 06:25:17 2008 New Revision: 767 Modified: trunk/lib/active_ldap/user_password.rb trunk/test/test_user_password.rb Log: * don't use Base64 module. Modified: trunk/lib/active_ldap/user_password.rb ============================================================================== --- trunk/lib/active_ldap/user_password.rb (original) +++ trunk/lib/active_ldap/user_password.rb Tue Jun 17 06:25:17 2008 @@ -43,7 +43,7 @@ end def md5(password) - "{MD5}#{Base64.encode64(MD5.md5(password).digest).chomp}" + "{MD5}#{[MD5.md5(password).digest].pack('m').chomp}" end def smd5(password, salt=nil) @@ -52,7 +52,7 @@ end salt ||= Salt.generate(4) md5_hash_with_salt = "#{MD5.md5(password + salt).digest}#{salt}" - "{SMD5}#{Base64.encode64(md5_hash_with_salt).chomp}" + "{SMD5}#{[md5_hash_with_salt].pack('m').chomp}" end def extract_salt_for_smd5(smd5ed_password) @@ -60,7 +60,7 @@ end def sha(password) - "{SHA}#{Base64.encode64(SHA1.sha1(password).digest).chomp}" + "{SHA}#{[SHA1.sha1(password).digest].pack('m').chomp}" end def ssha(password, salt=nil) @@ -69,7 +69,7 @@ end salt ||= Salt.generate(4) sha1_hash_with_salt = "#{SHA1.sha1(password + salt).digest}#{salt}" - "{SSHA}#{Base64.encode64(sha1_hash_with_salt).chomp}" + "{SSHA}#{[sha1_hash_with_salt].pack('m').chomp}" end def extract_salt_for_ssha(sshaed_password) Modified: trunk/test/test_user_password.rb ============================================================================== --- trunk/test/test_user_password.rb (original) +++ trunk/test/test_user_password.rb Tue Jun 17 06:25:17 2008 @@ -45,18 +45,18 @@ password = "PASSWORD" hashed_password = ActiveLdap::UserPassword.smd5(password) - salt = Base64.decode64(hashed_password.sub(/^\{SMD5\}/, ''))[-4, 4] + salt = decode64(hashed_password.sub(/^\{SMD5\}/, ''))[-4, 4] assert_equal(hashed_password, ActiveLdap::UserPassword.smd5(password, salt)) end def test_extract_salt_for_smd5 - assert_extract_salt(:smd5, nil, Base64.encode64("").chomp) - assert_extract_salt(:smd5, nil, Base64.encode64("1").chomp) - assert_extract_salt(:smd5, nil, Base64.encode64("12").chomp) - assert_extract_salt(:smd5, nil, Base64.encode64("123").chomp) - assert_extract_salt(:smd5, "ABCD", Base64.encode64("ABCD").chomp) - assert_extract_salt(:smd5, "BCDE", Base64.encode64("ABCDE").chomp) + assert_extract_salt(:smd5, nil, encode64("")) + assert_extract_salt(:smd5, nil, encode64("1")) + assert_extract_salt(:smd5, nil, encode64("12")) + assert_extract_salt(:smd5, nil, encode64("123")) + assert_extract_salt(:smd5, "ABCD", encode64("ABCD")) + assert_extract_salt(:smd5, "BCDE", encode64("ABCDE")) end def test_sha @@ -70,18 +70,18 @@ password = "PASSWORD" hashed_password = ActiveLdap::UserPassword.ssha(password) - salt = Base64.decode64(hashed_password.sub(/^\{SSHA\}/, ''))[-4, 4] + salt = decode64(hashed_password.sub(/^\{SSHA\}/, ''))[-4, 4] assert_equal(hashed_password, ActiveLdap::UserPassword.ssha(password, salt)) end def test_extract_salt_for_ssha - assert_extract_salt(:ssha, nil, Base64.encode64("").chomp) - assert_extract_salt(:ssha, nil, Base64.encode64("1").chomp) - assert_extract_salt(:ssha, nil, Base64.encode64("12").chomp) - assert_extract_salt(:ssha, nil, Base64.encode64("123").chomp) - assert_extract_salt(:ssha, "ABCD", Base64.encode64("ABCD").chomp) - assert_extract_salt(:ssha, "BCDE", Base64.encode64("ABCDE").chomp) + assert_extract_salt(:ssha, nil, encode64("")) + assert_extract_salt(:ssha, nil, encode64("1")) + assert_extract_salt(:ssha, nil, encode64("12")) + assert_extract_salt(:ssha, nil, encode64("123")) + assert_extract_salt(:ssha, "ABCD", encode64("ABCD")) + assert_extract_salt(:ssha, "BCDE", encode64("ABCDE")) end private @@ -89,5 +89,13 @@ actual = ActiveLdap::UserPassword.send("extract_salt_for_#{type}", hashed_password) assert_equal(expected, actual) + end + + def encode64(string) + [string].pack('m').chomp + end + + def decode64(string) + string.unpack('m')[0] end end From codesite-noreply at google.com Wed Jun 18 00:58:34 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Tue, 17 Jun 2008 21:58:34 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r768 - trunk/lib Message-ID: <000e0cd2421c7fa2cf044fe9b65f@google.com> Author: koutou Date: Tue Jun 17 21:57:49 2008 New Revision: 768 Modified: trunk/lib/active_ldap.rb Log: * 1.0.1 -> 1.0.2. Modified: trunk/lib/active_ldap.rb ============================================================================== --- trunk/lib/active_ldap.rb (original) +++ trunk/lib/active_ldap.rb Tue Jun 17 21:57:49 2008 @@ -928,7 +928,7 @@ end module ActiveLdap - VERSION = "1.0.1" + VERSION = "1.0.2" end if RUBY_PLATFORM.match('linux') From codesite-noreply at google.com Wed Jun 18 01:02:35 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Tue, 17 Jun 2008 22:02:35 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r769 - in trunk: . lib/active_ldap test Message-ID: <000e0cd17ea8db6ac2044fe9c454@google.com> Author: koutou Date: Tue Jun 17 21:59:33 2008 New Revision: 769 Modified: trunk/README trunk/lib/active_ldap/operations.rb trunk/test/test_load.rb Log: * fix a bug that ModifyRecord#load doesn't operate atomic. [Issue 4] Reported by gwarf12. Thanks!!! Modified: trunk/README ============================================================================== --- trunk/README (original) +++ trunk/README Tue Jun 17 21:59:33 2008 @@ -109,3 +109,4 @@ * Tilo: A bug report. * Matt Mencel: A bug report. * CultureSpy: A bug report. +* gwarf12: A bug report. Modified: trunk/lib/active_ldap/operations.rb ============================================================================== --- trunk/lib/active_ldap/operations.rb (original) +++ trunk/lib/active_ldap/operations.rb Tue Jun 17 21:59:33 2008 @@ -383,10 +383,12 @@ module ModifyRecordLoadable def load(operator, options) - each do |operation| - operator.modify_entry(dn, operation.to_modify_entries, - {:controls => controls}.merge(options)) + modify_entries = operations.inject([]) do |result, operation| + result + operation.to_modify_entries end + return if modify_entries.empty? + operator.modify_entry(dn, modify_entries, + {:controls => controls}.merge(options)) end module AddOperationModifiable Modified: trunk/test/test_load.rb ============================================================================== --- trunk/test/test_load.rb (original) +++ trunk/test/test_load.rb Tue Jun 17 21:59:33 2008 @@ -16,6 +16,12 @@ record = ActiveLdap::LDIF::ModifyRecord.new(user.dn) ldif << record + original_home_directory = user.home_directory + new_home_directory = "#{original_home_directory}-new" + record.add_operation(:delete, "homeDirectory", [], {}) + record.add_operation(:add, "homeDirectory", [], + {"homeDirectory" => [new_home_directory]}) + original_descriptions = user.description(true) new_description = "new description" record.add_operation(:add, "description", [], @@ -30,6 +36,7 @@ ActiveLdap::Base.load(ldif.to_s) user = @user_class.find(user.dn) + assert_equal(new_home_directory, user.home_directory) assert_equal(original_descriptions + [new_description], user.description(true)) assert_nil(user.display_name) From codesite-noreply at google.com Wed Jun 18 20:19:54 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 18 Jun 2008 17:19:54 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r770 - in trunk: lib/active_ldap test Message-ID: <000e0cd14e7cb80d5c044ff9ef47@google.com> Author: koutou Date: Wed Jun 18 17:19:37 2008 New Revision: 770 Modified: trunk/lib/active_ldap/ldif.rb trunk/test/test_ldif.rb Log: * fix a bug that LDIF parser can't handle comment and separator composite block correctly. Modified: trunk/lib/active_ldap/ldif.rb ============================================================================== --- trunk/lib/active_ldap/ldif.rb (original) +++ trunk/lib/active_ldap/ldif.rb Wed Jun 18 17:19:37 2008 @@ -475,6 +475,7 @@ class Scanner SEPARATOR = /(?:\r\n|\n)/u + SEPARATORS = /(?:(?:^#.*)?#{SEPARATOR})+/u def initialize(source) @source = source @@ -506,13 +507,13 @@ end def scan_separators - return @scanner.scan(/#{SEPARATOR}+/u) if @sub_scanner.eos? + return @scanner.scan(SEPARATORS) if @sub_scanner.eos? - sub_result = scan(/#{SEPARATOR}+/u) + sub_result = scan(SEPARATORS) return nil if sub_result.nil? return sub_result unless @sub_scanner.eos? - result = @scanner.scan(/#{SEPARATOR}+/u) + result = @scanner.scan(SEPARATORS) return sub_result if result.nil? sub_result + result Modified: trunk/test/test_ldif.rb ============================================================================== --- trunk/test/test_ldif.rb (original) +++ trunk/test/test_ldif.rb Wed Jun 18 17:19:37 2008 @@ -9,6 +9,36 @@ include AlTestUtils::ExampleFile priority :must + def test_command_lines_and_empty_lines_before_content + ldif_source = <<-EOL +version: 1 + +# +# LDAPv3 +# base with scope subtree +# filter: (objectclass=*) +# requesting: ALL +# + +# devel.example.com +dn: dc=devel,dc=example,dc=com +dc: devel +objectClass: top +objectClass: dcObject +objectClass: organization +o: devel +EOL + + assert_ldif_to_s(<<-EOL, ldif_source) +version: 1 +dn: dc=devel,dc=example,dc=com +dc: devel +o: devel +objectClass: dcObject +objectClass: organization +objectClass: top +EOL + end priority :normal def test_unknown_change_type From codesite-noreply at google.com Wed Jun 18 20:28:13 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 18 Jun 2008 17:28:13 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r771 - in trunk: lib/active_ldap test Message-ID: <000e0cd212cc7e0331044ffa0d32@google.com> Author: koutou Date: Wed Jun 18 17:27:22 2008 New Revision: 771 Modified: trunk/lib/active_ldap/ldif.rb trunk/test/test_ldif.rb Log: * accept comment and empty lines after LDIF content. Modified: trunk/lib/active_ldap/ldif.rb ============================================================================== --- trunk/lib/active_ldap/ldif.rb (original) +++ trunk/lib/active_ldap/ldif.rb Wed Jun 18 17:27:22 2008 @@ -364,6 +364,8 @@ records << parse_record break if @scanner.eos? raise separator_is_missing if @scanner.scan_separator.nil? + + break if @scanner.scan_separators and @scanner.eos? end records end Modified: trunk/test/test_ldif.rb ============================================================================== --- trunk/test/test_ldif.rb (original) +++ trunk/test/test_ldif.rb Wed Jun 18 17:27:22 2008 @@ -9,7 +9,60 @@ include AlTestUtils::ExampleFile priority :must - def test_command_lines_and_empty_lines_before_content + def test_accept_empty_lines_after_content + ldif_source = <<-EOL +version: 1 +dn: dc=devel,dc=example,dc=com +dc: devel +objectClass: top +objectClass: dcObject +objectClass: organization +o: devel + + +EOL + + assert_ldif_to_s(<<-EOL, ldif_source) +version: 1 +dn: dc=devel,dc=example,dc=com +dc: devel +o: devel +objectClass: dcObject +objectClass: organization +objectClass: top +EOL + end + + def test_accept_comments_after_content + ldif_source = <<-EOL +version: 1 +dn: dc=devel,dc=example,dc=com +dc: devel +objectClass: top +objectClass: dcObject +objectClass: organization +o: devel + +# search result + +# numResponse: 1 +# numEntries: 1 + +EOL + + assert_ldif_to_s(<<-EOL, ldif_source) +version: 1 +dn: dc=devel,dc=example,dc=com +dc: devel +o: devel +objectClass: dcObject +objectClass: organization +objectClass: top +EOL + end + + priority :normal + def test_comments_and_empty_lines_before_content ldif_source = <<-EOL version: 1 @@ -40,7 +93,6 @@ EOL end - priority :normal def test_unknown_change_type ldif_source = <<-EOL version: 1 From codesite-noreply at google.com Wed Jun 18 20:32:13 2008 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 18 Jun 2008 17:32:13 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r772 - in trunk: lib/active_ldap test Message-ID: <000e0cd172eed1117f044ffa1bfb@google.com> Author: koutou Date: Wed Jun 18 17:30:05 2008 New Revision: 772 Modified: trunk/lib/active_ldap/ldif.rb trunk/test/test_ldif.rb Log: * follow up the previous commit. Modified: trunk/lib/active_ldap/ldif.rb ============================================================================== --- trunk/lib/active_ldap/ldif.rb (original) +++ trunk/lib/active_ldap/ldif.rb Wed Jun 18 17:30:05 2008 @@ -365,6 +365,7 @@ break if @scanner.eos? raise separator_is_missing if @scanner.scan_separator.nil? + break if @scanner.eos? break if @scanner.scan_separators and @scanner.eos? end records Modified: trunk/test/test_ldif.rb ============================================================================== --- trunk/test/test_ldif.rb (original) +++ trunk/test/test_ldif.rb Wed Jun 18 17:30:05 2008 @@ -18,11 +18,9 @@ objectClass: dcObject objectClass: organization o: devel - - EOL - assert_ldif_to_s(<<-EOL, ldif_source) + expected_ldif_to_s = <<-EOL version: 1 dn: dc=devel,dc=example,dc=com dc: devel @@ -31,6 +29,12 @@ objectClass: organization objectClass: top EOL + + + assert_ldif_to_s(expected_ldif_to_s, ldif_source) + assert_ldif_to_s(expected_ldif_to_s, ldif_source + "\n") + assert_ldif_to_s(expected_ldif_to_s, ldif_source + "\n\n") + assert_ldif_to_s(expected_ldif_to_s, ldif_source + ("\n" * 10)) end def test_accept_comments_after_content