From 02cffd16ecaea0ace748788e65cd6ec51e237a96 Mon Sep 17 00:00:00 2001 From: jhkimnew Date: Thu, 19 Oct 2017 12:15:24 -0700 Subject: [PATCH] Jhkim/refactoring test (#176) Cleans up IIS initialization testing framework --- .../Framework/IISConfigUtility.cs | 20 +++---- .../Framework/InitializeTestMachine.cs | 57 ++++++++++--------- .../Framework/TestWebSite.cs | 20 +++---- .../FunctionalTestHelper.cs | 2 +- 4 files changed, 50 insertions(+), 49 deletions(-) diff --git a/test/AspNetCoreModule.Test/Framework/IISConfigUtility.cs b/test/AspNetCoreModule.Test/Framework/IISConfigUtility.cs index 86077f22d..79557281e 100644 --- a/test/AspNetCoreModule.Test/Framework/IISConfigUtility.cs +++ b/test/AspNetCoreModule.Test/Framework/IISConfigUtility.cs @@ -208,7 +208,7 @@ private static void CopyAppHostConfig(string fromfile, string tofile) if (!File.Exists(fromfile)) { - throw new System.ApplicationException("Failed to backup " + tofile); + throw new ApplicationException("Failed to backup " + tofile); } // try restoring applicationhost.config again after the ininial clean up for better reliability @@ -232,7 +232,7 @@ private static void CopyAppHostConfig(string fromfile, string tofile) // verify restoration is done successfully if (File.ReadAllBytes(fromfile).Length != File.ReadAllBytes(tofile).Length) { - throw new System.ApplicationException("Failed to restore applicationhost.config from " + fromfile + " to " + tofile); + throw new ApplicationException("Failed to restore applicationhost.config from " + fromfile + " to " + tofile); } } @@ -465,7 +465,7 @@ public void SetANCMConfig(string siteName, string appName, string attributeName, var element = FindElement(environmentVariablesCollection, "add", "name", value); if (element != null) { - throw new System.ApplicationException("duplicated collection item"); + throw new ApplicationException("duplicated collection item"); } environmentVariablesCollection.Add(environmentVariableElement); } @@ -1116,7 +1116,7 @@ public string CreateSelfSignedCertificateWithMakeCert(string subjectName, string string output = TestUtility.RunPowershellScript(powershellScript); if (output.Length != 40) { - throw new System.ApplicationException("Failed to create a certificate, output: " + output); + throw new ApplicationException("Failed to create a certificate, output: " + output); } return output; } @@ -1131,7 +1131,7 @@ public string CreateSelfSignedCertificate(string subjectName) string output = TestUtility.RunPowershellScript(powershellScript); if (output.Length != 40) { - throw new System.ApplicationException("Failed to create a certificate, output: " + output); + throw new ApplicationException("Failed to create a certificate, output: " + output); } return output; } @@ -1153,7 +1153,7 @@ public string ExportCertificateTo(string thumbPrint, string sslStoreFrom = @"Cer string output = TestUtility.RunPowershellScript(powershellScript); if (output != string.Empty) { - throw new System.ApplicationException("Failed to export a certificate to RootCA, output: " + output); + throw new ApplicationException("Failed to export a certificate to RootCA, output: " + output); } return output; } @@ -1169,7 +1169,7 @@ public string GetCertificatePublicKey(string thumbPrint, string sslStore = @"Cer string output = TestUtility.RunPowershellScript(powershellScript); if (output.Length < 500) { - throw new System.ApplicationException("Failed to get certificate public key, output: " + output); + throw new ApplicationException("Failed to get certificate public key, output: " + output); } return output; } @@ -1185,7 +1185,7 @@ public string DeleteCertificate(string thumbPrint, string sslStore= @"Cert:\Loca string output = TestUtility.RunPowershellScript(powershellScript); if (output != string.Empty) { - throw new System.ApplicationException("Failed to delete a certificate (thumbprint: " + thumbPrint + ", output: " + output); + throw new ApplicationException("Failed to delete a certificate (thumbprint: " + thumbPrint + ", output: " + output); } return output; } @@ -1207,7 +1207,7 @@ public void SetSSLCertificate(int port, string hexIpAddress, string thumbPrint, string output = TestUtility.RunPowershellScript(powershellScript); if (output != string.Empty) { - throw new System.ApplicationException("Failed to configure certificate, output: " + output); + throw new ApplicationException("Failed to configure certificate, output: " + output); } } @@ -1227,7 +1227,7 @@ public void RemoveSSLCertificate(int port, string hexIpAddress, string sslStore output = TestUtility.RunPowershellScript(powershellScript); if (output != string.Empty) { - throw new System.ApplicationException("Failed to delete certificate, output: " + output); + throw new ApplicationException("Failed to delete certificate, output: " + output); } } } diff --git a/test/AspNetCoreModule.Test/Framework/InitializeTestMachine.cs b/test/AspNetCoreModule.Test/Framework/InitializeTestMachine.cs index 53b7fcd38..9fc4d086c 100644 --- a/test/AspNetCoreModule.Test/Framework/InitializeTestMachine.cs +++ b/test/AspNetCoreModule.Test/Framework/InitializeTestMachine.cs @@ -18,6 +18,8 @@ public static class TestFlags public const string UseFullIIS = "UseFullIIS"; public const string RunAsAdministrator = "RunAsAdministrator"; public const string MakeCertExeAvailable = "MakeCertExeAvailable"; + public const string WebSocketModuleAvailable = "WebSocketModuleAvailable"; + public const string UrlRewriteModuleAvailable = "UrlRewriteModuleAvailable"; public const string X86Platform = "X86Platform"; public const string Wow64BitMode = "Wow64BitMode"; public const string RequireRunAsAdministrator = "RequireRunAsAdministrator"; @@ -65,7 +67,7 @@ public static bool MakeCertExeAvailable } catch { - _makeCertExeAvailable = false; + // ignore exception } } return (_makeCertExeAvailable == true); @@ -87,9 +89,8 @@ public static string GlobalTestFlags { if (_globalTestFlags == null) { - bool isElevated; WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); - isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator); + bool isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator); // check if this test process is started with the Run As Administrator start option _globalTestFlags = Environment.ExpandEnvironmentVariables(ANCMTestFlagsEnvironmentVariable); @@ -190,6 +191,26 @@ public static string GlobalTestFlags } } + if (File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "iiswsock.dll"))) + { + // Add WebSocketModuleAvailable + if (!_globalTestFlags.Contains(TestFlags.WebSocketModuleAvailable.ToLower())) + { + TestUtility.LogInformation("Added test context of " + TestFlags.WebSocketModuleAvailable); + _globalTestFlags += ";" + TestFlags.WebSocketModuleAvailable; + } + } + + if (File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "rewrite.dll"))) + { + // Add UrlRewriteModuleAvailable + if (!_globalTestFlags.Contains(TestFlags.UrlRewriteModuleAvailable.ToLower())) + { + TestUtility.LogInformation("Added test context of " + TestFlags.UrlRewriteModuleAvailable); + _globalTestFlags += ";" + TestFlags.UrlRewriteModuleAvailable; + } + } + _globalTestFlags = _globalTestFlags.ToLower(); } @@ -213,17 +234,7 @@ public void InitializeIISServer() if (!isIISInstalled) { - throw new System.ApplicationException("IIS server is not installed"); - } - - // Check websocket is installed - if (File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "iiswsock.dll"))) - { - TestUtility.LogInformation("Websocket is installed"); - } - else - { - throw new System.ApplicationException("websocket module is not installed"); + throw new ApplicationException("IIS server is not installed"); } // Clean up IIS worker process @@ -241,22 +252,12 @@ public void InitializeIISServer() } else { - throw new System.ApplicationException("WWW service can't start"); - } - - // check URLRewrite module exists - if (File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "rewrite.dll"))) - { - TestUtility.LogInformation("Verified URL Rewrite module installed for IIS server"); - } - else - { - throw new System.ApplicationException("URL Rewrite module is not installed"); + throw new ApplicationException("WWW service can't start"); } if (IISConfigUtility.ApppHostTemporaryBackupFileExtention == null) { - throw new System.ApplicationException("Failed to backup applicationhost.config"); + throw new ApplicationException("Failed to backup applicationhost.config"); } } @@ -355,7 +356,7 @@ public InitializeTestMachine() } if (!_InitializeTestMachineCompleted) { - throw new System.ApplicationException("InitializeTestMachine failed"); + throw new ApplicationException("InitializeTestMachine failed"); } } @@ -476,7 +477,7 @@ private void PreparePrivateANCMFiles() } if (!updateSuccess) { - throw new System.ApplicationException("Failed to update aspnetcore.dll"); + throw new ApplicationException("Failed to update aspnetcore.dll"); } // update applicationhost.config for IIS server with the new private ASPNET Core file name diff --git a/test/AspNetCoreModule.Test/Framework/TestWebSite.cs b/test/AspNetCoreModule.Test/Framework/TestWebSite.cs index 79b4ab65a..af7098f69 100644 --- a/test/AspNetCoreModule.Test/Framework/TestWebSite.cs +++ b/test/AspNetCoreModule.Test/Framework/TestWebSite.cs @@ -419,7 +419,7 @@ public void AttachAppverifier() cmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "syswow64", "appverif.exe"); if (!File.Exists(cmdline)) { - throw new System.ApplicationException("Not found :" + cmdline + "; this test requires appverif.exe."); + throw new ApplicationException("Not found :" + cmdline + "; this test requires appverif.exe."); } } else @@ -427,7 +427,7 @@ public void AttachAppverifier() cmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "appverif.exe"); if (!File.Exists(cmdline)) { - throw new System.ApplicationException("Not found :" + cmdline + "; this test requires appverif.exe."); + throw new ApplicationException("Not found :" + cmdline + "; this test requires appverif.exe."); } } @@ -438,7 +438,7 @@ public void AttachAppverifier() } catch { - throw new System.ApplicationException("Failed to configure Appverifier"); + throw new ApplicationException("Failed to configure Appverifier"); } } @@ -456,7 +456,7 @@ public void AttachWinDbg(int processIdOfWorkerProcess) debuggerCmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "Debugging Tools for Windows (x64)", "wow64", "windbg.exe"); if (!File.Exists(debuggerCmdline)) { - throw new System.ApplicationException("Not found :" + debuggerCmdline + "; this test requires windbg.exe."); + throw new ApplicationException("Not found :" + debuggerCmdline + "; this test requires windbg.exe."); } } else @@ -464,7 +464,7 @@ public void AttachWinDbg(int processIdOfWorkerProcess) debuggerCmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "Debugging Tools for Windows (x64)", "windbg.exe"); if (!File.Exists(debuggerCmdline)) { - throw new System.ApplicationException("Not found :" + debuggerCmdline + "; this test requires windbg.exe."); + throw new ApplicationException("Not found :" + debuggerCmdline + "; this test requires windbg.exe."); } } @@ -475,7 +475,7 @@ public void AttachWinDbg(int processIdOfWorkerProcess) } catch { - throw new System.ApplicationException("Failed to attach debuger"); + throw new ApplicationException("Failed to attach debuger"); } } @@ -497,12 +497,12 @@ public void DetachAppverifier() cmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "syswow64", "appverif.exe"); if (!File.Exists(cmdline)) { - throw new System.ApplicationException("Not found :" + cmdline); + throw new ApplicationException("Not found :" + cmdline); } debuggerCmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "Debugging Tools for Windows (x64)", "wow64", "windbg.exe"); if (!File.Exists(debuggerCmdline)) { - throw new System.ApplicationException("Not found :" + debuggerCmdline); + throw new ApplicationException("Not found :" + debuggerCmdline); } } else @@ -510,12 +510,12 @@ public void DetachAppverifier() cmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "appverif.exe"); if (!File.Exists(cmdline)) { - throw new System.ApplicationException("Not found :" + cmdline); + throw new ApplicationException("Not found :" + cmdline); } debuggerCmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "Debugging Tools for Windows (x64)", "windbg.exe"); if (!File.Exists(debuggerCmdline)) { - throw new System.ApplicationException("Not found :" + debuggerCmdline); + throw new ApplicationException("Not found :" + debuggerCmdline); } } TestUtility.RunCommand(cmdline, argument, true, false); diff --git a/test/AspNetCoreModule.Test/FunctionalTestHelper.cs b/test/AspNetCoreModule.Test/FunctionalTestHelper.cs index d66c850f5..7e15e1acf 100644 --- a/test/AspNetCoreModule.Test/FunctionalTestHelper.cs +++ b/test/AspNetCoreModule.Test/FunctionalTestHelper.cs @@ -695,7 +695,7 @@ public static async Task DoRequestTimeoutTest(IISConfigUtility.AppPoolBitness ap } else { - throw new System.ApplicationException("wrong data"); + throw new ApplicationException("wrong data"); } } testSite.AspNetCoreApp.RestoreFile("web.config");