+ Adding String#read_ber! back in, since our test server uses it.

This commit is contained in:
Kaspar Schiess 2010-03-20 14:18:15 +01:00
parent c913bc6fb9
commit ddb15caace
4 changed files with 64 additions and 15 deletions

View file

@ -1,4 +1,5 @@
=== Net::LDAP NEXT / 2010-__-__ === Net::LDAP NEXT / 2010-__-__
* String#read_ber! destructive read_ber added back in.
* SSL capabilities will be enabled or disabled based on whether we can load * SSL capabilities will be enabled or disabled based on whether we can load
OpenSSL successfully or not. OpenSSL successfully or not.
* Moved the core class extensions extensions from being in the Net::LDAP * Moved the core class extensions extensions from being in the Net::LDAP

View file

@ -36,6 +36,7 @@ Hoe.spec PKG_NAME do
extra_dev_deps << [ "archive-tar-minitar", "~>0.5.1" ] extra_dev_deps << [ "archive-tar-minitar", "~>0.5.1" ]
extra_dev_deps << [ "hanna", "~>0.1.2" ] extra_dev_deps << [ "hanna", "~>0.1.2" ]
extra_dev_deps << [ "hoe-git", "~>1" ] extra_dev_deps << [ "hoe-git", "~>1" ]
extra_dev_deps << [ "metaid", "~>1" ]
clean_globs << "coverage" clean_globs << "coverage"
spec_extras[:required_ruby_version] = ">= #{MINRUBY}" spec_extras[:required_ruby_version] = ">= #{MINRUBY}"

View file

@ -32,20 +32,15 @@ module Net::BER::Extensions::String
StringIO.new(self).read_ber(syntax) StringIO.new(self).read_ber(syntax)
end end
=begin
# 20100319 AZ I've kept this here because I'm not yet sure if it's
# necessary.
## ##
# Destructively reads a BER object from this string. # Destructively reads a BER object from the string.
def read_ber!(syntax = nil) #
obj, consumed = read_ber_from_string(self, syntax) def read_ber!(syntax=nil)
if consumed io = StringIO.new(self)
self.slice!(0...consumed)
obj result = io.read_ber(syntax)
else self.slice!(0...io.pos)
nil
return result
end end
end
=end
end end

View file

@ -0,0 +1,52 @@
require 'spec_helper'
require 'metaid'
describe String, "when extended with BER core extensions" do
describe "<- #read_ber! (consuming read_ber method)" do
context "when passed an ldap bind request and some extra data" do
attr_reader :str, :result
before(:each) do
@str = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus UNCONSUMED"
@result = str.read_ber!(Net::LDAP::AsnSyntax)
end
it "should correctly parse the ber message" do
result.should == [1, [3, "Administrator", "ad_is_bogus"]]
end
it "should leave unconsumed part of message in place" do
str.should == " UNCONSUMED"
end
context "if an exception occurs during #read_ber" do
attr_reader :initial_value
before(:each) do
stub_exception_class = Class.new(StandardError)
@initial_value = "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus"
@str = initial_value.dup
# Defines a string
io = StringIO.new(initial_value)
io.meta_def :read_ber do |syntax|
read
raise stub_exception_class
end
flexmock(StringIO).should_receive(:new).and_return(io)
begin
str.read_ber!(Net::LDAP::AsnSyntax)
rescue stub_exception_class
# EMPTY ON PURPOSE
else
raise "The stub code should raise an exception!"
end
end
it "should not modify string" do
str.should == initial_value
end
end
end
end
end