ANCM Test Refactoring: Initial check-in to fix the build issue on AspNetCI (#172)

* Initial check-in to fix the build issue on AspNetCI

* Updated with Jimmy's feedbacks
This commit is contained in:
jhkimnew 2017-09-29 14:49:12 -07:00 committed by GitHub
parent f130330db8
commit 890e49e539
6 changed files with 420 additions and 326 deletions

View File

@ -155,7 +155,7 @@ namespace AspNetCoreModule.Test.Framework
{ {
ApppHostTemporaryBackupFileExtention = temporaryBackupFileExtenstion; ApppHostTemporaryBackupFileExtention = temporaryBackupFileExtenstion;
break; break;
} }
} }
} }
@ -263,7 +263,7 @@ namespace AspNetCoreModule.Test.Framework
addElement[attribute] = value; addElement[attribute] = value;
break; break;
} }
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -291,7 +291,7 @@ namespace AspNetCoreModule.Test.Framework
} }
} }
public void CreateSite(string siteName, string physicalPath, int siteId, int tcpPort, string appPoolName = "DefaultAppPool") public void CreateSite(string siteName, string hostname, string physicalPath, int siteId, int tcpPort, string appPoolName = "DefaultAppPool")
{ {
TestUtility.LogInformation("Creating web site : " + siteName); TestUtility.LogInformation("Creating web site : " + siteName);
@ -312,7 +312,7 @@ namespace AspNetCoreModule.Test.Framework
ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding"); ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
bindingElement["protocol"] = @"http"; bindingElement["protocol"] = @"http";
bindingElement["bindingInformation"] = "*:" + tcpPort + ":"; bindingElement["bindingInformation"] = "*:" + tcpPort + ":" + hostname;
bindingsCollection.Add(bindingElement); bindingsCollection.Add(bindingElement);
ConfigurationElementCollection siteCollection = siteElement.GetCollection(); ConfigurationElementCollection siteCollection = siteElement.GetCollection();
@ -327,7 +327,6 @@ namespace AspNetCoreModule.Test.Framework
applicationCollection.Add(virtualDirectoryElement); applicationCollection.Add(virtualDirectoryElement);
siteCollection.Add(applicationElement); siteCollection.Add(applicationElement);
sitesCollection.Add(siteElement); sitesCollection.Add(siteElement);
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -361,7 +360,6 @@ namespace AspNetCoreModule.Test.Framework
virtualDirectoryElement["physicalPath"] = physicalPath; virtualDirectoryElement["physicalPath"] = physicalPath;
applicationCollection.Add(virtualDirectoryElement); applicationCollection.Add(virtualDirectoryElement);
siteCollection.Add(applicationElement); siteCollection.Add(applicationElement);
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -379,7 +377,6 @@ namespace AspNetCoreModule.Test.Framework
basicAuthenticationSection["enabled"] = basic; basicAuthenticationSection["enabled"] = basic;
ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", siteName); ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", siteName);
windowsAuthenticationSection["enabled"] = windows; windowsAuthenticationSection["enabled"] = windows;
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -416,7 +413,6 @@ namespace AspNetCoreModule.Test.Framework
anonymousAuthenticationSection["enabled"] = false; anonymousAuthenticationSection["enabled"] = false;
ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", siteName); ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", siteName);
windowsAuthenticationSection["enabled"] = false; windowsAuthenticationSection["enabled"] = false;
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -431,7 +427,6 @@ namespace AspNetCoreModule.Test.Framework
ConfigurationSection urlCompressionSection = config.GetSection("system.webServer/urlCompression", siteName); ConfigurationSection urlCompressionSection = config.GetSection("system.webServer/urlCompression", siteName);
urlCompressionSection["doStaticCompression"] = enabled; urlCompressionSection["doStaticCompression"] = enabled;
urlCompressionSection["doDynamicCompression"] = enabled; urlCompressionSection["doDynamicCompression"] = enabled;
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -447,7 +442,6 @@ namespace AspNetCoreModule.Test.Framework
anonymousAuthenticationSection["enabled"] = true; anonymousAuthenticationSection["enabled"] = true;
ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", siteName); ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", siteName);
windowsAuthenticationSection["enabled"] = false; windowsAuthenticationSection["enabled"] = false;
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -509,41 +503,10 @@ namespace AspNetCoreModule.Test.Framework
errorElement2["subStatusCode"] = subStatusCode; errorElement2["subStatusCode"] = subStatusCode;
errorElement2["path"] = path; errorElement2["path"] = path;
httpErrorsCollection.Add(errorElement2); httpErrorsCollection.Add(errorElement2);
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
Thread.Sleep(500); Thread.Sleep(500);
} }
private static bool? _isIISInstalled = null;
public static bool? IsIISInstalled
{
get
{
if (_isIISInstalled == null)
{
_isIISInstalled = true;
if (_isIISInstalled == true && !File.Exists(Path.Combine(Strings.IIS64BitPath, "iiscore.dll")))
{
_isIISInstalled = false;
}
if (_isIISInstalled == true && !File.Exists(Path.Combine(Strings.IIS64BitPath, "config", "applicationhost.config")))
{
_isIISInstalled = false;
}
}
return _isIISInstalled;
}
set
{
_isIISInstalled = value;
}
}
public static bool IsIISReady {
get;
set;
}
public bool IsAncmInstalled(ServerType servertype) public bool IsAncmInstalled(ServerType servertype)
{ {
@ -646,7 +609,7 @@ namespace AspNetCoreModule.Test.Framework
{ {
modulesCollection.Remove(module); modulesCollection.Remove(module);
} }
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
return result; return result;
@ -748,7 +711,6 @@ namespace AspNetCoreModule.Test.Framework
{ {
ApplicationPoolCollection appPools = serverManager.ApplicationPools; ApplicationPoolCollection appPools = serverManager.ApplicationPools;
appPools[appPoolName].ProcessModel.IdleTimeout = TimeSpan.FromMinutes(idleTimeoutMinutes); appPools[appPoolName].ProcessModel.IdleTimeout = TimeSpan.FromMinutes(idleTimeoutMinutes);
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -767,7 +729,6 @@ namespace AspNetCoreModule.Test.Framework
{ {
ApplicationPoolCollection appPools = serverManager.ApplicationPools; ApplicationPoolCollection appPools = serverManager.ApplicationPools;
appPools[appPoolName].ProcessModel.MaxProcesses = maxProcesses; appPools[appPoolName].ProcessModel.MaxProcesses = maxProcesses;
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -788,7 +749,6 @@ namespace AspNetCoreModule.Test.Framework
appPools[appPoolName].ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser; appPools[appPoolName].ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
appPools[appPoolName].ProcessModel.UserName = userName; appPools[appPoolName].ProcessModel.UserName = userName;
appPools[appPoolName].ProcessModel.Password = password; appPools[appPoolName].ProcessModel.Password = password;
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -810,7 +770,6 @@ namespace AspNetCoreModule.Test.Framework
{ {
ApplicationPoolCollection appPools = serverManager.ApplicationPools; ApplicationPoolCollection appPools = serverManager.ApplicationPools;
appPools[appPoolName]["startMode"] = startMode; appPools[appPoolName]["startMode"] = startMode;
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -841,11 +800,13 @@ namespace AspNetCoreModule.Test.Framework
{ {
ApplicationPoolCollection appPools = serverManager.ApplicationPools; ApplicationPoolCollection appPools = serverManager.ApplicationPools;
if (start) if (start)
{
appPools[appPoolName].Start(); appPools[appPoolName].Start();
}
else else
{
appPools[appPoolName].Stop(); appPools[appPoolName].Stop();
}
serverManager.CommitChanges();
} }
} }
catch (Exception ex) catch (Exception ex)
@ -902,8 +863,9 @@ namespace AspNetCoreModule.Test.Framework
{ {
ApplicationPoolCollection appPools = serverManager.ApplicationPools; ApplicationPoolCollection appPools = serverManager.ApplicationPools;
while (appPools.Count > 0) while (appPools.Count > 0)
{
appPools.RemoveAt(0); appPools.RemoveAt(0);
}
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -948,7 +910,6 @@ namespace AspNetCoreModule.Test.Framework
b.SetAttributeValue("bindingInformation", bindingInfo); b.SetAttributeValue("bindingInformation", bindingInfo);
site.Bindings.Add(b); site.Bindings.Add(b);
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -988,7 +949,6 @@ namespace AspNetCoreModule.Test.Framework
sites[siteName].Stop(); sites[siteName].Stop();
sites[siteName].SetAttributeValue("serverAutoStart", false); sites[siteName].SetAttributeValue("serverAutoStart", false);
} }
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -1033,7 +993,6 @@ namespace AspNetCoreModule.Test.Framework
vdir.SetAttributeValue("physicalPath", physicalPath); vdir.SetAttributeValue("physicalPath", physicalPath);
app.VirtualDirectories.Add(vdir); app.VirtualDirectories.Add(vdir);
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -1176,7 +1135,7 @@ namespace AspNetCoreModule.Test.Framework
} }
return output; return output;
} }
public string ExportCertificateTo(string thumbPrint, string sslStoreFrom = @"Cert:\LocalMachine\My", string sslStoreTo = @"Cert:\LocalMachine\Root", string pfxPassword = null) public string ExportCertificateTo(string thumbPrint, string sslStoreFrom = @"Cert:\LocalMachine\My", string sslStoreTo = @"Cert:\LocalMachine\Root", string pfxPassword = null)
{ {
string toolsPath = Path.Combine(InitializeTestMachine.GetSolutionDirectory(), "tools"); string toolsPath = Path.Combine(InitializeTestMachine.GetSolutionDirectory(), "tools");
@ -1391,8 +1350,9 @@ namespace AspNetCoreModule.Test.Framework
SiteCollection sites = serverManager.Sites; SiteCollection sites = serverManager.Sites;
while (sites.Count > 0) while (sites.Count > 0)
{
sites.RemoveAt(0); sites.RemoveAt(0);
}
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -1406,11 +1366,8 @@ namespace AspNetCoreModule.Test.Framework
using (ServerManager serverManager = new ServerManager()) using (ServerManager serverManager = new ServerManager())
{ {
Configuration config = serverManager.GetApplicationHostConfiguration(); Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection webLimitsSection = config.GetSection("system.applicationHost/webLimits"); ConfigurationSection webLimitsSection = config.GetSection("system.applicationHost/webLimits");
webLimitsSection["dynamicRegistrationThreshold"] = threshold; webLimitsSection["dynamicRegistrationThreshold"] = threshold;
serverManager.CommitChanges(); serverManager.CommitChanges();
} }
} }
@ -1418,6 +1375,6 @@ namespace AspNetCoreModule.Test.Framework
{ {
TestUtility.LogTrace(String.Format("#################### Changing dynamicRegistrationThreshold failed. Reason: {0} ####################", ex.Message)); TestUtility.LogTrace(String.Format("#################### Changing dynamicRegistrationThreshold failed. Reason: {0} ####################", ex.Message));
} }
} }
} }
} }

