Support for Unsafe Header Parsing in ServiceManagerWebTestPlugin
Showing
1 changed file
with
47 additions
and
2 deletions
... | @@ -22,6 +22,9 @@ using System.Text.RegularExpressions; | ... | @@ -22,6 +22,9 @@ using System.Text.RegularExpressions; |
22 | using System.Security.Cryptography.X509Certificates; | 22 | using System.Security.Cryptography.X509Certificates; |
23 | using System.Diagnostics; | 23 | using System.Diagnostics; |
24 | using System.Collections.Specialized; | 24 | using System.Collections.Specialized; |
25 | using System.Configuration; | ||
26 | using System.Net.Configuration; | ||
27 | using System.Reflection; | ||
25 | 28 | ||
26 | namespace LIL_VSTT_Plugins | 29 | namespace LIL_VSTT_Plugins |
27 | { | 30 | { |
... | @@ -952,6 +955,8 @@ namespace LIL_VSTT_Plugins | ... | @@ -952,6 +955,8 @@ namespace LIL_VSTT_Plugins |
952 | [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.")] | 955 | [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.")] |
953 | public class ServiceManagerWebTestPlugin : WebTestPlugin | 956 | public class ServiceManagerWebTestPlugin : WebTestPlugin |
954 | { | 957 | { |
958 | static bool unsafeHeadersSet = false; | ||
959 | |||
955 | [DisplayName("Use Expect 100 Behaviour"), DefaultValue(false)] | 960 | [DisplayName("Use Expect 100 Behaviour"), DefaultValue(false)] |
956 | [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).")] | 961 | [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).")] |
957 | public bool exp100 { get; set; } | 962 | public bool exp100 { get; set; } |
... | @@ -1004,10 +1009,14 @@ namespace LIL_VSTT_Plugins | ... | @@ -1004,10 +1009,14 @@ namespace LIL_VSTT_Plugins |
1004 | public string proxyUser { get; set; } | 1009 | public string proxyUser { get; set; } |
1005 | 1010 | ||
1006 | [DisplayName("User Password"), DefaultValue("")] | 1011 | [DisplayName("User Password"), DefaultValue("")] |
1007 | [Description("Sätter swedbanks proxy (temp lösning)")] | 1012 | [Description("Sätter lösenordet för användarnamnet för proxyn")] |
1008 | [Category("Web Proxy")] | 1013 | [Category("Web Proxy")] |
1009 | public string proxyPass { get; set; } | 1014 | public string proxyPass { get; set; } |
1010 | 1015 | ||
1016 | [DisplayName("Use Unsafe Header Parsing"), DefaultValue(false)] | ||
1017 | [Description("Enables unsafe parsing of response headers")] | ||
1018 | public bool unsafeHeaders { get; set; } | ||
1019 | |||
1011 | System.Net.WebProxy myProxy = null; | 1020 | System.Net.WebProxy myProxy = null; |
1012 | 1021 | ||
1013 | public override void PreWebTest(object sender, PreWebTestEventArgs e) | 1022 | public override void PreWebTest(object sender, PreWebTestEventArgs e) |
... | @@ -1040,7 +1049,43 @@ namespace LIL_VSTT_Plugins | ... | @@ -1040,7 +1049,43 @@ namespace LIL_VSTT_Plugins |
1040 | System.Net.ServicePointManager.MaxServicePointIdleTime = maxIdle; | 1049 | System.Net.ServicePointManager.MaxServicePointIdleTime = maxIdle; |
1041 | System.Net.ServicePointManager.SetTcpKeepAlive(keepAlive, timeOut, interVal); | 1050 | System.Net.ServicePointManager.SetTcpKeepAlive(keepAlive, timeOut, interVal); |
1042 | System.Net.ServicePointManager.UseNagleAlgorithm = useNagle; | 1051 | System.Net.ServicePointManager.UseNagleAlgorithm = useNagle; |
1043 | if(useTls12) System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; | 1052 | |
1053 | if (useTls12) System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; | ||
1054 | if (unsafeHeaders && !unsafeHeadersSet) | ||
1055 | { | ||
1056 | ToggleAllowUnsafeHeaderParsing(true); | ||
1057 | unsafeHeadersSet = true; | ||
1058 | } | ||
1059 | } | ||
1060 | |||
1061 | public static bool ToggleAllowUnsafeHeaderParsing(bool enable) | ||
1062 | { | ||
1063 | //Get the assembly that contains the internal class | ||
1064 | Assembly assembly = Assembly.GetAssembly(typeof(SettingsSection)); | ||
1065 | if (assembly != null) | ||
1066 | { | ||
1067 | //Use the assembly in order to get the internal type for the internal class | ||
1068 | Type settingsSectionType = assembly.GetType("System.Net.Configuration.SettingsSectionInternal"); | ||
1069 | if (settingsSectionType != null) | ||
1070 | { | ||
1071 | //Use the internal static property to get an instance of the internal settings class. | ||
1072 | //If the static instance isn't created already invoking the property will create it for us. | ||
1073 | object anInstance = settingsSectionType.InvokeMember("Section", | ||
1074 | BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { }); | ||
1075 | if (anInstance != null) | ||
1076 | { | ||
1077 | //Locate the private bool field that tells the framework if unsafe header parsing is allowed | ||
1078 | FieldInfo aUseUnsafeHeaderParsing = settingsSectionType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance); | ||
1079 | if (aUseUnsafeHeaderParsing != null) | ||
1080 | { | ||
1081 | aUseUnsafeHeaderParsing.SetValue(anInstance, enable); | ||
1082 | return true; | ||
1083 | } | ||
1084 | |||
1085 | } | ||
1086 | } | ||
1087 | } | ||
1088 | return false; | ||
1044 | } | 1089 | } |
1045 | } | 1090 | } |
1046 | 1091 | ... | ... |
-
Please register or sign in to post a comment