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

后端 未结 1 900
花落未央
花落未央 2020-12-12 01:01

I have a contractor who created and uploaded test to VSTS but now when we run them we get:

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


        
相关标签:
1条回答
  • 2020-12-12 01:52

    Is your certificate valid? This error most often comes from an invalid or development certificate, or from a certificate supplying a different TLS version to the one the client is expecting.

    According to this answer on Software QA, you can usually work around this by modifying the ServicePointManager in a pre-test handler plugin that you include with your code.

    Please read the comments in this example from the MSDN forums - you should modify the call-back function to perform some validation on the certificate to ensure it is the environment you are expecting.

    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;
        }
      }
    }
    

    This will then need to be added to your Web Test as per the MSDN documentation on creating Web Test Plugins.

    You will need to follow a similar process to create a Load Test plug-in (inheriting instead from `Microsoft.VisualStudio.TestTools.LoadTesting.ILoadTestPlugin) and follow the MSDN documentation on creating Load Test Plugins.

    0 讨论(0)
提交回复
热议问题