View File

@ -5,58 +5,41 @@ using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.PlatformAbstractions;
using System.Security.Principal;
using System.Security.AccessControl;
namespace AspNetCoreModule.Test.Framework namespace AspNetCoreModule.Test.Framework
{ {
public static class TestFlags
{
public const string SkipTest = "SkipTest";
public const string UsePrivateANCM = "UsePrivateANCM";
public const string UseIISExpress = "UseIISExpress";
public const string UseFullIIS = "UseFullIIS";
public const string RunAsAdministrator = "RunAsAdministrator";
public const string MakeCertExeAvailable = "MakeCertExeAvailable";
public const string X86Platform = "X86Platform";
public const string Wow64BitMode = "Wow64BitMode";
public const string RequireRunAsAdministrator = "RequireRunAsAdministrator";
public const string Default = "Default";
public static bool Enabled(string flagValue)
{
return InitializeTestMachine.GlobalTestFlags.Contains(flagValue.ToLower());
}
}
public class InitializeTestMachine : IDisposable public class InitializeTestMachine : IDisposable
{ {
public const string ANCMTestFlagsEnvironmentVariable = "%ANCMTestFlags%"; public const string ANCMTestFlagsEnvironmentVariable = "%ANCMTestFlags%";
public const string ANCMTestFlagsDefaultContext = "AdminAnd64Bit";
public const string ANCMTestFlagsTestSkipContext = "SkipTest";
public const string ANCMTestFlagsUsePrivateAspNetCoreFileContext = "UsePrivate";
private const string ANCMTestFlagsUseIISExpressContext = "UseIISExpress";
private static bool? _usePrivateAspNetCoreFile = null;
public static bool? UsePrivateAspNetCoreFile
{
get {
//
// By default, we don't use the private AspNetCore.dll that is compiled with this solution.
// In order to use the private file, you should add 'UsePrivateAspNetCoreFile' flag to the Environmnet variable %ANCMTestFlag%.
//
// Set ANCMTestFlag=%ANCMTestFlag%;UsePrivateAspNetCoreFile
// Or
// $Env:ANCMTestFlag=$Env:ANCMTestFlag + ";UsePrivateAspNetCoreFile"
//
if (_usePrivateAspNetCoreFile == null)
{
_usePrivateAspNetCoreFile = false;
var envValue = Environment.ExpandEnvironmentVariables(ANCMTestFlagsEnvironmentVariable);
if (envValue.ToLower().Contains(ANCMTestFlagsUsePrivateAspNetCoreFileContext.ToLower()))
{
TestUtility.LogInformation("PrivateAspNetCoreFile is set");
_usePrivateAspNetCoreFile = true;
}
else
{
TestUtility.LogInformation("PrivateAspNetCoreFile is not set");
}
}
return _usePrivateAspNetCoreFile;
}
set
{
_usePrivateAspNetCoreFile = value;
}
}
public static int SiteId = 40000; public static int SiteId = 40000;
public const string PrivateFileName = "aspnetcore_private.dll"; public const string PrivateFileName = "aspnetcore_private.dll";
public static string FullIisAspnetcore_path = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "inetsrv", PrivateFileName); public static string FullIisAspnetcore_path = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "inetsrv", PrivateFileName);
public static string FullIisAspnetcore_path_original = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "inetsrv", "aspnetcore.dll"); public static string FullIisAspnetcore_path_original = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "inetsrv", "aspnetcore.dll");
public static string FullIisAspnetcore_X86_path = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "syswow64", "inetsrv", PrivateFileName); public static string FullIisAspnetcore_X86_path = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "syswow64", "inetsrv", PrivateFileName);
public static string IisExpressAspnetcore_path = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "IIS Express", PrivateFileName); public static string IisExpressAspnetcore_path;
public static string IisExpressAspnetcore_X86_path = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%"), "IIS Express", PrivateFileName); public static string IisExpressAspnetcore_X86_path;
public static string IisExpressAspnetcoreSchema_path = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "IIS Express", "config", "schema", "aspnetcore_schema.xml"); public static string IisExpressAspnetcoreSchema_path = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "IIS Express", "config", "schema", "aspnetcore_schema.xml");
public static string IisExpressAspnetcoreSchema_X86_path = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%"), "IIS Express", "config", "schema", "aspnetcore_schema.xml"); public static string IisExpressAspnetcoreSchema_X86_path = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%"), "IIS Express", "config", "schema", "aspnetcore_schema.xml");
@ -65,27 +48,225 @@ namespace AspNetCoreModule.Test.Framework
private static bool _InitializeTestMachineCompleted = false; private static bool _InitializeTestMachineCompleted = false;
private string _setupScriptPath = null; private string _setupScriptPath = null;
private bool CheckPerquisiteForANCMTest() private static bool? _makeCertExeAvailable = null;
public static bool MakeCertExeAvailable
{ {
bool result = true; get
TestUtility.LogInformation("CheckPerquisiteForANCMTest(): Environment.Is64BitOperatingSystem: {0}, Environment.Is64BitProcess {1}", Environment.Is64BitOperatingSystem, Environment.Is64BitProcess);
TestUtility.LogInformation("%ANCMTestFlags%: {0}", Environment.ExpandEnvironmentVariables(ANCMTestFlagsEnvironmentVariable));
if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
{ {
TestUtility.LogInformation("CheckPerquisiteForANCMTest() Failed: ANCM test should be started with x64 process mode on 64 bit machine; if you run this test on Visual Studio, you should set X64 first after selecting 'Test -> Test Settings -> Default Process Architecture' menu"); if (_makeCertExeAvailable == null)
result = false; {
_makeCertExeAvailable = false;
try
{
string makecertExeFilePath = TestUtility.GetMakeCertPath();
TestUtility.RunCommand(makecertExeFilePath, null, true, true);
TestUtility.LogInformation("Verified makecert.exe is available : " + makecertExeFilePath);
_makeCertExeAvailable = true;
}
catch
{
_makeCertExeAvailable = false;
}
}
return (_makeCertExeAvailable == true);
} }
return result;
} }
public static string TestRootDirectory
{
get
{
return Path.Combine(Environment.ExpandEnvironmentVariables("%SystemDrive%") + @"\", "_ANCMTest");
}
}
private static string _globalTestFlags = null;
public static string GlobalTestFlags
{
get
{
if (_globalTestFlags == null)
{
bool isElevated;
WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
// check if this test process is started with the Run As Administrator start option
_globalTestFlags = Environment.ExpandEnvironmentVariables(ANCMTestFlagsEnvironmentVariable);
//
// Check if ANCMTestFlags environment is not defined and the test program was started
// without using the Run As Administrator start option.
// In that case, we have to use the default TestFlags of UseIISExpress and UsePrivateANCM
//
if (!isElevated)
{
if (_globalTestFlags.ToLower().Contains("%" + ANCMTestFlagsEnvironmentVariable.ToLower() + "%"))
{
_globalTestFlags = TestFlags.UsePrivateANCM + ";" + TestFlags.UseIISExpress;
}
}
//
// convert in lower case
//
_globalTestFlags = _globalTestFlags.ToLower();
//
// error handling: UseIISExpress and UseFullIIS can be used together.
//
if (_globalTestFlags.Contains(TestFlags.UseIISExpress.ToLower()) && _globalTestFlags.Contains(TestFlags.UseFullIIS.ToLower()))
{
_globalTestFlags = _globalTestFlags.Replace(TestFlags.UseFullIIS.ToLower(), "");
}
//
// adjust the default test context in run time to figure out wrong test context values
//
if (isElevated)
{
// add RunAsAdministrator
if (!_globalTestFlags.Contains(TestFlags.RunAsAdministrator.ToLower()))
{
TestUtility.LogInformation("Added test context of " + TestFlags.RunAsAdministrator);
_globalTestFlags += ";" + TestFlags.RunAsAdministrator;
}
}
else
{
// add UseIISExpress
if (!_globalTestFlags.Contains(TestFlags.UseIISExpress.ToLower()))
{
TestUtility.LogInformation("Added test context of " + TestFlags.UseIISExpress);
_globalTestFlags += ";" + TestFlags.UseIISExpress;
}
// remove UseFullIIS
if (_globalTestFlags.Contains(TestFlags.UseFullIIS.ToLower()))
{
_globalTestFlags = _globalTestFlags.Replace(TestFlags.UseFullIIS.ToLower(), "");
}
// remove RunAsAdmistrator
if (_globalTestFlags.Contains(TestFlags.RunAsAdministrator.ToLower()))
{
_globalTestFlags = _globalTestFlags.Replace(TestFlags.RunAsAdministrator.ToLower(), "");
}
}
if (MakeCertExeAvailable)
{
// Add MakeCertExeAvailable
if (!_globalTestFlags.Contains(TestFlags.MakeCertExeAvailable.ToLower()))
{
TestUtility.LogInformation("Added test context of " + TestFlags.MakeCertExeAvailable);
_globalTestFlags += ";" + TestFlags.MakeCertExeAvailable;
}
}
if (!Environment.Is64BitOperatingSystem)
{
// Add X86Platform
if (!_globalTestFlags.Contains(TestFlags.X86Platform.ToLower()))
{
TestUtility.LogInformation("Added test context of " + TestFlags.X86Platform);
_globalTestFlags += ";" + TestFlags.X86Platform;
}
}
if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
{
// Add Wow64bitMode
if (!_globalTestFlags.Contains(TestFlags.Wow64BitMode.ToLower()))
{
TestUtility.LogInformation("Added test context of " + TestFlags.Wow64BitMode);
_globalTestFlags += ";" + TestFlags.Wow64BitMode;
}
// remove X86Platform
if (_globalTestFlags.Contains(TestFlags.X86Platform.ToLower()))
{
_globalTestFlags = _globalTestFlags.Replace(TestFlags.X86Platform.ToLower(), "");
}
}
_globalTestFlags = _globalTestFlags.ToLower();
}
return _globalTestFlags;
}
}
public void InitializeIISServer()
{
// Check if IIS server is installed or not
bool isIISInstalled = true;
if (!File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "iiscore.dll")))
{
isIISInstalled = false;
}
if (!File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "config", "applicationhost.config")))
{
isIISInstalled = false;
}
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");
}
// Clean up IIS worker process
TestUtility.ResetHelper(ResetHelperMode.KillWorkerProcess);
// Reset applicationhost.config
TestUtility.LogInformation("Restoring applicationhost.config");
IISConfigUtility.RestoreAppHostConfig(restoreFromMasterBackupFile: true);
TestUtility.StartW3svc();
// check w3svc is running after resetting applicationhost.config
if (IISConfigUtility.GetServiceStatus("w3svc") == "Running")
{
TestUtility.LogInformation("W3SVC service is restarted after restoring applicationhost.config");
}
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");
}
if (IISConfigUtility.ApppHostTemporaryBackupFileExtention == null)
{
throw new System.ApplicationException("Failed to backup applicationhost.config");
}
}
public InitializeTestMachine() public InitializeTestMachine()
{ {
_referenceCount++; _referenceCount++;
// This method should be called only one time
if (_referenceCount == 1) if (_referenceCount == 1)
{ {
CheckPerquisiteForANCMTest();
TestUtility.LogInformation("InitializeTestMachine::InitializeTestMachine() Start"); TestUtility.LogInformation("InitializeTestMachine::InitializeTestMachine() Start");
_InitializeTestMachineCompleted = false; _InitializeTestMachineCompleted = false;
@ -93,94 +274,34 @@ namespace AspNetCoreModule.Test.Framework
TestUtility.LogInformation("InitializeTestMachine::Start"); TestUtility.LogInformation("InitializeTestMachine::Start");
if (Environment.ExpandEnvironmentVariables("%ANCMTEST_DEBUG%").ToLower() == "true") if (Environment.ExpandEnvironmentVariables("%ANCMTEST_DEBUG%").ToLower() == "true")
{ {
System.Diagnostics.Debugger.Launch(); System.Diagnostics.Debugger.Launch();
} }
// check Makecert.exe exists //
try // Clean up IISExpress processes
{ //
string makecertExeFilePath = TestUtility.GetMakeCertPath();
TestUtility.RunCommand(makecertExeFilePath, null, true, true);
TestUtility.LogInformation("Verified makecert.exe is available : " + makecertExeFilePath);
}
catch (Exception ex)
{
throw new System.ApplicationException("makecert.exe is not available : " + ex.Message);
}
TestUtility.ResetHelper(ResetHelperMode.KillIISExpress); TestUtility.ResetHelper(ResetHelperMode.KillIISExpress);
// check if we can use IIS server instead of IISExpress //
try // Initalize IIS server
//
if (TestFlags.Enabled(TestFlags.UseFullIIS))
{ {
IISConfigUtility.IsIISReady = false; InitializeIISServer();
if (IISConfigUtility.IsIISInstalled == true)
{
var envValue = Environment.ExpandEnvironmentVariables(ANCMTestFlagsEnvironmentVariable);
if (envValue.ToLower().Contains(ANCMTestFlagsUseIISExpressContext.ToLower()))
{
TestUtility.LogInformation("UseIISExpress is set");
throw new System.ApplicationException("'ANCMTestServerType' environment variable is set to 'true'");
}
else
{
TestUtility.LogInformation("UseIISExpress is not set");
}
// 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");
}
TestUtility.ResetHelper(ResetHelperMode.KillWorkerProcess);
// Reset applicationhost.config
TestUtility.LogInformation("Restoring applicationhost.config");
IISConfigUtility.RestoreAppHostConfig(restoreFromMasterBackupFile:true);
TestUtility.StartW3svc();
// check w3svc is running after resetting applicationhost.config
if (IISConfigUtility.GetServiceStatus("w3svc") == "Running")
{
TestUtility.LogInformation("W3SVC service is restarted after restoring applicationhost.config");
}
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");
}
if (IISConfigUtility.ApppHostTemporaryBackupFileExtention == null)
{
throw new System.ApplicationException("Failed to backup applicationhost.config");
}
IISConfigUtility.IsIISReady = true;
}
} }
catch (Exception ex)
{ string siteRootPath = TestRootDirectory;
RollbackIISApplicationhostConfigFile();
TestUtility.LogInformation("We will use IISExpress instead of IIS: " + ex.Message);
}
string siteRootPath = Path.Combine(Environment.ExpandEnvironmentVariables("%SystemDrive%") + @"\", "inetpub", "ANCMTest");
if (!Directory.Exists(siteRootPath)) if (!Directory.Exists(siteRootPath))
{ {
//
// Create a new directory and set the write permission for the SID of AuthenticatedUser
//
Directory.CreateDirectory(siteRootPath); Directory.CreateDirectory(siteRootPath);
DirectorySecurity sec = Directory.GetAccessControl(siteRootPath);
SecurityIdentifier authenticatedUser = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
sec.AddAccessRule(new FileSystemAccessRule(authenticatedUser, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(siteRootPath, sec);
} }
foreach (string directory in Directory.GetDirectories(siteRootPath)) foreach (string directory in Directory.GetDirectories(siteRootPath))
@ -208,18 +329,12 @@ namespace AspNetCoreModule.Test.Framework
} }
} }
if (InitializeTestMachine.UsePrivateAspNetCoreFile == true) //
// Intialize Private ANCM files for Full IIS server or IISExpress
//
if (TestFlags.Enabled(TestFlags.UsePrivateANCM))
{ {
PreparePrivateANCMFiles(); PreparePrivateANCMFiles();
// update applicationhost.config for IIS server
if (IISConfigUtility.IsIISReady)
{
using (var iisConfig = new IISConfigUtility(ServerType.IIS, null))
{
iisConfig.AddModule("AspNetCoreModule", FullIisAspnetcore_path, null);
}
}
} }
_InitializeTestMachineCompleted = true; _InitializeTestMachineCompleted = true;
@ -231,7 +346,7 @@ namespace AspNetCoreModule.Test.Framework
if (_InitializeTestMachineCompleted) if (_InitializeTestMachineCompleted)
{ {
break; break;
} }
else else
{ {
TestUtility.LogInformation("InitializeTestMachine::InitializeTestMachine() Waiting..."); TestUtility.LogInformation("InitializeTestMachine::InitializeTestMachine() Waiting...");
@ -312,12 +427,24 @@ namespace AspNetCoreModule.Test.Framework
{ {
throw new ApplicationException("aspnetcore.dll is not available; check if there is any build issue!!!"); throw new ApplicationException("aspnetcore.dll is not available; check if there is any build issue!!!");
} }
// create an extra private copy of the private file on IIS directory
if (InitializeTestMachine.UsePrivateAspNetCoreFile == true)
{
bool updateSuccess = false;
//
// NOTE:
// ANCM schema file can't be overwritten here
// If there is any schema change, that should be updated with installing setup or manually copied with the new schema file.
//
if (TestFlags.Enabled(TestFlags.UseIISExpress))
{
//
// Initialize 32 bit IisExpressAspnetcore_path
//
IisExpressAspnetcore_path = Path.Combine(outputPath, "x64", "aspnetcore.dll");
IisExpressAspnetcore_X86_path = Path.Combine(outputPath, "Win32", "aspnetcore.dll");
}
else // if use Full IIS server
{
bool updateSuccess = false;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
updateSuccess = false; updateSuccess = false;
@ -326,28 +453,16 @@ namespace AspNetCoreModule.Test.Framework
TestUtility.ResetHelper(ResetHelperMode.KillWorkerProcess); TestUtility.ResetHelper(ResetHelperMode.KillWorkerProcess);
TestUtility.ResetHelper(ResetHelperMode.StopW3svcStartW3svc); TestUtility.ResetHelper(ResetHelperMode.StopW3svcStartW3svc);
Thread.Sleep(1000); Thread.Sleep(1000);
string from = Path.Combine(outputPath, "x64", "aspnetcore.dll"); // Copy private file on Inetsrv directory
TestUtility.FileCopy(from, FullIisAspnetcore_path, overWrite:true, ignoreExceptionWhileDeletingExistingFile:false); TestUtility.FileCopy(Path.Combine(outputPath, "x64", "aspnetcore.dll"), FullIisAspnetcore_path, overWrite: true, ignoreExceptionWhileDeletingExistingFile: false);
TestUtility.FileCopy(from, IisExpressAspnetcore_path, overWrite: true, ignoreExceptionWhileDeletingExistingFile: false);
// NOTE: schema file can't be overwritten, if there is any schema change, that should be updated manually
from = Path.Combine(outputPath, "x64", "aspnetcore_schema.xml");
TestUtility.FileCopy(from, FullIisAspnetcoreSchema_path, overWrite: false, ignoreExceptionWhileDeletingExistingFile: false);
TestUtility.FileCopy(from, IisExpressAspnetcoreSchema_path, overWrite: false, ignoreExceptionWhileDeletingExistingFile: false);
if (TestUtility.IsOSAmd64) if (TestUtility.IsOSAmd64)
{ {
from = Path.Combine(outputPath, "Win32", "aspnetcore.dll");
TestUtility.FileCopy(from, FullIisAspnetcore_X86_path, overWrite: true, ignoreExceptionWhileDeletingExistingFile: false); // Copy 32bit private file on Inetsrv directory
TestUtility.FileCopy(from, IisExpressAspnetcore_X86_path, overWrite: true, ignoreExceptionWhileDeletingExistingFile: false); TestUtility.FileCopy(Path.Combine(outputPath, "Win32", "aspnetcore.dll"), FullIisAspnetcore_X86_path, overWrite: true, ignoreExceptionWhileDeletingExistingFile: false);
// NOTE: schema file can't be overwritten, if there is any schema change, that should be updated manually
from = Path.Combine(outputPath, "Win32", "aspnetcore_schema.xml");
TestUtility.FileCopy(from, IisExpressAspnetcoreSchema_X86_path, overWrite: false, ignoreExceptionWhileDeletingExistingFile: false);
} }
updateSuccess = true; updateSuccess = true;
} }
catch catch
@ -363,6 +478,15 @@ namespace AspNetCoreModule.Test.Framework
{ {
throw new System.ApplicationException("Failed to update aspnetcore.dll"); throw new System.ApplicationException("Failed to update aspnetcore.dll");
} }
// update applicationhost.config for IIS server with the new private ASPNET Core file name
if (TestFlags.Enabled(TestFlags.UseFullIIS))
{
using (var iisConfig = new IISConfigUtility(ServerType.IIS, null))
{
iisConfig.AddModule("AspNetCoreModule", FullIisAspnetcore_path, null);
}
}
} }
} }

