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

标签 c# visual-studio azure-devops load-testing webtest

我有一个承包商创建了测试并将其上传到 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 .

关于c# - 使用 Visual Studio Team Services (VSTS) 运行带有 SSL 错误的 Web/负载测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47822386/

相关文章:

c# - 为什么我不能在 Windows 窗体设计 View 中更改 TextBox 控件的高度?

c# - 什么是 C# 检查的 C++ 等价物

visual-studio - 在 Visual Studio 中从 github 下载项目

npm - 如何在Azure DevOps中自动对npm包进行版本控制(不触发新管道)?

Azure DevOps 我无法获得 1800 分钟的 MS 托管

c# - 我应该返回 IEnumerable 还是 IList?

c# - 控制台应用程序/服务需要 40 秒才能启动

visual-studio - Visual Studio Code - 下载扩展文件

c# - 使用 Azure Function V3,如何将现有的 Ilogger 注入(inject)到新的类文件中?

azure-devops - 在 Azure DevOps 中,有什么方法可以创建指向最新构建工件的永久链接吗?