Skip to content

Commit ddb15ca

Browse files
committed
+ Adding String#read_ber! back in, since our test server uses it.
1 parent c913bc6 commit ddb15ca

File tree

4 files changed

+64
-15
lines changed

4 files changed

+64
-15
lines changed

History.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
=== Net::LDAP NEXT / 2010-__-__
2+
* String#read_ber! destructive read_ber added back in.
23
* SSL capabilities will be enabled or disabled based on whether we can load
34
OpenSSL successfully or not.
45
* Moved the core class extensions extensions from being in the Net::LDAP

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Hoe.spec PKG_NAME do
3636
extra_dev_deps << [ "archive-tar-minitar", "~>0.5.1" ]
3737
extra_dev_deps << [ "hanna", "~>0.1.2" ]
3838
extra_dev_deps << [ "hoe-git", "~>1" ]
39+
extra_dev_deps << [ "metaid", "~>1" ]
3940
clean_globs << "coverage"
4041

4142
spec_extras[:required_ruby_version] = ">= #{MINRUBY}"

lib/net/ber/core_ext/string.rb

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,16 @@ def to_ber_contextspecific(code)
3131
def read_ber(syntax = nil)
3232
StringIO.new(self).read_ber(syntax)
3333
end
34-
35-
=begin
36-
# 20100319 AZ I've kept this here because I'm not yet sure if it's
37-
# necessary.
38-
34+
3935
##
40-
# Destructively reads a BER object from this string.
41-
def read_ber!(syntax = nil)
42-
obj, consumed = read_ber_from_string(self, syntax)
43-
if consumed
44-
self.slice!(0...consumed)
45-
obj
46-
else
47-
nil
48-
end
36+
# Destructively reads a BER object from the string.
37+
#
38+
def read_ber!(syntax=nil)
39+
io = StringIO.new(self)
40+
41+
result = io.read_ber(syntax)
42+
self.slice!(0...io.pos)
43+
44+
return result
4945
end
50-
=end
5146
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require 'spec_helper'
2+
3+
require 'metaid'
4+
5+
describe String, "when extended with BER core extensions" do
6+
describe "<- #read_ber! (consuming read_ber method)" do
7+
context "when passed an ldap bind request and some extra data" do
8+
attr_reader :str, :result
9+
before(:each) do
10+
@str = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus UNCONSUMED"
11+
@result = str.read_ber!(Net::LDAP::AsnSyntax)
12+
end
13+
14+
it "should correctly parse the ber message" do
15+
result.should == [1, [3, "Administrator", "ad_is_bogus"]]
16+
end
17+
it "should leave unconsumed part of message in place" do
18+
str.should == " UNCONSUMED"
19+
end
20+
21+
context "if an exception occurs during #read_ber" do
22+
attr_reader :initial_value
23+
before(:each) do
24+
stub_exception_class = Class.new(StandardError)
25+
26+
@initial_value = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus"
27+
@str = initial_value.dup
28+
29+
# Defines a string
30+
io = StringIO.new(initial_value)
31+
io.meta_def :read_ber do |syntax|
32+
read
33+
raise stub_exception_class
34+
end
35+
flexmock(StringIO).should_receive(:new).and_return(io)
36+
37+
begin
38+
str.read_ber!(Net::LDAP::AsnSyntax)
39+
rescue stub_exception_class
40+
# EMPTY ON PURPOSE
41+
else
42+
raise "The stub code should raise an exception!"
43+
end
44+
end
45+
46+
it "should not modify string" do
47+
str.should == initial_value
48+
end
49+
end
50+
end
51+
end
52+
end

0 commit comments

Comments
 (0)