From a6310a0a4f746d2502a9b90948177688c30ce852 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Mon, 8 Feb 2010 13:48:18 -0500 Subject: [PATCH] not logging binary data RUBY-90 --- lib/mongo/types/binary.rb | 4 ++++ test/test_binary.rb | 17 +++++++++++++++++ test/unit/collection_test.rb | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 test/test_binary.rb diff --git a/lib/mongo/types/binary.rb b/lib/mongo/types/binary.rb index 9d4577c..a6ad170 100644 --- a/lib/mongo/types/binary.rb +++ b/lib/mongo/types/binary.rb @@ -44,5 +44,9 @@ module Mongo @subtype = subtype end + def inspect + "" + end + end end diff --git a/test/test_binary.rb b/test/test_binary.rb new file mode 100644 index 0000000..b4f6327 --- /dev/null +++ b/test/test_binary.rb @@ -0,0 +1,17 @@ +# encoding:utf-8 + +require 'test/test_helper' + +class BinaryTest < Test::Unit::TestCase + + context "Inspecting" do + setup do + @data = ("THIS IS BINARY " * 50).unpack("c*") + end + + should "not display actual data" do + binary = Mongo::Binary.new(@data) + assert_equal "", binary.inspect + end + end +end diff --git a/test/unit/collection_test.rb b/test/unit/collection_test.rb index 98fcdc9..ffdb5b3 100644 --- a/test/unit/collection_test.rb +++ b/test/unit/collection_test.rb @@ -27,6 +27,17 @@ class ConnectionTest < Test::Unit::TestCase @coll.insert({:title => 'Moby Dick'}) end + should "not log binary data" do + @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false) + @db = @conn['testing'] + @coll = @db.collection('books') + data = Mongo::Binary.new(("BINARY " * 1000).unpack("c*")) + @conn.expects(:send_message).with do |op, msg, log| + op == 2002 && log.include?("Mongo::Binary") + end + @coll.insert({:data => data}) + end + should "send safe update message" do @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false) @db = @conn['testing']