无法使用 DirectoryServices.Protocols.LdapConnection 打开 SecureSocketLayer

发布于 2024-07-08 19:57:38 字数 489 浏览 15 评论 0原文

我正在尝试修复产品中的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三寸金莲 2024-07-15 19:57:39

事实证明,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文