Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

Commit

Permalink
Jhkim/refactoring test (#176)
Browse files Browse the repository at this point in the history
Cleans up IIS initialization testing framework
  • Loading branch information
jhkimnew authored Oct 19, 2017
1 parent 68014a7 commit 02cffd1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 49 deletions.
20 changes: 10 additions & 10 deletions test/AspNetCoreModule.Test/Framework/IISConfigUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down
57 changes: 29 additions & 28 deletions test/AspNetCoreModule.Test/Framework/InitializeTestMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -65,7 +67,7 @@ public static bool MakeCertExeAvailable
}
catch
{
_makeCertExeAvailable = false;
// ignore exception
}
}
return (_makeCertExeAvailable == true);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}

Expand All @@ -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
Expand All @@ -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");
}
}

Expand Down Expand Up @@ -355,7 +356,7 @@ public InitializeTestMachine()
}
if (!_InitializeTestMachineCompleted)
{
throw new System.ApplicationException("InitializeTestMachine failed");
throw new ApplicationException("InitializeTestMachine failed");
}
}

Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions test/AspNetCoreModule.Test/Framework/TestWebSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ 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
{
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.");
}
}

Expand All @@ -438,7 +438,7 @@ public void AttachAppverifier()
}
catch
{
throw new System.ApplicationException("Failed to configure Appverifier");
throw new ApplicationException("Failed to configure Appverifier");
}
}

Expand All @@ -456,15 +456,15 @@ 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
{
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.");
}
}

Expand All @@ -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");
}
}

Expand All @@ -497,25 +497,25 @@ 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
{
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);
Expand Down
2 changes: 1 addition & 1 deletion test/AspNetCoreModule.Test/FunctionalTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 02cffd1

Please sign in to comment.