使用 Visual Studio Team Services (VSTS) 运行带有 SSL 错误的 Web/负载测试

Posted

技术标签:

【中文标题】使用 Visual Studio Team Services (VSTS) 运行带有 SSL 错误的 Web/负载测试【英文标题】:Using Visual Studio Team Services (VSTS) to run web/load testing with SSL error 【发布时间】:2017-12-14 21:33:36 【问题描述】:

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

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

Screen cap of errors

这是如何解决的?我是 VSTS 的新手。

【问题讨论】:

【参考方案1】:

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

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

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

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。

【讨论】:

如果您的负载/网络测试被记录,我需要从头开始吗?我没有看到任何代码文件。 @cdub 是 webtest 插件,所以你需要创建一个插件并使用它来进行 web 测试。 msdn.microsoft.com/en-us/library/… 之后我只运行它吗?我想我也需要学习如何把它放到云端。 我按照你上面的链接,但运行测试仍然产生了这个screencast.com/t/AZUWTf0BSNvM 确保您遵循@starianchen-MSFT 提供的链接中的所有说明。缺少其中任何一个都可能意味着插件无法使用。

以上是关于使用 Visual Studio Team Services (VSTS) 运行带有 SSL 错误的 Web/负载测试的主要内容,如果未能解决你的问题,请参考以下文章

Visual Studio Express 2012 无法添加到 Visual Studio Team Services 的连接

Visual Studio Team System 的最佳功能是啥?

无法使用 Git Bash 对 Visual Studio Team Services 进行身份验证

Azure 和 Visual Studio Team Services 有啥关系

Visual Studio Online 上的远程分支不会出现在 Visual Studio 2015 Team Explorer 上

在 Visual Studio Team Services(之前是 Visual Studio Online)上运行负载测试时出现通信错误