Gentoo Archives: gentoo-commits

From: "Manuel Rueger (mrueg)" <mrueg@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in dev-ruby/ruby-net-ldap/files: ruby-net-ldap-0.6.1-fix-test.patch
Date: Fri, 25 Jul 2014 14:57:27
Message-Id: 20140725145723.5506D2004F@flycatcher.gentoo.org
1 mrueg 14/07/25 14:57:23
2
3 Added: ruby-net-ldap-0.6.1-fix-test.patch
4 Log:
5 Add support for ruby20, ruby21.
6
7 (Portage version: 2.2.10/cvs/Linux x86_64, signed Manifest commit with key )
8
9 Revision Changes Path
10 1.1 dev-ruby/ruby-net-ldap/files/ruby-net-ldap-0.6.1-fix-test.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/ruby-net-ldap/files/ruby-net-ldap-0.6.1-fix-test.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-ruby/ruby-net-ldap/files/ruby-net-ldap-0.6.1-fix-test.patch?rev=1.1&content-type=text/plain
14
15 Index: ruby-net-ldap-0.6.1-fix-test.patch
16 ===================================================================
17 From 0c439a94a2e67136f43a16fba34695120997b49e Mon Sep 17 00:00:00 2001
18 From: Shaun Mangelsdorf <s.mangelsdorf@×××××.com>
19 Date: Fri, 4 Apr 2014 16:56:40 +1000
20 Subject: [PATCH] Add raw_string helper in tests, to repair encoding issues
21
22 Strings with raw byte sequences misbehave in Ruby 2.0+ because the
23 default encoding for string literals is now UTF-8. The String#b method
24 resolves this, and was not previously available.
25 ---
26 spec/spec_helper.rb | 5 +++++
27 spec/unit/ber/ber_spec.rb | 42 +++++++++++++++++------------------
28 spec/unit/ber/core_ext/string_spec.rb | 4 ++--
29 spec/unit/ldap/filter_spec.rb | 4 ++--
30 test/test_snmp.rb | 11 ++++++---
31 5 files changed, 38 insertions(+), 28 deletions(-)
32
33 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
34 index 5079537..a585398 100644
35 --- a/spec/spec_helper.rb
36 +++ b/spec/spec_helper.rb
37 @@ -2,4 +2,9 @@
38
39 RSpec.configure do |config|
40 config.mock_with :flexmock
41 +
42 + def raw_string(s)
43 + # Conveniently, String#b only needs to be called when it exists
44 + s.respond_to?(:b) ? s.b : s
45 + end
46 end
47 diff --git a/spec/unit/ber/ber_spec.rb b/spec/unit/ber/ber_spec.rb
48 index 48e161a..9806cc8 100644
49 --- a/spec/unit/ber/ber_spec.rb
50 +++ b/spec/unit/ber/ber_spec.rb
51 @@ -33,28 +33,28 @@
52 context "numbers" do
53 # Sample based
54 {
55 - 0 => "\x02\x01\x00",
56 - 1 => "\x02\x01\x01",
57 - 127 => "\x02\x01\x7F",
58 - 128 => "\x02\x01\x80",
59 - 255 => "\x02\x01\xFF",
60 - 256 => "\x02\x02\x01\x00",
61 - 65535 => "\x02\x02\xFF\xFF",
62 - 65536 => "\x02\x03\x01\x00\x00",
63 - 16_777_215 => "\x02\x03\xFF\xFF\xFF",
64 - 0x01000000 => "\x02\x04\x01\x00\x00\x00",
65 - 0x3FFFFFFF => "\x02\x04\x3F\xFF\xFF\xFF",
66 - 0x4FFFFFFF => "\x02\x04\x4F\xFF\xFF\xFF",
67 -
68 + 0 => raw_string("\x02\x01\x00"),
69 + 1 => raw_string("\x02\x01\x01"),
70 + 127 => raw_string("\x02\x01\x7F"),
71 + 128 => raw_string("\x02\x01\x80"),
72 + 255 => raw_string("\x02\x01\xFF"),
73 + 256 => raw_string("\x02\x02\x01\x00"),
74 + 65535 => raw_string("\x02\x02\xFF\xFF"),
75 + 65536 => raw_string("\x02\x03\x01\x00\x00"),
76 + 16_777_215 => raw_string("\x02\x03\xFF\xFF\xFF"),
77 + 0x01000000 => raw_string("\x02\x04\x01\x00\x00\x00"),
78 + 0x3FFFFFFF => raw_string("\x02\x04\x3F\xFF\xFF\xFF"),
79 + 0x4FFFFFFF => raw_string("\x02\x04\x4F\xFF\xFF\xFF"),
80 +
81 # Some odd samples...
82 - 5 => "\002\001\005",
83 - 500 => "\002\002\001\364",
84 - 50_000 => "\x02\x02\xC3P",
85 - 5_000_000_000 => "\002\005\001*\005\362\000"
86 - }.each do |number, expected_encoding|
87 + 5 => raw_string("\002\001\005"),
88 + 500 => raw_string("\002\002\001\364"),
89 + 50_000 => raw_string("\x02\x02\xC3P"),
90 + 5_000_000_000 => raw_string("\002\005\001*\005\362\000")
91 + }.each do |number, expected_encoding|
92 it "should encode #{number} as #{expected_encoding.inspect}" do
93 number.to_ber.should == expected_encoding
94 - end
95 + end
96 end
97
98 # Round-trip encoding: This is mostly to be sure to cover Bignums well.
99 @@ -79,7 +79,7 @@
100 context "strings" do
101 it "should properly encode UTF-8 strings" do
102 "\u00e5".force_encoding("UTF-8").to_ber.should ==
103 - "\x04\x02\xC3\xA5"
104 + raw_string("\x04\x02\xC3\xA5")
105 end
106 it "should properly encode strings encodable as UTF-8" do
107 "teststring".encode("US-ASCII").to_ber.should == "\x04\nteststring"
108 @@ -87,7 +87,7 @@
109 it "should properly encode binary data strings using to_ber_bin" do
110 # This is used for searching for GUIDs in Active Directory
111 ["6a31b4a12aa27a41aca9603f27dd5116"].pack("H*").to_ber_bin.should ==
112 - "\x04\x10" + "j1\xB4\xA1*\xA2zA\xAC\xA9`?'\xDDQ\x16"
113 + raw_string("\x04\x10" + "j1\xB4\xA1*\xA2zA\xAC\xA9`?'\xDDQ\x16")
114 end
115 it "should not fail on strings that can not be converted to UTF-8" do
116 error = Encoding::UndefinedConversionError
117 diff --git a/spec/unit/ber/core_ext/string_spec.rb b/spec/unit/ber/core_ext/string_spec.rb
118 index 6eebe05..ef2c498 100644
119 --- a/spec/unit/ber/core_ext/string_spec.rb
120 +++ b/spec/unit/ber/core_ext/string_spec.rb
121 @@ -6,7 +6,7 @@
122 context "when passed an ldap bind request and some extra data" do
123 attr_reader :str, :result
124 before(:each) do
125 - @str = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus UNCONSUMED"
126 + @str = raw_string("0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus UNCONSUMED")
127 @result = str.read_ber!(Net::LDAP::AsnSyntax)
128 end
129
130 @@ -22,7 +22,7 @@
131 before(:each) do
132 stub_exception_class = Class.new(StandardError)
133
134 - @initial_value = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus"
135 + @initial_value = raw_string("0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus")
136 @str = initial_value.dup
137
138 # Defines a string
139 diff --git a/spec/unit/ldap/filter_spec.rb b/spec/unit/ldap/filter_spec.rb
140 index 5e4cb8a..06fd3b8 100644
141 --- a/spec/unit/ldap/filter_spec.rb
142 +++ b/spec/unit/ldap/filter_spec.rb
143 @@ -83,12 +83,12 @@ def eq(attribute, value)
144 end
145
146 context 'with a well-known BER string' do
147 - ber = "\xa4\x2d" \
148 + ber = raw_string("\xa4\x2d" \
149 "\x04\x0b" "objectclass" \
150 "\x30\x1e" \
151 "\x80\x08" "foo" "*\\" "bar" \
152 "\x81\x08" "foo" "*\\" "bar" \
153 - "\x82\x08" "foo" "*\\" "bar"
154 + "\x82\x08" "foo" "*\\" "bar")
155
156 describe "<- .to_ber" do
157 [
158 diff --git a/test/test_snmp.rb b/test/test_snmp.rb
159 index 88a619d..065025e 100644
160 --- a/test/test_snmp.rb
161 +++ b/test/test_snmp.rb
162 @@ -4,10 +4,15 @@
163 require 'net/snmp'
164
165 class TestSnmp < Test::Unit::TestCase
166 - SnmpGetRequest = "0'\002\001\000\004\006public\240\032\002\002?*\002\001\000\002\001\0000\0160\f\006\b+\006\001\002\001\001\001\000\005\000"
167 - SnmpGetResponse = "0+\002\001\000\004\006public\242\036\002\002'\017\002\001\000\002\001\0000\0220\020\006\b+\006\001\002\001\001\001\000\004\004test"
168 + def self.raw_string(s)
169 + # Conveniently, String#b only needs to be called when it exists
170 + s.respond_to?(:b) ? s.b : s
171 + end
172 +
173 + SnmpGetRequest = raw_string("0'\002\001\000\004\006public\240\032\002\002?*\002\001\000\002\001\0000\0160\f\006\b+\006\001\002\001\001\001\000\005\000")
174 + SnmpGetResponse = raw_string("0+\002\001\000\004\006public\242\036\002\002'\017\002\001\000\002\001\0000\0220\020\006\b+\006\001\002\001\001\001\000\004\004test")
175
176 - SnmpGetRequestXXX = "0'\002\001\000\004\006xxxxxx\240\032\002\002?*\002\001\000\002\001\0000\0160\f\006\b+\006\001\002\001\001\001\000\005\000"
177 + SnmpGetRequestXXX = raw_string("0'\002\001\000\004\006xxxxxx\240\032\002\002?*\002\001\000\002\001\0000\0160\f\006\b+\006\001\002\001\001\001\000\005\000")
178
179 def test_invalid_packet
180 data = "xxxx"
181 --
182 1.9.3