Add success and failure methods.

This commit is contained in:
Michael Baker 2011-11-30 20:03:02 +00:00
parent 2763040162
commit 40f0e1857e
2 changed files with 16 additions and 8 deletions

View file

@ -128,6 +128,14 @@ class Net::LDAP::PDU
result_code == 0 ? :success : :failure result_code == 0 ? :success : :failure
end end
def success?
status == :success
end
def failure?
!success?
end
## ##
# Return serverSaslCreds, which are only present in BindResponse packets. # Return serverSaslCreds, which are only present in BindResponse packets.
#-- #--

View file

@ -7,11 +7,11 @@ describe Net::LDAP::Connection do
flexmock(TCPSocket). flexmock(TCPSocket).
should_receive(:new).and_raise(Errno::ECONNREFUSED) should_receive(:new).and_raise(Errno::ECONNREFUSED)
end end
it "should raise LdapError" do it "should raise LdapError" do
lambda { lambda {
Net::LDAP::Connection.new( Net::LDAP::Connection.new(
:server => 'test.mocked.com', :server => 'test.mocked.com',
:port => 636) :port => 636)
}.should raise_error(Net::LDAP::LdapError) }.should raise_error(Net::LDAP::LdapError)
end end
@ -21,11 +21,11 @@ describe Net::LDAP::Connection do
flexmock(TCPSocket). flexmock(TCPSocket).
should_receive(:new).and_raise(SocketError) should_receive(:new).and_raise(SocketError)
end end
it "should raise LdapError" do it "should raise LdapError" do
lambda { lambda {
Net::LDAP::Connection.new( Net::LDAP::Connection.new(
:server => 'test.mocked.com', :server => 'test.mocked.com',
:port => 636) :port => 636)
}.should raise_error(Net::LDAP::LdapError) }.should raise_error(Net::LDAP::LdapError)
end end
@ -35,11 +35,11 @@ describe Net::LDAP::Connection do
flexmock(TCPSocket). flexmock(TCPSocket).
should_receive(:new).and_raise(NameError) should_receive(:new).and_raise(NameError)
end end
it "should rethrow the exception" do it "should rethrow the exception" do
lambda { lambda {
Net::LDAP::Connection.new( Net::LDAP::Connection.new(
:server => 'test.mocked.com', :server => 'test.mocked.com',
:port => 636) :port => 636)
}.should raise_error(NameError) }.should raise_error(NameError)
end end
@ -61,7 +61,7 @@ describe Net::LDAP::Connection do
@tcp_socket.should_receive(:read_ber).and_return([2, ber]) @tcp_socket.should_receive(:read_ber).and_return([2, ber])
result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]]) result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]])
result.status.should == :failure result.should be_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" 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 end
@ -71,7 +71,7 @@ describe Net::LDAP::Connection do
@tcp_socket.should_receive(:read_ber).and_return([2, ber]) @tcp_socket.should_receive(:read_ber).and_return([2, ber])
result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]]) result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]])
result.status.should == :success result.should be_success
result.error_message.should == "" result.error_message.should == ""
end end
end end