无法使用 DirectoryServices.Protocols.LdapConnection 打开 SecureSocketLayer
我正在尝试修复产品中的 SSL 错误,并注意到虽然代码将 SSL 设置为 true,但在代码的下一行中 SSL 仍然为 false。 我为此编写了一个单元测试,单元测试证实了我的怀疑。
[TestMethod]
public void SecureSocketLayerSetToTrue( )
{
var ldapConnection = new LdapConnection(
new LdapDirectoryIdentifier( "ldap.test.com", 636 ));
ldapConnection.SessionOptions.SecureSocketLayer = true;
Assert.IsTrue( ldapConnection.SessionOptions.SecureSocketLayer );
}
测试失败。 这里有我缺少的东西吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,DirectoryServices.Protocols 实现 LDAP 调用的方式是将它们传递到低级 LDAP API。 当对属性执行 get 操作时,将查询此 LDAP API。
低级 API 仅在执行方法时更新。 您可以将其视为正在为尚未启动的可执行文件构建命令行参数。
当进行像 Bind() 这样的调用时,可执行文件将启动并且属性将报告正确的值。
因此,仅仅因为属性说该值是 false,它就会在必要时使用 true。
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.