View File

@ -287,7 +287,7 @@ namespace AspNetCoreModule.Test.Framework
} }
if (File.Exists(from)) if (File.Exists(from))
{ {
if (File.Exists(to) && overWrite == false) if (File.Exists(to) && !overWrite)
{ {
return; return;
} }
@ -326,7 +326,7 @@ namespace AspNetCoreModule.Test.Framework
if (File.Exists(from)) if (File.Exists(from))
{ {
if (File.Exists(to) && overWrite == false) if (File.Exists(to) && !overWrite)
{ {
return; return;
} }

View File

@ -130,6 +130,21 @@ namespace AspNetCoreModule.Test.Framework
} }
} }
public string HostNameBinding
{
get
{
if (IisServerType == ServerType.IISExpress)
{
return "localhost";
}
else
{
return "";
}
}
}
public ServerType IisServerType { get; set; } public ServerType IisServerType { get; set; }
public string IisExpressConfigPath { get; set; } public string IisExpressConfigPath { get; set; }
private int _siteId { get; set; } private int _siteId { get; set; }
@ -138,15 +153,36 @@ namespace AspNetCoreModule.Test.Framework
public TestWebSite(IISConfigUtility.AppPoolBitness appPoolBitness, string loggerPrefix = "ANCMTest", bool startIISExpress = true, bool copyAllPublishedFiles = false, bool attachAppVerifier = false) public TestWebSite(IISConfigUtility.AppPoolBitness appPoolBitness, string loggerPrefix = "ANCMTest", bool startIISExpress = true, bool copyAllPublishedFiles = false, bool attachAppVerifier = false)
{ {
_appPoolBitness = appPoolBitness; _appPoolBitness = appPoolBitness;
// //
// Default server type is IISExpress. we, however, should use IIS server instead if IIS server is ready to use. // Initialize IisServerType
// //
IisServerType = ServerType.IISExpress; if (TestFlags.Enabled(TestFlags.UseFullIIS))
if (IISConfigUtility.IsIISReady)
{ {
IisServerType = ServerType.IIS; IisServerType = ServerType.IIS;
} }
else
{
IisServerType = ServerType.IISExpress;
}
//
// Use localhost hostname for IISExpress
//
if (IisServerType == ServerType.IISExpress
&& TestFlags.Enabled(TestFlags.Wow64BitMode))
{
//
// In Wow64/IISExpress test context, always use 32 bit worker process
//
if (_appPoolBitness == IISConfigUtility.AppPoolBitness.noChange)
{
TestUtility.LogInformation("Warning!!! In Wow64, _appPoolBitness should be set with enable32bit");
_appPoolBitness = IISConfigUtility.AppPoolBitness.enable32Bit;
}
}
TestUtility.LogInformation("TestWebSite::TestWebSite() Start"); TestUtility.LogInformation("TestWebSite::TestWebSite() Start");
@ -177,7 +213,7 @@ namespace AspNetCoreModule.Test.Framework
{ {
postfix = Path.GetRandomFileName(); postfix = Path.GetRandomFileName();
siteName = loggerPrefix.Replace(" ", "") + "_" + postfix; siteName = loggerPrefix.Replace(" ", "") + "_" + postfix;
siteRootPath = Path.Combine(Environment.ExpandEnvironmentVariables("%SystemDrive%") + @"\", "inetpub", "ANCMTest", siteName); siteRootPath = Path.Combine(InitializeTestMachine.TestRootDirectory, siteName);
if (!Directory.Exists(siteRootPath)) if (!Directory.Exists(siteRootPath))
{ {
break; break;
@ -199,14 +235,14 @@ namespace AspNetCoreModule.Test.Framework
// Currently we use DotnetCore v2.0 // Currently we use DotnetCore v2.0
// //
string publishPath = Path.Combine(srcPath, "bin", "Debug", "netcoreapp2.0", "publish"); string publishPath = Path.Combine(srcPath, "bin", "Debug", "netcoreapp2.0", "publish");
string publishPathOutput = Path.Combine(Environment.ExpandEnvironmentVariables("%SystemDrive%") + @"\", "inetpub", "ANCMTest", "publishPathOutput"); string publishPathOutput = Path.Combine(InitializeTestMachine.TestRootDirectory, "publishPathOutput");
// //
// Publish aspnetcore app // Publish aspnetcore app
// //
if (_publishedAspnetCoreApp != true) if (_publishedAspnetCoreApp != true)
{ {
string argumentForDotNet = "publish " + srcPath; string argumentForDotNet = "publish " + srcPath + " --framework netcoreapp2.0";
TestUtility.LogInformation("TestWebSite::TestWebSite() StandardTestApp is not published, trying to publish on the fly: dotnet.exe " + argumentForDotNet); TestUtility.LogInformation("TestWebSite::TestWebSite() StandardTestApp is not published, trying to publish on the fly: dotnet.exe " + argumentForDotNet);
TestUtility.DeleteDirectory(publishPath); TestUtility.DeleteDirectory(publishPath);
TestUtility.RunCommand("dotnet", argumentForDotNet); TestUtility.RunCommand("dotnet", argumentForDotNet);
@ -227,7 +263,7 @@ namespace AspNetCoreModule.Test.Framework
{ {
argumentFileName = "AspNetCoreModule.TestSites.Standard.dll"; argumentFileName = "AspNetCoreModule.TestSites.Standard.dll";
} }
iisConfig.CreateSite(tempSiteName, publishPathOutput, tempId, tempId); iisConfig.CreateSite(tempSiteName, HostNameBinding, publishPathOutput, tempId, tempId);
iisConfig.SetANCMConfig(tempSiteName, "/", "arguments", Path.Combine(publishPathOutput, argumentFileName)); iisConfig.SetANCMConfig(tempSiteName, "/", "arguments", Path.Combine(publishPathOutput, argumentFileName));
iisConfig.DeleteSite(tempSiteName); iisConfig.DeleteSite(tempSiteName);
} }
@ -306,12 +342,26 @@ namespace AspNetCoreModule.Test.Framework
} }
} }
if (InitializeTestMachine.UsePrivateAspNetCoreFile == true && IisServerType == ServerType.IISExpress) if (TestFlags.Enabled(TestFlags.UsePrivateANCM) && IisServerType == ServerType.IISExpress)
{ {
iisConfig.AddModule("AspNetCoreModule", ("%IIS_BIN%\\" + InitializeTestMachine.PrivateFileName), null); if (TestUtility.IsOSAmd64)
{
if (_appPoolBitness == IISConfigUtility.AppPoolBitness.enable32Bit)
{
iisConfig.AddModule("AspNetCoreModule", (InitializeTestMachine.IisExpressAspnetcore_X86_path), null);
}
else
{
iisConfig.AddModule("AspNetCoreModule", (InitializeTestMachine.IisExpressAspnetcore_path), null);
}
}
else
{
iisConfig.AddModule("AspNetCoreModule", (InitializeTestMachine.IisExpressAspnetcore_path), null);
}
} }
iisConfig.CreateSite(siteName, RootAppContext.PhysicalPath, _siteId, TcpPort, appPoolName); iisConfig.CreateSite(siteName, HostNameBinding, RootAppContext.PhysicalPath, _siteId, TcpPort, appPoolName);
iisConfig.CreateApp(siteName, AspNetCoreApp.Name, AspNetCoreApp.PhysicalPath, appPoolName); iisConfig.CreateApp(siteName, AspNetCoreApp.Name, AspNetCoreApp.PhysicalPath, appPoolName);
iisConfig.CreateApp(siteName, WebSocketApp.Name, WebSocketApp.PhysicalPath, appPoolName); iisConfig.CreateApp(siteName, WebSocketApp.Name, WebSocketApp.PhysicalPath, appPoolName);
iisConfig.CreateApp(siteName, URLRewriteApp.Name, URLRewriteApp.PhysicalPath, appPoolName); iisConfig.CreateApp(siteName, URLRewriteApp.Name, URLRewriteApp.PhysicalPath, appPoolName);

View File

@ -12,7 +12,7 @@ namespace AspNetCoreModule.Test
public class FunctionalTest : FunctionalTestHelper, IClassFixture<InitializeTestMachine> public class FunctionalTest : FunctionalTestHelper, IClassFixture<InitializeTestMachine>
{ {
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.Default)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.noChange)] [InlineData(IISConfigUtility.AppPoolBitness.noChange)]
@ -23,7 +23,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.noChange, 5)] [InlineData(IISConfigUtility.AppPoolBitness.noChange, 5)]
@ -36,7 +36,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, 25, 19, false)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, 25, 19, false)]
@ -57,7 +57,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, 10)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, 10)]
@ -70,7 +70,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -81,7 +81,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -92,7 +92,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -103,7 +103,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -114,7 +114,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -125,7 +125,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData("ANCMTestBar", "bar", "bar", IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData("ANCMTestBar", "bar", "bar", IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -142,7 +142,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -153,7 +153,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -164,7 +164,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.Default)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789")] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789")]
@ -175,7 +175,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.Default)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -186,7 +186,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, 10)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, 10)]
@ -197,7 +197,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, "00:02:00")] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, "00:02:00")]
@ -210,7 +210,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -221,7 +221,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, "dotnet.exe", "./")] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, "dotnet.exe", "./")]
@ -234,7 +234,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, true)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, true)]
@ -247,7 +247,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, true, true)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, true, true)]
@ -260,7 +260,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -271,7 +271,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -282,7 +282,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, "MS-ASPNETCORE", "f")] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, "MS-ASPNETCORE", "f")]
@ -297,7 +297,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, true)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit, true)]
@ -309,7 +309,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.noChange, false, DoAppVerifierTest_StartUpMode.UseGracefulShutdown, DoAppVerifierTest_ShutDownMode.RecycleAppPool, 1)] [InlineData(IISConfigUtility.AppPoolBitness.noChange, false, DoAppVerifierTest_StartUpMode.UseGracefulShutdown, DoAppVerifierTest_ShutDownMode.RecycleAppPool, 1)]
@ -325,7 +325,7 @@ namespace AspNetCoreModule.Test
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)] [InlineData(IISConfigUtility.AppPoolBitness.enable32Bit)]
@ -339,7 +339,7 @@ namespace AspNetCoreModule.Test
// NOTE: below test scenarios are not valid for Win7 OS // NOTE: below test scenarios are not valid for Win7 OS
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "IIS does not support Websocket on Win7")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "IIS does not support Websocket on Win7")]
@ -353,7 +353,7 @@ namespace AspNetCoreModule.Test
} }
[ConditionalTheory] [ConditionalTheory]
[ANCMTestSkipCondition("%ANCMTestFlags%")] [ANCMTestFlags(TestFlags.RequireRunAsAdministrator)]
[OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)] [OSSkipCondition(OperatingSystems.MacOSX)]
[OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "WAS does not handle private memory limitation with Job object on Win7")] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, SkipReason = "WAS does not handle private memory limitation with Job object on Win7")]
@ -363,5 +363,5 @@ namespace AspNetCoreModule.Test
{ {
return DoRecylingAppPoolTest(appPoolBitness); return DoRecylingAppPoolTest(appPoolBitness);
} }
} }
} }

