Commit 2171274d 2171274d557413c8825c1e9730e07c685dca82c3 by Christian Gerdes

Support for Unsafe Header Parsing in ServiceManagerWebTestPlugin

1 parent a80b5e4b
......@@ -22,6 +22,9 @@ using System.Text.RegularExpressions;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
using System.Collections.Specialized;
using System.Configuration;
using System.Net.Configuration;
using System.Reflection;
namespace LIL_VSTT_Plugins
{
......@@ -952,6 +955,8 @@ namespace LIL_VSTT_Plugins
[Description("(C) Copyright 2015 LIGHTS IN LINE AB\r\nSätter config värden i Service Manager instansen för hela testet, finns även som loadtest plugin och gäller då hela loadtestet.")]
public class ServiceManagerWebTestPlugin : WebTestPlugin
{
static bool unsafeHeadersSet = false;
[DisplayName("Use Expect 100 Behaviour"), DefaultValue(false)]
[Description("Default i .NET är att detta är påslaget, default i webbläsare är dock att detta inte är påslaget. Detta plugin stänger default därför av detta (false).")]
public bool exp100 { get; set; }
......@@ -1004,10 +1009,14 @@ namespace LIL_VSTT_Plugins
public string proxyUser { get; set; }
[DisplayName("User Password"), DefaultValue("")]
[Description("Sätter swedbanks proxy (temp lösning)")]
[Description("Sätter lösenordet för användarnamnet för proxyn")]
[Category("Web Proxy")]
public string proxyPass { get; set; }
[DisplayName("Use Unsafe Header Parsing"), DefaultValue(false)]
[Description("Enables unsafe parsing of response headers")]
public bool unsafeHeaders { get; set; }
System.Net.WebProxy myProxy = null;
public override void PreWebTest(object sender, PreWebTestEventArgs e)
......@@ -1040,7 +1049,43 @@ namespace LIL_VSTT_Plugins
System.Net.ServicePointManager.MaxServicePointIdleTime = maxIdle;
System.Net.ServicePointManager.SetTcpKeepAlive(keepAlive, timeOut, interVal);
System.Net.ServicePointManager.UseNagleAlgorithm = useNagle;
if(useTls12) System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
if (useTls12) System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
if (unsafeHeaders && !unsafeHeadersSet)
{
ToggleAllowUnsafeHeaderParsing(true);
unsafeHeadersSet = true;
}
}
public static bool ToggleAllowUnsafeHeaderParsing(bool enable)
{
//Get the assembly that contains the internal class
Assembly assembly = Assembly.GetAssembly(typeof(SettingsSection));
if (assembly != null)
{
//Use the assembly in order to get the internal type for the internal class
Type settingsSectionType = assembly.GetType("System.Net.Configuration.SettingsSectionInternal");
if (settingsSectionType != null)
{
//Use the internal static property to get an instance of the internal settings class.
//If the static instance isn't created already invoking the property will create it for us.
object anInstance = settingsSectionType.InvokeMember("Section",
BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { });
if (anInstance != null)
{
//Locate the private bool field that tells the framework if unsafe header parsing is allowed
FieldInfo aUseUnsafeHeaderParsing = settingsSectionType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance);
if (aUseUnsafeHeaderParsing != null)
{
aUseUnsafeHeaderParsing.SetValue(anInstance, enable);
return true;
}
}
}
}
return false;
}
}
......