public void TestProviders() { const string Current = @"applicationHost.config"; const string Original = @"original2.config"; const string OriginalMono = @"original.mono.config"; File.Copy(Helper.IsRunningOnMono() ? OriginalMono : Original, Current, true); var directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Environment.SetEnvironmentVariable("JEXUS_TEST_HOME", directoryName); if (directoryName == null) { return; } #if IIS var server = new ServerManager(Path.Combine(directoryName, Current)); #else var server = new IisExpressServerManager(Path.Combine(directoryName, Current)); #endif var config = server.GetApplicationHostConfiguration(); var section = config.GetSection("configProtectedData"); Assert.Equal("RsaProtectedConfigurationProvider", section["defaultProvider"]); var collection = section.GetCollection("providers"); Assert.Equal(5, collection.Count); }
public void TestIisExpressSiteDefaults() { 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.TestIisSiteDefaults(server); // TODO: assert generated XML. }
public void TestIisExpressAdministration() { 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, @"administration.config"); string siteConfig = TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(original, current, true); TestHelper.FixPhysicalPathMono(current); #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif var exception = Assert.Throws <COMException>(() => server.ApplicationPools); Assert.Equal( $"Filename: \\\\?\\{current}\r\nError: The configuration section 'system.applicationHost/applicationPools' cannot be read because it is missing a section declaration\r\n\r\n", exception.Message); }
public void TestIisExpressInvalidAttribute() { 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_invalid_attribute.config"); TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var exception = Assert.Throws <COMException>( () => { TestCases.TestIisExpress(server); }); Assert.Equal( string.Format( "Filename: \\\\?\\{0}\r\nLine number: 143\r\nError: Unrecognized attribute 'testAuto'\r\n\r\n", Current), exception.Message); }
public void TestIisExpressMissingClosingTag() { 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(@"original2_missing_closing.config"); TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(Original, Current, true); //TestHelper.FixPhysicalPathMono(Current); #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var exception = Assert.Throws <COMException>( () => { TestCases.TestIisExpress(server); }); Assert.Equal( string.Format( "Filename: \\\\?\\{0}\r\nLine number: 1135\r\nError: Configuration file is not well-formed XML\r\n\r\n", Current), exception.Message); }
public async void AddSiteManaged() { const string Current = @"applicationHost.config"; const string Original = @"original.config"; const string OriginalMono = @"original.mono.config"; if (Helper.IsRunningOnMono()) { File.Copy("Website1/original.config", "Website1/web.config", true); File.Copy(OriginalMono, Current, true); } else { File.Copy("Website1\\original.config", "Website1\\web.config", true); File.Copy(Original, Current, true); } Environment.SetEnvironmentVariable( "JEXUS_TEST_HOME", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); var serverManager = new IisExpressServerManager(Current); var sites = serverManager.Sites; var site = new Site(sites); site.Name = @"Contoso"; site.Id = 2L; site.ServerAutoStart = true; var binding = new Binding(@"http", @"*:80:www.contoso.com", null, null, SslFlags.None, site.Bindings); site.Bindings.Add(binding); var application = new Application(site.Applications); application.Path = @"/"; site.Applications.Add(application); var directory = new VirtualDirectory(null, application.VirtualDirectories); directory.Path = @"/"; directory.PhysicalPath = @"C:\Inetpub\www.contoso.com\wwwroot"; application.VirtualDirectories.Add(directory); sites.Add(site); serverManager.CommitChanges(); const string Expected = @"expected_site_add.config"; const string ExpectedMono = @"expected_site_add.mono.config"; XmlAssert.Equal( Helper.IsRunningOnMono() ? Path.Combine("Main", ExpectedMono) : Path.Combine("Main", Expected), Current); }
public void TestIisExpressMissingFile() { const string Original = @"applicationHost.config"; var directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Environment.SetEnvironmentVariable("JEXUS_TEST_HOME", directoryName); if (directoryName == null) { return; } var file = Path.Combine(directoryName, Original); File.Delete(file); #if IIS var server = new ServerManager(file); #else var server = new IisExpressServerManager(file); #endif var exception = Assert.Throws <FileNotFoundException>( () => { TestCases.TestIisExpress(server); }); Assert.Equal( string.Format("Filename: \\\\?\\{0}\r\nError: Cannot read configuration file\r\n\r\n", file), exception.Message); }
public void TestIisExpressRootVirtualDirectoryOutOfOrder() { 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_root_vdir_out.config"); TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var site = server.Sites[0]; var config = site.GetWebConfiguration(); var root = config.RootSectionGroup; Assert.NotNull(root); // 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); }
public void TestIisExpressInvalidLocation() { 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"); var siteConfig = TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(original, current, true); TestHelper.FixPhysicalPathMono(current); { // add the tags var file = XDocument.Load(current); var root = file.Root; if (root == null) { return; } root.Add( new XElement("location", new XAttribute("path", "NotExist"), new XElement("system.webServer", new XElement("security", new XElement("authentication", new XElement("windowsAuthentication", new XAttribute("enabled", true))))))); file.Save(current); } #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif #if IIS var config = server.GetApplicationHostConfiguration(); var exception = Assert.Throws <FileNotFoundException>(() => config.GetSection("system.webServer/security/authentication/windowsAuthentication", "NotExist")); Assert.Equal($"Filename: \\\\?\\{current}\r\nError: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/NotExist'\r\n\r\n", exception.Message); #else var config = server.GetApplicationHostConfiguration(); var exception = Assert.Throws <FileNotFoundException>(() => config.GetSection("system.webServer/security/authentication/windowsAuthentication", "NotExist")); Assert.Equal($"Filename: \\\\?\\{current}\r\nError: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/NotExist'\r\n\r\n", exception.Message); // TODO: fix where the exception is throwed. //var exception = Assert.Throws<COMException>(() => server.Sites[0].Applications[0].GetWebConfiguration()); #endif Assert.Equal($"Filename: \\\\?\\{current}\r\nError: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/NotExist'\r\n\r\n", exception.Message); }
public void TestIisExpressRootApplicationOutOfOrder() { 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); { // add the tags var file = XDocument.Load(Current); var root = file.Root; if (root == null) { return; } var app = root.XPathSelectElement("/configuration/system.applicationHost/sites/site[@id='1']/application"); var newApp = new XElement("application"); app.AddBeforeSelf(newApp); newApp.SetAttributeValue("path", "/xxx"); var vDir = new XElement("virtualDirectory"); newApp.Add(vDir); vDir.SetAttributeValue("path", "/"); vDir.SetAttributeValue("physicalPath", @"%JEXUS_TEST_HOME%\WebSite1"); file.Save(Current); } #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var site = server.Sites[0]; var config = site.GetWebConfiguration(); { var root = config.RootSectionGroup; Assert.NotNull(root); } // 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); }
public void TestIisExpressInvalidSection() { 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"); var siteConfig = TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); { // add the section. var file = XDocument.Load(siteConfig); var root = file.Root; if (root == null) { return; } var pool = root.XPathSelectElement("/configuration/system.webServer"); var security = new XElement("security"); pool.Add(security); var authentication = new XElement("authentication"); security.Add(authentication); var windows = new XElement("windowsAuthentication"); authentication.Add(windows); windows.SetAttributeValue("enabled", true); file.Save(siteConfig); } #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var config = server.Sites[0].Applications[0].GetWebConfiguration(); var exception = Assert.Throws <FileLoadException>( () => { // enable Windows authentication var windowsSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication"); }); Assert.Equal( string.Format( "Filename: \\\\?\\{0}\r\nLine number: 11\r\nError: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=\"Deny\"), or set explicitly by a location tag with overrideMode=\"Deny\" or the legacy allowOverride=\"false\".\r\n\r\n", siteConfig), exception.Message); }
public void TestIisExpressArrSection() { 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"); var siteConfig = TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); { // Add the section. var file = XDocument.Load(siteConfig); var root = file.Root; if (root == null) { return; } var pool = root.XPathSelectElement("/configuration/system.webServer"); var unknown = new XElement("webFarms"); pool.Add(unknown); var test = new XElement("test"); unknown.Add(test); test.SetAttributeValue("test", "test"); file.Save(siteConfig); } #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var config = server.Sites[0].Applications[0].GetWebConfiguration(); var exception = Assert.Throws <COMException>( () => { // enable Windows authentication var windowsSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication"); }); #if IIS Assert.Equal(string.Format("Filename: \\\\?\\{0}\r\nError: \r\n", siteConfig), exception.Message); #else Assert.Equal("Application Request Routing Module (system.webServer/webFarms/)", exception.Data["oob"]); Assert.Equal("https://docs.microsoft.com/en-us/iis/extensions/configuring-application-request-routing-arr/define-and-configure-an-application-request-routing-server-farm#prerequisites", exception.Data["link"]); Assert.Equal(string.Format("Filename: \\\\?\\{0}\r\nLine number: 10\r\nError: Unrecognized element 'test'\r\n\r\n", siteConfig), exception.Message); #endif }
public void TestIisExpressNoRootVirtualDirectory() { 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); { // modify the path var file = XDocument.Load(current); var root = file.Root; if (root == null) { return; } var vDir = root.XPathSelectElement("/configuration/system.applicationHost/sites/site[@id='1']/application/virtualDirectory"); vDir?.SetAttributeValue("path", "/xxx"); file.Save(current); } #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif var site = server.Sites[0]; var config = site.GetWebConfiguration(); #if IIS var exception = Assert.Throws <NullReferenceException>( () => { var root = config.RootSectionGroup; }); #else var exception = Assert.Throws <FileNotFoundException>( () => { var root = config.RootSectionGroup; }); Assert.Equal( $"Filename: \\\\?\\{current}\r\nLine number: 155\r\nError: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/WebSite1'\r\n\r\n", exception.Message); #endif }
public void TestIisExpressConfigSource() { 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"); var siteConfig = TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(original, current, true); TestHelper.FixPhysicalPathMono(current); { // add the tags var file = XDocument.Load(current); var root = file.Root; if (root == null) { return; } root.Add( new XElement("location", new XAttribute("path", "WebSite1"), new XElement("system.web", new XElement("authorization", new XAttribute("configSource", Path.Combine(Path.GetDirectoryName(siteConfig), "authorization.config")))))); file.Save(current); } #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif #if IIS var config = server.Sites[0].Applications[0].GetWebConfiguration(); var exception = Assert.Throws <COMException>(() => config.GetSection("system.web/authorization")); #else // TODO: fix where the exception is throwed. var exception = Assert.Throws <COMException>(() => server.Sites[0].Applications[0].GetWebConfiguration()); #endif Assert.Equal($"Filename: \\\\?\\{current}\r\nLine number: 1120\r\nError: Unrecognized attribute 'configSource'\r\n\r\n", exception.Message); }
public void TestIisExpressBindingInvalidAddress4() { 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); { // add the tags var file = XDocument.Load(current); var root = file.Root; if (root == null) { return; } var site1 = root.XPathSelectElement("/configuration/system.applicationHost/sites/site[@id='2']/bindings"); site1?.Add( new XElement("binding", new XAttribute("protocol", "http"), new XAttribute("bindingInformation", "::"))); file.Save(current); } #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif { Binding binding = server.Sites[1].Bindings[2]; Assert.Null(binding.EndPoint); Assert.Equal("::", binding.BindingInformation); #if !IIS Assert.Equal("http://localhost", binding.ToUri()); Assert.Equal(": (http)", binding.ToShortString()); #endif } }
public void TestIisExpressInvalidAttribute() { 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); { // Remove the attribute. var file = XDocument.Load(Current); var root = file.Root; if (root == null) { return; } var pool = root.XPathSelectElement("/configuration/system.applicationHost/applicationPools/add[@name='UnmanagedClassicAppPool']"); pool.SetAttributeValue("testAuto", true); file.Save(Current); } #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var exception = Assert.Throws <COMException>( () => { TestCases.TestIisExpress(server); }); Assert.Equal( string.Format( "Filename: \\\\?\\{0}\r\nLine number: 142\r\nError: Unrecognized attribute 'testAuto'\r\n\r\n", Current), exception.Message); }
public void TestIisExpressValidatorFails() { 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); { // Remove the attribute. var file = XDocument.Load(current); var root = file.Root; if (root == null) { return; } var pool = root.XPathSelectElement("/configuration/system.applicationHost/applicationPools/add[@name='UnmanagedClassicAppPool']"); pool?.SetAttributeValue("name", string.Empty); file.Save(current); } #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif var exception = Assert.Throws <COMException>( () => { TestCases.TestIisExpress(server, current); }); Assert.Equal( $"Filename: \\\\?\\{current}\r\nLine number: 141\r\nError: The 'name' attribute is invalid. Invalid application pool name\r\n\r\n\r\n", exception.Message); }
public void TestIisExpressBindingInvalidAddress2() { 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); { // add the tags var file = XDocument.Load(Current); var root = file.Root; if (root == null) { return; } var site1 = root.XPathSelectElement("/configuration/system.applicationHost/sites/site[@id='2']/bindings"); var binding = new XElement("binding", new XAttribute("protocol", "http"), new XAttribute("bindingInformation", "1.1.1:61902:localhost")); site1.Add(binding); file.Save(Current); } #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif { Assert.Equal(IPAddress.Parse("1.1.0.1"), server.Sites[1].Bindings[2].EndPoint.Address); Assert.Equal("1.1.1:61902:localhost", server.Sites[1].Bindings[2].BindingInformation); } }
public void TestIisExpressDuplicateBindings() { 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); { // add the tags var file = XDocument.Load(current); var root = file.Root; if (root == null) { return; } var site1 = root.XPathSelectElement("/configuration/system.applicationHost/sites/site[@id='2']/bindings"); site1?.Add( new XElement("binding", new XAttribute("protocol", "http"), new XAttribute("bindingInformation", "*:61902:localhost"))); file.Save(current); } #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif { var exception = Assert.Throws <COMException>(() => server.Sites[1]); Assert.Equal($"Filename: \\\\?\\{current}\r\nLine number: 182\r\nError: Cannot add duplicate collection entry of type 'binding' with combined key attributes 'protocol, bindingInformation' respectively set to 'http, *:61902:localhost'\r\n\r\n", exception.Message); } }
public void TestIisExpressNoBinding() { 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); { // change the path. var file = XDocument.Load(current); var root = file.Root; if (root == null) { return; } var app = root.XPathSelectElement("/configuration/system.applicationHost/sites/site[@id='1']/bindings"); app.Remove(); file.Save(current); } #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif var site = server.Sites[0]; var exception = Assert.Throws <ArgumentOutOfRangeException>( () => { var binding = site.Bindings[0]; }); }
public void TestIisExpressDuplicateApplicationPools() { 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); { // add the tags var file = XDocument.Load(current); var root = file.Root; if (root == null) { return; } var pools = root.XPathSelectElement("/configuration/system.applicationHost/applicationPools"); pools?.Add( new XElement("add", new XAttribute("name", "Clr4IntegratedAppPool"))); file.Save(current); } #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif { var exception = Assert.Throws <COMException>(() => server.ApplicationPools); Assert.Equal($"Filename: \\\\?\\{current}\r\nLine number: 143\r\nError: Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'Clr4IntegratedAppPool'\r\n\r\n", exception.Message); } }
public void TestIisExpressEmptyTag2() { 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"); var siteConfig = TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); { // add the section. var file = XDocument.Load(siteConfig); var root = file.Root; if (root == null) { return; } var pool = root.XPathSelectElement("/configuration/system.webServer"); pool?.RemoveAll(); pool.Add(new XElement("security")); file.Save(siteConfig); } #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var config = server.Sites[0].Applications[0].GetWebConfiguration(); // enable Windows authentication var windowsSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication"); }
public void TestIisExpressLogFileInheritance() { 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_logfile.config"); TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif { var site = server.Sites[0]; Assert.Equal(@"%IIS_USER_HOME%\Logs", site.LogFile.Directory); Assert.Equal(LogFormat.W3c, site.LogFile.LogFormat); } { var site = server.Sites[1]; Assert.Equal(@"%IIS_USER_HOME%\Logs", site.LogFile.Directory); Assert.Equal(LogFormat.Iis, site.LogFile.LogFormat); } { var site = server.Sites[2]; Assert.Equal(@"%IIS_USER_HOME%\Logs\1", site.LogFile.Directory); Assert.Equal(LogFormat.W3c, site.LogFile.LogFormat); } }
public void TestIisExpressNoApplicationPools() { 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); { // add the tags var file = XDocument.Load(current); var root = file.Root; if (root == null) { return; } var pools = root.XPathSelectElement("/configuration/system.applicationHost/applicationPools"); pools?.Remove(); file.Save(current); } #if IIS var server = new ServerManager(current); #else var server = new IisExpressServerManager(current); #endif { var pools = server.ApplicationPools; Assert.Empty(pools); } }
public void TestIisExpressDuplicateSection() { 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, @"original3.config"); TestHelper.CopySiteConfig(directoryName, "original_duplicate_section.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var config = server.Sites[0].Applications[0].GetWebConfiguration(); var section = config.GetSection("system.webServer/defaultDocument"); Assert.Equal(true, section["enabled"]); var files = section.GetCollection("files"); Assert.Equal(8, files.Count); Assert.Equal("home2.html", files[0]["value"]); Assert.True(files[0].IsLocallyStored); Assert.Equal("home1.html", files[1]["value"]); Assert.False(files[1].IsLocallyStored); files.RemoveAt(1); server.CommitChanges(); const string Expected = @"expected3.config"; TestHelper.FixPhysicalPathMono(Expected); XmlAssert.Equal(Expected, Current); TestHelper.AssertSiteConfig(directoryName, Expected); }
public void TestIisExpressNoRootVirtualDirectory() { 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_no_root_vdir.config"); TestHelper.CopySiteConfig(directoryName, "original.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var site = server.Sites[0]; var config = site.GetWebConfiguration(); #if IIS var exception = Assert.Throws <NullReferenceException>( () => { var root = config.RootSectionGroup; }); #else var exception = Assert.Throws <FileNotFoundException>( () => { var root = config.RootSectionGroup; }); Assert.Equal(string.Format("Filename: \\\\?\\{0}\r\nLine number: 165\r\nError: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/WebSite1'\r\n\r\n", Current), exception.Message); #endif }
public void TestIisExpressUnknownSection() { 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_unknown_section.config"); File.Copy(Original, Current, true); TestHelper.FixPhysicalPathMono(Current); #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif var config = server.Sites[0].Applications[0].GetWebConfiguration(); var exception = Assert.Throws <COMException>( () => { // enable Windows authentication var windowsSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication"); }); var siteConfig = Path.Combine(directoryName, "WebSite1", "web.config"); #if IIS Assert.Equal(string.Format("Filename: \\\\?\\{0}\r\nError: \r\n", siteConfig), exception.Message); #else Assert.Equal(string.Format("Filename: \\\\?\\{0}\r\nLine number: 10\r\nError: Unrecognized element 'test'\r\n\r\n", siteConfig), exception.Message); #endif }
public override void HandleDoubleClick(MainForm mainForm) { if (ServerManager != null) { return; } if (_status == NodeStatus.Loading) { return; } MainForm = mainForm; mainForm.DisconnectButton.Enabled = false; _status = NodeStatus.Loading; mainForm.ShowInfo($"Connecting to {HostName}..."); try { if (Mode == WorkingMode.IisExpress) { ServerManager = new IisExpressServerManager(HostName); } else if (Mode == WorkingMode.Iis) { ServerManager = new IisServerManager(false, HostName); } else { ServerManager = new JexusServerManager(HostName, Credentials); } ServerManager.Name = DisplayName; if (Mode == WorkingMode.Jexus) { SetHandler(); var server = (JexusServerManager)ServerManager; var version = AsyncHelper.RunSync(() => server.GetVersionAsync()); if (version == null) { MessageBox.Show("Authentication failed.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); ServerManager = null; _status = NodeStatus.Default; mainForm.DisconnectButton.Enabled = true; return; } if (version < JexusServerManager.MinimumServerVersion) { var toContinue = MessageBox.Show( $"The server version is {version}, while minimum compatible version is {JexusServerManager.MinimumServerVersion}. Making changes might corrupt server configuration. Do you want to continue?", Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (toContinue != DialogResult.Yes) { ServerManager = null; _status = NodeStatus.Default; mainForm.DisconnectButton.Enabled = true; return; } } var conflict = AsyncHelper.RunSync(() => server.HelloAsync()); if (Environment.MachineName != conflict) { MessageBox.Show( $"The server is also connected to {conflict}. Making changes on multiple clients might corrupt server configuration.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } ServerManager.IsLocalhost = IsLocalhost; LoadServer(mainForm.ApplicationPoolsMenu, mainForm.SitesMenu, mainForm.SiteMenu); Tag = ServerManager; mainForm.EnableServerMenuItems(true); _status = NodeStatus.Loaded; mainForm.DisconnectButton.Enabled = true; } catch (Exception ex) { File.WriteAllText(DialogHelper.DebugLog, ex.ToString()); var last = ex; while (last is AggregateException) { last = last.InnerException; } var message = new StringBuilder(); message.AppendLine("Could not connect to the specified computer.") .AppendLine() .AppendFormat("Details: {0}", last?.Message); MessageBox.Show(message.ToString(), mainForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); ServerManager = null; _status = NodeStatus.Default; mainForm.DisconnectButton.Enabled = true; } finally { mainForm.HideInfo(); } }
public void TestIisExpressMissingWebsiteConfig() { 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); File.Delete(TestHelper.GetSiteConfig(directoryName)); #if IIS var server = new ServerManager(Current); #else var server = new IisExpressServerManager(Current); #endif TestCases.TestIisExpressMissingWebsiteConfig(server); { // 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"); #if !IIS 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"); #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 top = root.XPathSelectElement("/configuration/system.webServer/defaultDocument"); var staticContent = root.XPathSelectElement("/configuration/system.webServer/staticContent"); staticContent?.Remove(); top.AddBeforeSelf(staticContent); #if !IIS 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"); // IMPORTANT: workaround an IIS issue. var document = root.XPathSelectElement("/configuration/system.webServer/defaultDocument/files/add[@value='index.htm']"); var item = new XElement("add", new XAttribute("value", "index.html")); document?.AddAfterSelf(item); var clear = root.XPathSelectElement("/configuration/system.webServer/defaultDocument/files/clear"); var remove = new XElement("remove", new XAttribute("value", "index.html")); clear?.AddAfterSelf(remove); #endif file.Save(TestHelper.GetSiteConfig(directoryName)); } TestHelper.FixPhysicalPathMono(Expected); XmlAssert.Equal(Expected, Current); TestHelper.AssertSiteConfig(directoryName, "expected1.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); } }