public void TestIisExpressLoad() { var directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Environment.SetEnvironmentVariable("JEXUS_TEST_HOME", directoryName); if (directoryName == null) { return; } string Current = Path.Combine(directoryName, @"applicationHost.config"); string Original = Path.Combine(directoryName, @"original2.config"); string Expected = Path.Combine(directoryName, @"expected.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); TestHelper.CopySiteConfig(directoryName, "original.config"); #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif TestCases.TestIisExpress(server, Current); { // reorder entities to match IIS result. var file = XDocument.Load(Current); var root = file.Root; if (root == null) { return; } var pool = root.XPathSelectElement("/configuration/system.applicationHost/applicationPools/add[@name='Clr4IntegratedAppPool']"); pool.SetAttributeValue("managedPipelineMode", "Integrated"); var windows = root.XPathSelectElement("/configuration/location[@path='WebSite2']/system.webServer/security/authentication/windowsAuthentication"); windows.SetAttributeValue("enabled", true); var security = root.XPathSelectElement("/configuration/location[@path='WebSite1']/system.webServer/security"); security.Remove(); var httpLogging = root.XPathSelectElement("/configuration/location[@path='WebSite1']/system.webServer/httpLogging"); httpLogging.AddAfterSelf(security); var extended = windows.Element("extendedProtection"); extended?.SetAttributeValue("flags", "None"); #if IIS var asp = root.XPathSelectElement("/configuration/system.webServer/asp/comPlus"); asp.Remove(); #endif file.Save(Current); } { // reorder entities to match IIS result. var file = XDocument.Load(TestHelper.GetSiteConfig(directoryName)); var root = file.Root; if (root == null) { return; } var rewrite = root.XPathSelectElement("/configuration/system.webServer/rewrite"); var urlCompression = root.XPathSelectElement("/configuration/system.webServer/urlCompression"); urlCompression.Remove(); var httpErrors = root.XPathSelectElement("/configuration/system.webServer/httpErrors"); httpErrors?.Remove(); var security = root.XPathSelectElement("/configuration/system.webServer/security"); security.Remove(); rewrite.AddAfterSelf(httpErrors, urlCompression, security); httpErrors?.Element("error")?.SetAttributeValue("prefixLanguageFilePath", string.Empty); httpErrors?.Element("error")?.SetAttributeValue("responseMode", "File"); #if !IIS // IMPORTANT: workaround an IIS issue. var document = root.XPathSelectElement("/configuration/system.webServer/defaultDocument/files/add[@value='Default.asp']"); var item = new XElement("add", new XAttribute("value", "index.htm")); document?.AddAfterSelf(item); var clear = root.XPathSelectElement("/configuration/system.webServer/defaultDocument/files/clear"); var remove = new XElement("remove", new XAttribute("value", "index.htm")); clear?.AddAfterSelf(remove); #endif file.Save(TestHelper.GetSiteConfig(directoryName)); } TestHelper.FixPhysicalPathMono(Expected); XmlAssert.Equal(Expected, Current); TestHelper.AssertSiteConfig(directoryName, "expected.config"); }
public void TestIisExpressReadOnly() { var directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Environment.SetEnvironmentVariable("JEXUS_TEST_HOME", directoryName); if (directoryName == null) { return; } string Current = Path.Combine(directoryName, @"applicationHost.config"); string Original = Path.Combine(directoryName, @"original2.config"); TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); var message = "The configuration object is read only, because it has been committed by a call to ServerManager.CommitChanges(). If write access is required, use ServerManager to get a new reference."; #if IIS var server = new ServerManager(true, Current); #else var server = new IisExpressServerManager(true, Current); #endif var exception1 = Assert.Throws <InvalidOperationException>( () => { TestCases.TestIisExpress(server); }); Assert.Equal(message, exception1.Message); // site config "Website1" var config = server.Sites[0].Applications[0].GetWebConfiguration(); // enable Windows authentication var windowsSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication"); Assert.Equal(OverrideMode.Inherit, windowsSection.OverrideMode); Assert.Equal(OverrideMode.Deny, windowsSection.OverrideModeEffective); Assert.Equal(true, windowsSection.IsLocked); Assert.Equal(false, windowsSection.IsLocallyStored); var windowsEnabled = (bool)windowsSection["enabled"]; Assert.False(windowsEnabled); var compression = config.GetSection("system.webServer/urlCompression"); Assert.Equal(OverrideMode.Inherit, compression.OverrideMode); Assert.Equal(OverrideMode.Allow, compression.OverrideModeEffective); Assert.Equal(false, compression.IsLocked); Assert.Equal(false, compression.IsLocallyStored); Assert.Equal(true, compression["doDynamicCompression"]); var compress = Assert.Throws <InvalidOperationException>(() => compression["doDynamicCompression"] = false); Assert.Equal(message, compress.Message); { // disable default document. Saved to web.config as this section can be overridden anywhere. ConfigurationSection defaultDocumentSection = config.GetSection("system.webServer/defaultDocument"); Assert.Equal(true, defaultDocumentSection["enabled"]); ConfigurationElementCollection filesCollection = defaultDocumentSection.GetCollection("files"); Assert.Equal(7, filesCollection.Count); { var first = filesCollection[0]; Assert.Equal("home1.html", first["value"]); Assert.True(first.IsLocallyStored); } var second = filesCollection[1]; Assert.Equal("Default.htm", second["value"]); Assert.False(second.IsLocallyStored); var third = filesCollection[2]; Assert.Equal("Default.asp", third["value"]); Assert.False(third.IsLocallyStored); var remove = Assert.Throws <FileLoadException>(() => filesCollection.RemoveAt(4)); Assert.Equal( "Filename: \r\nError: This configuration section cannot be modified because it has been opened for read only access\r\n\r\n", remove.Message); ConfigurationElement addElement = filesCollection.CreateElement(); var add = Assert.Throws <InvalidOperationException>(() => filesCollection.AddAt(0, addElement)); Assert.Equal(message, add.Message); Assert.Equal(7, filesCollection.Count); { var first = filesCollection[0]; Assert.Equal("home1.html", first["value"]); // TODO: why? // Assert.IsFalse(first.IsLocallyStored); } Assert.Equal(7, filesCollection.Count); var clear = Assert.Throws <InvalidOperationException>(() => filesCollection.Clear()); Assert.Equal(message, clear.Message); var delete = Assert.Throws <InvalidOperationException>(() => filesCollection.Delete()); Assert.Equal(message, delete.Message); } }