使用 Visual Studio Team Services (VSTS) 运行 web/load 进行 SSL 错误测试

Using Visual Studio Team Services (VSTS) to run web/load testing with SSL error

我有一个承包商创建了测试并将其上传到 VSTS,但现在当我们 运行 他们时,我们得到:

The request was aborted. Could not create SSL/TLS secure channel.

Screen cap of errors

这是怎么解决的?我是 VSTS 新手。

您的证书有效吗?此错误通常来自无效证书或开发证书,或者来自提供与客户端期望版本不同的 TLS 版本的证书。

根据 this answer on Software QA,您通常可以通过修改包含在代码中的预测试处理程序插件中的 ServicePointManager 来解决此问题。

请阅读此示例中的评论 the MSDN forums - 您应该修改回调函数以对证书执行一些验证以确保它是您期望的环境。

using System;
using System.ComponentModel;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using Microsoft.VisualStudio.TestTools.WebTesting;


namespace ExperimentalTesting
{
  [Description("This plugin will force the underlying System.Net ServicePointManager to negotiate downlevel SSLv3 instead of TLS. WARNING: The servers X509 Certificate will be ignored as part of this process, so verify that you are testing the correct system.")]
  public class SSLv3ForcedPlugin : WebTestPlugin
  {
    [Description("Enable or Disable the plugin functionality")]
    [DefaultValue(true)]
    public bool Enabled {get;set;}

    public override void PreWebTest(object sender, PreWebTestEventArgs e)
    {
      base.PreWebTest(sender, e);

      // We're using SSL3 here and not TLS. Update as required.
      // Without this line, nothing works.
      ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

      // Wire up the callback so we can override behaviour and force it to
      // accept the certificate
      ServicePointManager.ServerCertificateValidationCallback = 
                                             RemoteCertificateValidationCB;

      // Log the changes to the service point manager
      e.WebTest.AddCommentToResult(this.ToString() + " has made the following modification-> ServicePointManager.SecurityProtocol set to use SSLv3 in WebTest Plugin.");
    }

    public static bool RemoteCertificateValidationCB(Object sender, 
                                                     X509Certificate certificate,
                                                     X509Chain chain,
                                                     SslPolicyErrors sslPolicyErrors)
    {
      // Validate the certificate issuer here 
      // (at least check the O, L, C values, better yet the signature).
      // Returning true will accept any certificate
      return true;
    }
  }
}

然后需要根据 MSDN documentation on creating Web Test Plugins.

将其添加到您的 Web 测试中

您将需要遵循类似的过程来创建负载测试插件(而不是继承自 `Microsoft.VisualStudio.TestTools.LoadTesting.ILoadTestPlugin)并遵循 MSDN documentation on creating Load Test Plugins.