views:

310

answers:

1

I am trying to fix a bug with SSL in a product and noticed that although the code sets SSL to be true, in the next line in the code SSL is still at false. I wrote a unit test for this and the unit test confirms my suspicions.

  [TestMethod]
  public void SecureSocketLayerSetToTrue( )
  {
     var ldapConnection = new LdapConnection( 
                                new LdapDirectoryIdentifier( "ldap.test.com", 636 ));
     ldapConnection.SessionOptions.SecureSocketLayer = true;
     Assert.IsTrue( ldapConnection.SessionOptions.SecureSocketLayer );
  }

The test fails. Is there something here that I am missing?

+3  A: 

It turns out that the way that the DirectoryServices.Protocols implements it's LDAP calls is by passing them through to a low-level LDAP API. This LDAP API is what is queried when a get is done on the property.

The low-level API is only updated when the methods are executed. You can think about this like it is building command-line arguments for an executable that hasn't been launched yet.

When a call like Bind() is made, then the executable is launched and the properties will report the correct value.

So, just because the property was saying that the value was false, it was using the true when necessary.

Jared