+ Adding String#read_ber! back in, since our test server uses it.
This commit is contained in:
parent
c913bc6fb9
commit
ddb15caace
|
@ -1,4 +1,5 @@
|
|||
=== 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
|
||||
OpenSSL successfully or not.
|
||||
* Moved the core class extensions extensions from being in the Net::LDAP
|
||||
|
|
1
Rakefile
1
Rakefile
|
@ -36,6 +36,7 @@ Hoe.spec PKG_NAME do
|
|||
extra_dev_deps << [ "archive-tar-minitar", "~>0.5.1" ]
|
||||
extra_dev_deps << [ "hanna", "~>0.1.2" ]
|
||||
extra_dev_deps << [ "hoe-git", "~>1" ]
|
||||
extra_dev_deps << [ "metaid", "~>1" ]
|
||||
clean_globs << "coverage"
|
||||
|
||||
spec_extras[:required_ruby_version] = ">= #{MINRUBY}"
|
||||
|
|
|
@ -32,20 +32,15 @@ module Net::BER::Extensions::String
|
|||
StringIO.new(self).read_ber(syntax)
|
||||
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.
|
||||
def read_ber!(syntax = nil)
|
||||
obj, consumed = read_ber_from_string(self, syntax)
|
||||
if consumed
|
||||
self.slice!(0...consumed)
|
||||
obj
|
||||
else
|
||||
nil
|
||||
# Destructively reads a BER object from the string.
|
||||
#
|
||||
def read_ber!(syntax=nil)
|
||||
io = StringIO.new(self)
|
||||
|
||||
result = io.read_ber(syntax)
|
||||
self.slice!(0...io.pos)
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
=end
|
||||
end
|
||||
|
|
52
spec/unit/ber/core_ext/string_spec.rb
Normal file
52
spec/unit/ber/core_ext/string_spec.rb
Normal 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
|
Loading…
Reference in a new issue