Return PDU instead of result code

This commit is contained in:
Michael Baker 2011-11-29 22:01:34 +00:00
parent 63db8c836a
commit 2763040162
4 changed files with 74 additions and 30 deletions

View file

@ -3,8 +3,7 @@
describe Net::LDAP, "search method" do
class FakeConnection
def search(args)
error_code = 1
return error_code
OpenStruct.new(:result_code => 1, :message => "error")
end
end
@ -22,8 +21,8 @@ describe Net::LDAP, "search method" do
context "when :return_result => false" do
it "should return false upon error" do
success = @connection.search(:return_result => false)
success.should == false
result = @connection.search(:return_result => false)
result.result_code.should == 1
end
end

View file

@ -45,4 +45,34 @@ describe Net::LDAP::Connection do
end
end
end
end
context "populate error messages" do
before do
@tcp_socket = flexmock(:connection)
@tcp_socket.should_receive(:write)
flexmock(TCPSocket).should_receive(:new).and_return(@tcp_socket)
end
subject { Net::LDAP::Connection.new(:server => 'test.mocked.com', :port => 636) }
it "should get back error messages if operation fails" do
ber = Net::BER::BerIdentifiedArray.new([53, "", "The provided password value was rejected by a password validator: The provided password did not contain enough characters from the character set 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. The minimum number of characters from that set that must be present in user passwords is 1"])
ber.ber_identifier = 7
@tcp_socket.should_receive(:read_ber).and_return([2, ber])
result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]])
result.status.should == :failure
result.error_message.should == "The provided password value was rejected by a password validator: The provided password did not contain enough characters from the character set 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. The minimum number of characters from that set that must be present in user passwords is 1"
end
it "shouldn't get back error messages if operation succeeds" do
ber = Net::BER::BerIdentifiedArray.new([0, "", ""])
ber.ber_identifier = 7
@tcp_socket.should_receive(:read_ber).and_return([2, ber])
result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]])
result.status.should == :success
result.error_message.should == ""
end
end
end