View File

@ -23,68 +23,31 @@ using Microsoft.AspNetCore.Testing.xunit;
namespace AspNetCoreModule.Test namespace AspNetCoreModule.Test
{ {
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class ANCMTestSkipCondition : Attribute, ITestCondition public class ANCMTestFlags : Attribute, ITestCondition
{ {
private readonly string _environmentVariableName; private readonly string _attributeValue;
public ANCMTestSkipCondition(string environmentVariableName) public ANCMTestFlags(string attributeValue)
{ {
_environmentVariableName = environmentVariableName; _attributeValue = attributeValue.ToString();
} }
public bool IsMet public bool IsMet
{ {
get get
{ {
bool result = true; if (InitializeTestMachine.GlobalTestFlags.Contains(TestFlags.SkipTest))
if (_environmentVariableName == InitializeTestMachine.ANCMTestFlagsEnvironmentVariable)
{ {
var envValue = Environment.ExpandEnvironmentVariables(_environmentVariableName); AdditionalInfo = TestFlags.SkipTest + " is set";
if (string.IsNullOrEmpty(envValue)) return false;
{
envValue = InitializeTestMachine.ANCMTestFlagsDefaultContext;
}
else
{
envValue += ";" + InitializeTestMachine.ANCMTestFlagsDefaultContext;
}
// split tokens with ';'
var tokens = envValue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string token in tokens)
{
if (token.Equals(InitializeTestMachine.ANCMTestFlagsDefaultContext, StringComparison.InvariantCultureIgnoreCase))
{
try
{
if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
{
throw new System.InvalidOperationException("this should be started with x64 process mode on 64 bit machine");
}
bool isElevated;
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
if (!isElevated)
{
throw new System.ApplicationException("this should be started as an administrator");
}
}
catch (Exception ex)
{
AdditionalInfo = ex.Message;
result = false;
}
}
if (token.Equals(InitializeTestMachine.ANCMTestFlagsTestSkipContext, StringComparison.InvariantCultureIgnoreCase))
{
AdditionalInfo = InitializeTestMachine.ANCMTestFlagsTestSkipContext + " is set";
result = false;
}
}
} }
return result;
if (_attributeValue == TestFlags.RequireRunAsAdministrator
&& !InitializeTestMachine.GlobalTestFlags.Contains(TestFlags.RunAsAdministrator))
{
AdditionalInfo = _attributeValue + " is not belong to the given global test context(" + InitializeTestMachine.GlobalTestFlags + ")";
return false;
}
return true;
} }
} }
@ -92,7 +55,7 @@ namespace AspNetCoreModule.Test
{ {
get get
{ {
return $"Skip condition: {_environmentVariableName}: this test case is skipped becauset {AdditionalInfo}."; return $"Skip condition: ANCMTestFlags: this test case is skipped becauset {AdditionalInfo}.";
} }
} }
@ -998,7 +961,7 @@ namespace AspNetCoreModule.Test
} }
int y = Convert.ToInt32(TestUtility.GetProcessWMIAttributeValue("w3wp.exe", "Handle", userName)); int y = Convert.ToInt32(TestUtility.GetProcessWMIAttributeValue("w3wp.exe", "Handle", userName));
Assert.True(x == y && foundVSJit == false, "worker process is not recycled after 30 seconds"); Assert.True(x == y && !foundVSJit, "worker process is not recycled after 30 seconds");
string backupPocessIdBackendProcess = await GetResponse(testSite.AspNetCoreApp.GetUri("GetProcessId"), HttpStatusCode.OK); string backupPocessIdBackendProcess = await GetResponse(testSite.AspNetCoreApp.GetUri("GetProcessId"), HttpStatusCode.OK);
string newPocessIdBackendProcess = backupPocessIdBackendProcess; string newPocessIdBackendProcess = backupPocessIdBackendProcess;
@ -1322,7 +1285,7 @@ namespace AspNetCoreModule.Test
string publicKey = iisConfig.GetCertificatePublicKey(thumbPrintForClientAuthentication, @"Cert:\CurrentUser\My"); string publicKey = iisConfig.GetCertificatePublicKey(thumbPrintForClientAuthentication, @"Cert:\CurrentUser\My");
bool setPasswordSeperately = false; bool setPasswordSeperately = false;
if (testSite.IisServerType == ServerType.IISExpress && IISConfigUtility.IsIISInstalled == true) if (testSite.IisServerType == ServerType.IISExpress)
{ {
setPasswordSeperately = true; setPasswordSeperately = true;
iisConfig.EnableOneToOneClientCertificateMapping(testSite.SiteName, ".\\" + userName, null, publicKey); iisConfig.EnableOneToOneClientCertificateMapping(testSite.SiteName, ".\\" + userName, null, publicKey);
@ -1934,7 +1897,7 @@ namespace AspNetCoreModule.Test
TestUtility.ResetHelper(ResetHelperMode.KillWorkerProcess); TestUtility.ResetHelper(ResetHelperMode.KillWorkerProcess);
// cleanup windbg process incase it is still running // cleanup windbg process incase it is still running
if (testResult == false) if (!testResult)
{ {
TestUtility.RunPowershellScript("stop-process -Name windbg -Force -Confirm:$false 2> $null"); TestUtility.RunPowershellScript("stop-process -Name windbg -Force -Confirm:$false 2> $null");
} }
@ -1984,7 +1947,7 @@ namespace AspNetCoreModule.Test
// Verify test result // Verify test result
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
if (DoVerifyDataSentAndReceived(websocketClient) == false) if (!DoVerifyDataSentAndReceived(websocketClient))
{ {
// retrying after 1 second sleeping // retrying after 1 second sleeping
Thread.Sleep(1000); Thread.Sleep(1000);
@ -2210,7 +2173,7 @@ namespace AspNetCoreModule.Test
result = reader.ReadToEnd(); result = reader.ReadToEnd();
outputStream.Close(); outputStream.Close();
} }
} }
} }
else else
{ {