public void Throws_WithMismatchedXmlDeclaration(string input1, string input2) { Assert.Throws <EqualException>(() => XmlAssert.Equal(input1, input2)); }
public void BigXmlDocumentIsSameWithSelf() { XmlAssert.AreEqual(bigXml, bigXml); }
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, @"original2.config"); var siteConfig = 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 location = root.XPathSelectElement("/configuration/location[@path='WebSite2']"); var newLocation = new XElement("location"); location.AddAfterSelf(newLocation); newLocation.SetAttributeValue("path", "WebSite1"); var webServer = new XElement("system.webServer"); newLocation.Add(webServer); var document = new XElement("defaultDocument"); document.SetAttributeValue("enabled", false); webServer.Add(document); var files = new XElement("files"); document.Add(files); var add = new XElement("add"); add.SetAttributeValue("value", "home1.html"); files.Add(add); file.Save(Current); } { // Add the section. var file = XDocument.Load(siteConfig); var root = file.Root; if (root == null) { return; } var doc = root.XPathSelectElement("/configuration/system.webServer/defaultDocument"); doc.SetAttributeValue("enabled", true); var add = root.XPathSelectElement("/configuration/system.webServer/defaultDocument/files/add"); add.SetAttributeValue("value", "home2.html"); 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 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 ReturnsSuccessfully_WithMatchingTextNodes(string input1, string input2) { XmlAssert.Equal(input1, input2); }
void AttributesAndNamespaces(XPathNavigator nav, string label) { XmlReader r = nav.ReadSubtree(); XmlAssert.AssertNode(label + "#1", r, // NodeType, Depth, IsEmptyElement XmlNodeType.None, 0, false, // Name, Prefix, LocalName, NamespaceURI String.Empty, String.Empty, String.Empty, String.Empty, // Value, HasValue, AttributeCount, HasAttributes String.Empty, false, 0, false); Assert.IsTrue(r.Read(), label + "#2"); XmlAssert.AssertNode(label + "#3", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Element, 0, false, // Name, Prefix, LocalName, NamespaceURI "root", String.Empty, "root", "urn:default", // Value, HasValue, AttributeCount, HasAttributes String.Empty, false, 4, true); // Namespaces Assert.IsTrue(r.MoveToAttribute("xmlns:x"), label + "#4"); XmlAssert.AssertNode(label + "#5", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Attribute, 1, false, // Name, Prefix, LocalName, NamespaceURI "xmlns:x", "xmlns", "x", "http://www.w3.org/2000/xmlns/", // Value, HasValue, AttributeCount, HasAttributes "urn:foo", true, 4, true); Assert.IsTrue(r.ReadAttributeValue(), label + "#6"); ///* MS.NET has a bug here XmlAssert.AssertNode(label + "#7", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Text, 2, false, // Name, Prefix, LocalName, NamespaceURI String.Empty, String.Empty, String.Empty, String.Empty, // Value, HasValue, AttributeCount, HasAttributes "urn:foo", true, 4, true); //*/ Assert.IsFalse(r.ReadAttributeValue(), label + "#8"); Assert.IsTrue(r.MoveToAttribute("xmlns"), label + "#9"); XmlAssert.AssertNode(label + "#10", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Attribute, 1, false, // Name, Prefix, LocalName, NamespaceURI "xmlns", String.Empty, "xmlns", "http://www.w3.org/2000/xmlns/", // Value, HasValue, AttributeCount, HasAttributes "urn:default", true, 4, true); Assert.IsTrue(r.ReadAttributeValue(), label + "#11"); ///* MS.NET has a bug here XmlAssert.AssertNode(label + "#12", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Text, 2, false, // Name, Prefix, LocalName, NamespaceURI String.Empty, String.Empty, String.Empty, String.Empty, // Value, HasValue, AttributeCount, HasAttributes "urn:default", true, 4, true); //*/ Assert.IsFalse(r.ReadAttributeValue(), label + "#13"); // Attributes Assert.IsTrue(r.MoveToAttribute("attr"), label + "#14"); XmlAssert.AssertNode(label + "#15", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Attribute, 1, false, // Name, Prefix, LocalName, NamespaceURI "attr", String.Empty, "attr", String.Empty, // Value, HasValue, AttributeCount, HasAttributes "value", true, 4, true); Assert.IsTrue(r.ReadAttributeValue(), label + "#16"); XmlAssert.AssertNode(label + "#17", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Text, 2, false, // Name, Prefix, LocalName, NamespaceURI String.Empty, String.Empty, String.Empty, String.Empty, // Value, HasValue, AttributeCount, HasAttributes "value", true, 4, true); Assert.IsFalse(r.ReadAttributeValue(), label + "#18"); Assert.IsTrue(r.MoveToAttribute("x:a2"), label + "#19"); XmlAssert.AssertNode(label + "#20", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Attribute, 1, false, // Name, Prefix, LocalName, NamespaceURI "x:a2", "x", "a2", "urn:foo", // Value, HasValue, AttributeCount, HasAttributes "v2", true, 4, true); Assert.IsTrue(r.ReadAttributeValue(), label + "#21"); XmlAssert.AssertNode(label + "#22", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Text, 2, false, // Name, Prefix, LocalName, NamespaceURI String.Empty, String.Empty, String.Empty, String.Empty, // Value, HasValue, AttributeCount, HasAttributes "v2", true, 4, true); Assert.IsTrue(r.MoveToElement(), label + "#24"); Assert.IsTrue(r.Read(), label + "#25"); XmlAssert.AssertNode(label + "#26", r, // NodeType, Depth, IsEmptyElement XmlNodeType.EndElement, 0, false, // Name, Prefix, LocalName, NamespaceURI "root", String.Empty, "root", "urn:default", // Value, HasValue, AttributeCount, HasAttributes String.Empty, false, 0, false); Assert.IsFalse(r.Read(), label + "#27"); }
public 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); const string Expected = @"expected_site_add.config"; var document = XDocument.Load(Current); var node = document.Root.XPathSelectElement("/configuration/system.applicationHost/sites"); var siteNode = new XElement("site"); siteNode.SetAttributeValue("name", "Contoso"); siteNode.SetAttributeValue("id", "2"); var bindingsNode = new XElement("bindings"); siteNode.Add(bindingsNode); node?.Add(siteNode); var bindingNode = new XElement("binding"); bindingNode.SetAttributeValue("protocol", "http"); bindingNode.SetAttributeValue("bindingInformation", @"*:80:www.contoso.com"); bindingsNode.Add(bindingNode); var appNode = new XElement("application"); appNode.SetAttributeValue("path", "/"); siteNode.Add(appNode); var vDirNode = new XElement("virtualDirectory"); vDirNode.SetAttributeValue("path", "/"); vDirNode.SetAttributeValue("physicalPath", @"C:\Inetpub\www.contoso.com\wwwroot"); appNode.Add(vDirNode); document.Save(Expected); 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(); XmlAssert.Equal(Expected, Current); }
public void XmlEqualsWithTextReaderFail() { XmlAssert.XmlEquals(new StringReader(_xmlTrueTest), new StringReader(_xmlFalseTest)); }
public void TestMoveUp() { SetUp(); const string Expected = @"expected_add.site.config"; var document = XDocument.Load(Current); var node = new XElement("location"); node.SetAttributeValue("path", "WebSite1"); document.Root.Add(node); var web = new XElement("system.webServer"); node.Add(web); var content = new XElement("modules"); web.Add(content); var clear = new XElement("clear"); content.Add(clear); var all = document.Root.XPathSelectElement("/configuration/location[@path='']/system.webServer/modules"); foreach (var element in all.Elements()) { content.Add(element); } content.LastNode.Remove(); var add = new XElement("add"); add.SetAttributeValue("name", "test"); add.SetAttributeValue("type", "test1"); content.Add(add); var one = new XElement("add"); one.SetAttributeValue("preCondition", "managedHandler,runtimeVersionv4.0"); one.SetAttributeValue("name", "ScriptModule-4.0"); one.SetAttributeValue("type", "System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); content.Add(one); document.Save(Expected); var item = new ModulesItem(null); item.Name = "test"; item.Type = "test1"; item.IsManaged = true; _feature.AddItem(item); var last = 44; var previous = last - 1; _feature.SelectedItem = _feature.Items[last]; var expected = "test"; Assert.Equal(expected, _feature.Items[last].Name); var original = "ScriptModule-4.0"; Assert.Equal(original, _feature.Items[previous].Name); _feature.MoveUp(); Assert.NotNull(_feature.SelectedItem); Assert.Equal(expected, _feature.SelectedItem.Name); Assert.Equal(expected, _feature.Items[previous].Name); Assert.Equal(original, _feature.Items[last].Name); XmlAssert.Equal(Expected, Current); XmlAssert.Equal(Path.Combine("Website1", "original.config"), Path.Combine("Website1", "web.config")); }
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 ServerManager(Current) { Mode = WorkingMode.IisExpress }; 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 TestMoveDown() { SetUp(); const string Expected = @"expected_add.site.config"; var document = XDocument.Load(Current); var node = new XElement("location"); node.SetAttributeValue("path", "WebSite1"); document.Root.Add(node); var web = new XElement("system.webServer"); node.Add(web); var content = new XElement("handlers"); web.Add(content); var remove = new XElement("remove"); remove.SetAttributeValue("name", "StaticFile"); content.Add(remove); var add = new XElement("add"); add.SetAttributeValue("resourceType", "File"); add.SetAttributeValue("modules", ""); add.SetAttributeValue("name", "test"); add.SetAttributeValue("path", "*"); add.SetAttributeValue("verb", "*"); content.Add(add); var one = new XElement("add"); one.SetAttributeValue("modules", "StaticFileModule,DefaultDocumentModule,DirectoryListingModule"); one.SetAttributeValue("name", "StaticFile"); one.SetAttributeValue("path", "*"); one.SetAttributeValue("requireAccess", "Read"); one.SetAttributeValue("resourceType", "Either"); one.SetAttributeValue("verb", "*"); content.Add(one); document.Save(Expected); var item = new HandlersItem(null); item.Name = "test"; item.Path = "*"; _feature.AddItem(item); var last = 82; var previous = last - 1; _feature.SelectedItem = _feature.Items[previous]; var expected = "test"; Assert.Equal(expected, _feature.Items[last].Name); var original = "StaticFile"; Assert.Equal(original, _feature.Items[previous].Name); _feature.MoveDown(); Assert.NotNull(_feature.SelectedItem); Assert.Equal(original, _feature.SelectedItem.Name); Assert.Equal(expected, _feature.Items[previous].Name); Assert.Equal(original, _feature.Items[last].Name); XmlAssert.Equal(Expected, Current); XmlAssert.Equal(Path.Combine("Website1", "original.config"), Path.Combine("Website1", "web.config")); }
public async void AddSite() { 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 ServerManager(Current) { Mode = WorkingMode.IisExpress }; Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElementCollection sitesCollection = sitesSection.GetCollection(); ConfigurationElement siteElement = sitesCollection.CreateElement("site"); siteElement["name"] = @"Contoso"; siteElement["id"] = 2; siteElement["serverAutoStart"] = true; ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings"); ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding"); bindingElement["protocol"] = @"http"; bindingElement["bindingInformation"] = @"*:80:www.contoso.com"; bindingsCollection.Add(bindingElement); ConfigurationElementCollection siteCollection = siteElement.GetCollection(); ConfigurationElement applicationElement = siteCollection.CreateElement("application"); applicationElement["path"] = @"/"; ConfigurationElementCollection applicationCollection = applicationElement.GetCollection(); ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory"); virtualDirectoryElement["path"] = @"/"; virtualDirectoryElement["physicalPath"] = @"C:\Inetpub\www.contoso.com\wwwroot"; applicationCollection.Add(virtualDirectoryElement); siteCollection.Add(applicationElement); sitesCollection.Add(siteElement); 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 TestMoveDown() { SetUp(); const string Expected = @"expected_add.site.config"; var document = XDocument.Load(Current); var node = new XElement("location"); node.SetAttributeValue("path", "WebSite1"); document.Root.Add(node); var web = new XElement("system.webServer"); node.Add(web); var content = new XElement("isapiFilters"); web.Add(content); var remove = new XElement("remove"); remove.SetAttributeValue("name", "ASP.Net_4.0_64bit"); content.Add(remove); var add = new XElement("filter"); add.SetAttributeValue("name", "test"); add.SetAttributeValue("path", "c:\\test.dll"); content.Add(add); var six = new XElement("filter"); six.SetAttributeValue("enableCache", "true"); six.SetAttributeValue("name", "ASP.Net_4.0_64bit"); six.SetAttributeValue("path", @"%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_filter.dll"); six.SetAttributeValue("preCondition", "bitness64,runtimeVersionv4.0"); content.Add(six); document.Save(Expected); var item = new IsapiFiltersItem(null); item.Name = "test"; item.Path = "c:\\test.dll"; _feature.AddItem(item); var last = 5; var previous = last - 1; _feature.SelectedItem = _feature.Items[previous]; var expected = "test"; Assert.Equal(expected, _feature.Items[last].Name); var original = "ASP.Net_4.0_64bit"; Assert.Equal(original, _feature.Items[previous].Name); _feature.MoveDown(); Assert.NotNull(_feature.SelectedItem); Assert.Equal(original, _feature.SelectedItem.Name); Assert.Equal(expected, _feature.Items[previous].Name); Assert.Equal(original, _feature.Items[last].Name); XmlAssert.Equal(Expected, Current); XmlAssert.Equal(Path.Combine("Website1", "original.config"), Path.Combine("Website1", "web.config")); }
public void TestMoveUp() { SetUp(); const string Expected = @"expected_add.site.config"; var document = XDocument.Load(Current); var node = new XElement("location", new XAttribute("path", "WebSite1")); document.Root?.Add(node); var web = new XElement("system.webServer"); node.Add(web); var content = new XElement("handlers", new XElement("clear")); web.Add(content); var all = document.Root?.XPathSelectElement("/configuration/location[@path='']/system.webServer/handlers"); if (all != null) { foreach (var element in all.Elements()) { content.Add(element); } } content.LastNode.Remove(); var add = new XElement("add", new XAttribute("resourceType", "File"), new XAttribute("modules", ""), new XAttribute("name", "test"), new XAttribute("path", "*"), new XAttribute("verb", "*")); content.Add(add); var one = new XElement("add", new XAttribute("modules", "StaticFileModule,DefaultDocumentModule,DirectoryListingModule"), new XAttribute("name", "StaticFile"), new XAttribute("path", "*"), new XAttribute("requireAccess", "Read"), new XAttribute("resourceType", "Either"), new XAttribute("verb", "*")); content.Add(one); document.Save(Expected); var item = new HandlersItem(null); item.Name = "test"; item.Path = "*"; _feature.AddItem(item); var last = 82; var previous = last - 1; _feature.SelectedItem = _feature.Items[last]; var expected = "test"; Assert.Equal(expected, _feature.Items[last].Name); var original = "StaticFile"; Assert.Equal(original, _feature.Items[previous].Name); _feature.MoveUp(); Assert.NotNull(_feature.SelectedItem); Assert.Equal(expected, _feature.SelectedItem.Name); Assert.Equal(expected, _feature.Items[previous].Name); Assert.Equal(original, _feature.Items[last].Name); XmlAssert.Equal(Expected, Current); XmlAssert.Equal(Path.Combine("Website1", "original.config"), Path.Combine("Website1", "web.config")); }
public void CreateNewKey_Internal_WithEscrowAndEncryption() { // Constants var creationDate = new DateTimeOffset(2014, 01, 01, 0, 0, 0, TimeSpan.Zero); var activationDate = new DateTimeOffset(2014, 02, 01, 0, 0, 0, TimeSpan.Zero); var expirationDate = new DateTimeOffset(2014, 03, 01, 0, 0, 0, TimeSpan.Zero); var keyId = new Guid("3d6d01fd-c0e7-44ae-82dd-013b996b4093"); // Arrange - mocks XElement elementStoredInEscrow = null; Guid? keyIdStoredInEscrow = null; XElement elementStoredInRepository = null; string friendlyNameStoredInRepository = null; var expectedAuthenticatedEncryptor = new Mock <IAuthenticatedEncryptor>().Object; var mockDescriptor = new Mock <IAuthenticatedEncryptorDescriptor>(); mockDescriptor.Setup(o => o.ExportToXml()).Returns(new XmlSerializedDescriptorInfo(serializedDescriptor, typeof(MyDeserializer))); mockDescriptor.Setup(o => o.CreateEncryptorInstance()).Returns(expectedAuthenticatedEncryptor); var mockConfiguration = new Mock <IAuthenticatedEncryptorConfiguration>(); mockConfiguration.Setup(o => o.CreateNewDescriptor()).Returns(mockDescriptor.Object); var mockXmlRepository = new Mock <IXmlRepository>(); mockXmlRepository .Setup(o => o.StoreElement(It.IsAny <XElement>(), It.IsAny <string>())) .Callback <XElement, string>((el, friendlyName) => { elementStoredInRepository = el; friendlyNameStoredInRepository = friendlyName; }); var mockKeyEscrow = new Mock <IKeyEscrowSink>(); mockKeyEscrow .Setup(o => o.Store(It.IsAny <Guid>(), It.IsAny <XElement>())) .Callback <Guid, XElement>((innerKeyId, el) => { keyIdStoredInEscrow = innerKeyId; elementStoredInEscrow = el; }); // Arrange - services var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <IXmlRepository>(mockXmlRepository.Object); serviceCollection.AddSingleton <IAuthenticatedEncryptorConfiguration>(mockConfiguration.Object); serviceCollection.AddSingleton <IKeyEscrowSink>(mockKeyEscrow.Object); serviceCollection.AddSingleton <IXmlEncryptor, NullXmlEncryptor>(); var services = serviceCollection.BuildServiceProvider(); var keyManager = new XmlKeyManager(services); // Act & assert // The cancellation token should not already be fired var firstCancellationToken = keyManager.GetCacheExpirationToken(); Assert.False(firstCancellationToken.IsCancellationRequested); // After the call to CreateNewKey, the first CT should be fired, // and we should've gotten a new CT. var newKey = ((IInternalXmlKeyManager)keyManager).CreateNewKey( keyId: keyId, creationDate: creationDate, activationDate: activationDate, expirationDate: expirationDate); var secondCancellationToken = keyManager.GetCacheExpirationToken(); Assert.True(firstCancellationToken.IsCancellationRequested); Assert.False(secondCancellationToken.IsCancellationRequested); // Does the IKey have the properties we requested? Assert.Equal(keyId, newKey.KeyId); Assert.Equal(creationDate, newKey.CreationDate); Assert.Equal(activationDate, newKey.ActivationDate); Assert.Equal(expirationDate, newKey.ExpirationDate); Assert.False(newKey.IsRevoked); Assert.Same(expectedAuthenticatedEncryptor, newKey.CreateEncryptorInstance()); // Was the correct element stored in escrow? // This should not have gone through the encryptor. string expectedEscrowXml = String.Format(@" <key id='3d6d01fd-c0e7-44ae-82dd-013b996b4093' version='1' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'> {1} {2} {3} <descriptor deserializerType='{0}'> <theElement> <secret enc:requiresEncryption='true'> <![CDATA[This is a secret value.]]> </secret> </theElement> </descriptor> </key>", typeof(MyDeserializer).AssemblyQualifiedName, new XElement("creationDate", creationDate), new XElement("activationDate", activationDate), new XElement("expirationDate", expirationDate)); XmlAssert.Equal(expectedEscrowXml, elementStoredInEscrow); Assert.Equal(keyId, keyIdStoredInEscrow.Value); // Finally, was the correct element stored in the repository? // This should have gone through the encryptor (which we set to be the null encryptor in this test) string expectedRepositoryXml = String.Format(@" <key id='3d6d01fd-c0e7-44ae-82dd-013b996b4093' version='1' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'> {2} {3} {4} <descriptor deserializerType='{0}'> <theElement> <enc:encryptedSecret decryptorType='{1}'> <unencryptedKey> <secret enc:requiresEncryption='true'> <![CDATA[This is a secret value.]]> </secret> </unencryptedKey> </enc:encryptedSecret> </theElement> </descriptor> </key>", typeof(MyDeserializer).AssemblyQualifiedName, typeof(NullXmlDecryptor).AssemblyQualifiedName, new XElement("creationDate", creationDate), new XElement("activationDate", activationDate), new XElement("expirationDate", expirationDate)); XmlAssert.Equal(expectedRepositoryXml, elementStoredInRepository); Assert.Equal("key-3d6d01fd-c0e7-44ae-82dd-013b996b4093", friendlyNameStoredInRepository); }
public void XmlEqualsWithStringFail() { XmlAssert.XmlEquals(_xmlTrueTest, _xmlFalseTest); }
private void TestAddFCCSettings(string runSettings, string expectedFccRunSettings, IRunSettingsTemplateReplacements runSettingsTemplateReplacements) { var actualRunSettings = AddFCCSettings(runSettings, runSettingsTemplateReplacements); XmlAssert.NoXmlDifferences(actualRunSettings, expectedFccRunSettings); }
public void XmlEqualsWithXmlInput() { XmlAssert.XmlEquals(new XmlInput(_xmlTrueTest), new XmlInput(_xmlTrueTest)); }
public void CreateNewKey_Internal_NoEscrowOrEncryption() { // Constants var creationDate = new DateTimeOffset(2014, 01, 01, 0, 0, 0, TimeSpan.Zero); var activationDate = new DateTimeOffset(2014, 02, 01, 0, 0, 0, TimeSpan.Zero); var expirationDate = new DateTimeOffset(2014, 03, 01, 0, 0, 0, TimeSpan.Zero); var keyId = new Guid("3d6d01fd-c0e7-44ae-82dd-013b996b4093"); // Arrange XElement elementStoredInRepository = null; string friendlyNameStoredInRepository = null; var expectedAuthenticatedEncryptor = new Mock <IAuthenticatedEncryptor>().Object; var mockDescriptor = new Mock <IAuthenticatedEncryptorDescriptor>(); mockDescriptor.Setup(o => o.ExportToXml()).Returns(new XmlSerializedDescriptorInfo(serializedDescriptor, typeof(MyDeserializer))); var expectedDescriptor = mockDescriptor.Object; var testEncryptorFactory = new TestEncryptorFactory(expectedDescriptor, expectedAuthenticatedEncryptor); var mockConfiguration = new Mock <AlgorithmConfiguration>(); mockConfiguration.Setup(o => o.CreateNewDescriptor()).Returns(expectedDescriptor); var mockXmlRepository = new Mock <IXmlRepository>(); mockXmlRepository .Setup(o => o.StoreElement(It.IsAny <XElement>(), It.IsAny <string>())) .Callback <XElement, string>((el, friendlyName) => { elementStoredInRepository = el; friendlyNameStoredInRepository = friendlyName; }); var options = Options.Create(new KeyManagementOptions() { AuthenticatedEncryptorConfiguration = mockConfiguration.Object, XmlRepository = mockXmlRepository.Object, XmlEncryptor = null }); options.Value.AuthenticatedEncryptorFactories.Add(testEncryptorFactory); var keyManager = new XmlKeyManager(options, SimpleActivator.DefaultWithoutServices, NullLoggerFactory.Instance); // Act & assert // The cancellation token should not already be fired var firstCancellationToken = keyManager.GetCacheExpirationToken(); Assert.False(firstCancellationToken.IsCancellationRequested); // After the call to CreateNewKey, the first CT should be fired, // and we should've gotten a new CT. var newKey = ((IInternalXmlKeyManager)keyManager).CreateNewKey( keyId: keyId, creationDate: creationDate, activationDate: activationDate, expirationDate: expirationDate); var secondCancellationToken = keyManager.GetCacheExpirationToken(); Assert.True(firstCancellationToken.IsCancellationRequested); Assert.False(secondCancellationToken.IsCancellationRequested); // Does the IKey have the properties we requested? Assert.Equal(keyId, newKey.KeyId); Assert.Equal(creationDate, newKey.CreationDate); Assert.Equal(activationDate, newKey.ActivationDate); Assert.Equal(expirationDate, newKey.ExpirationDate); Assert.Same(expectedDescriptor, newKey.Descriptor); Assert.False(newKey.IsRevoked); Assert.Same(expectedAuthenticatedEncryptor, testEncryptorFactory.CreateEncryptorInstance(newKey)); // Finally, was the correct element stored in the repository? string expectedXml = string.Format(@" <key id='3d6d01fd-c0e7-44ae-82dd-013b996b4093' version='1' xmlns:enc='http://schemas.asp.net/2015/03/dataProtection'> {1} {2} {3} <descriptor deserializerType='{0}'> <theElement> <secret enc:requiresEncryption='true'> <![CDATA[This is a secret value.]]> </secret> </theElement> </descriptor> </key>", typeof(MyDeserializer).AssemblyQualifiedName, new XElement("creationDate", creationDate), new XElement("activationDate", activationDate), new XElement("expirationDate", expirationDate)); XmlAssert.Equal(expectedXml, elementStoredInRepository); Assert.Equal("key-3d6d01fd-c0e7-44ae-82dd-013b996b4093", friendlyNameStoredInRepository); }
public void XmlEqualsWithXmlDiff() { XmlAssert.XmlEquals(new XmlDiff(_xmlTrueTest, _xmlTrueTest)); }
void MixedContentAndDepth(XPathNavigator nav, string label) { XmlReader r = nav.ReadSubtree(); r.Read(); XmlAssert.AssertNode(label + "#1", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Element, 0, false, // Name, Prefix, LocalName, NamespaceURI "one", String.Empty, "one", String.Empty, // Value, HasValue, AttributeCount, HasAttributes String.Empty, false, 0, false); r.Read(); XmlAssert.AssertNode(label + "#2", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Element, 1, false, // Name, Prefix, LocalName, NamespaceURI "two", String.Empty, "two", String.Empty, // Value, HasValue, AttributeCount, HasAttributes String.Empty, false, 0, false); r.Read(); XmlAssert.AssertNode(label + "#3", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Text, 2, false, // Name, Prefix, LocalName, NamespaceURI String.Empty, String.Empty, String.Empty, String.Empty, // Value, HasValue, AttributeCount, HasAttributes "Some data.", true, 0, false); r.Read(); XmlAssert.AssertNode(label + "#4", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Element, 2, false, // Name, Prefix, LocalName, NamespaceURI "three", String.Empty, "three", String.Empty, // Value, HasValue, AttributeCount, HasAttributes String.Empty, false, 0, false); r.Read(); XmlAssert.AssertNode(label + "#5", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Text, 3, false, // Name, Prefix, LocalName, NamespaceURI String.Empty, String.Empty, String.Empty, String.Empty, // Value, HasValue, AttributeCount, HasAttributes "more", true, 0, false); r.Read(); XmlAssert.AssertNode(label + "#6", r, // NodeType, Depth, IsEmptyElement XmlNodeType.EndElement, 2, false, // Name, Prefix, LocalName, NamespaceURI "three", String.Empty, "three", String.Empty, // Value, HasValue, AttributeCount, HasAttributes String.Empty, false, 0, false); r.Read(); XmlAssert.AssertNode(label + "#7", r, // NodeType, Depth, IsEmptyElement XmlNodeType.Text, 2, false, // Name, Prefix, LocalName, NamespaceURI String.Empty, String.Empty, String.Empty, String.Empty, // Value, HasValue, AttributeCount, HasAttributes " done.", true, 0, false); r.Read(); XmlAssert.AssertNode(label + "#8", r, // NodeType, Depth, IsEmptyElement XmlNodeType.EndElement, 1, false, // Name, Prefix, LocalName, NamespaceURI "two", String.Empty, "two", String.Empty, // Value, HasValue, AttributeCount, HasAttributes String.Empty, false, 0, false); r.Read(); XmlAssert.AssertNode(label + "#9", r, // NodeType, Depth, IsEmptyElement XmlNodeType.EndElement, 0, false, // Name, Prefix, LocalName, NamespaceURI "one", String.Empty, "one", String.Empty, // Value, HasValue, AttributeCount, HasAttributes String.Empty, false, 0, false); Assert.IsFalse(r.Read(), label + "#10"); }
public void XmlEqualsWithXmlDiffFail() { XmlAssert.XmlEquals(new XmlDiff(new XmlInput(_xmlTrueTest), new XmlInput(_xmlFalseTest))); }
public void AddSite() { 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); const string Expected = @"expected_site_add.config"; var document = XDocument.Load(Current); var node = document.Root.XPathSelectElement("/configuration/system.applicationHost/sites"); var siteNode = new XElement("site"); siteNode.SetAttributeValue("name", "Contoso"); siteNode.SetAttributeValue("id", "2"); var bindingsNode = new XElement("bindings"); siteNode.Add(bindingsNode); node?.Add(siteNode); var bindingNode = new XElement("binding"); bindingNode.SetAttributeValue("protocol", "http"); bindingNode.SetAttributeValue("bindingInformation", @"*:80:www.contoso.com"); bindingsNode.Add(bindingNode); var appNode = new XElement("application"); appNode.SetAttributeValue("path", "/"); siteNode.Add(appNode); var vDirNode = new XElement("virtualDirectory"); vDirNode.SetAttributeValue("path", "/"); vDirNode.SetAttributeValue("physicalPath", @"C:\Inetpub\www.contoso.com\wwwroot"); appNode.Add(vDirNode); document.Save(Expected); Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElementCollection sitesCollection = sitesSection.GetCollection(); ConfigurationElement siteElement = sitesCollection.CreateElement("site"); siteElement["name"] = @"Contoso"; siteElement["id"] = 2; siteElement["serverAutoStart"] = true; ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings"); ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding"); bindingElement["protocol"] = @"http"; bindingElement["bindingInformation"] = @"*:80:www.contoso.com"; bindingsCollection.Add(bindingElement); ConfigurationElementCollection siteCollection = siteElement.GetCollection(); ConfigurationElement applicationElement = siteCollection.CreateElement("application"); applicationElement["path"] = @"/"; ConfigurationElementCollection applicationCollection = applicationElement.GetCollection(); ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory"); virtualDirectoryElement["path"] = @"/"; virtualDirectoryElement["physicalPath"] = @"C:\Inetpub\www.contoso.com\wwwroot"; applicationCollection.Add(virtualDirectoryElement); siteCollection.Add(applicationElement); sitesCollection.Add(siteElement); serverManager.CommitChanges(); XmlAssert.Equal(Expected, Current); }
[Test] public void AssertXPathEvaluatesToWorksForNonMatchingExpression() { XmlAssert.XPathEvaluatesTo("//planet[@position='4']/@supportsLife", MY_SOLAR_SYSTEM, ""); }
public void PrependChildXmlReader() { XPathNavigator nav = GetInstance("<root><foo>existing_child</foo></root>"); nav.MoveToFirstChild(); nav.MoveToFirstChild(); // foo XmlReader reader = new XmlTextReader( "<child>text</child><next_sibling/>", XmlNodeType.Element, null); nav.PrependChild(reader); XmlAssert.AssertNode("#0", reader, XmlNodeType.None, 0, // Depth false, // IsEmptyElement String.Empty, // Name String.Empty, // Prefix String.Empty, // LocalName String.Empty, // NamespaceURI String.Empty, // Value false, // HasValue 0, // AttributeCount false); // HasAttributes AssertNavigator("#1", nav, XPathNodeType.Element, String.Empty, // Prefix "foo", // LocalName String.Empty, // NamespaceURI "foo", // Name "textexisting_child", // Value false, // HasAttributes true, // HasChildren false); // IsEmptyElement Assert.IsTrue(nav.MoveToFirstChild(), "#1-2"); AssertNavigator("#2", nav, XPathNodeType.Element, String.Empty, // Prefix "child", // LocalName String.Empty, // NamespaceURI "child", // Name "text", // Value false, // HasAttributes true, // HasChildren false); // IsEmptyElement Assert.IsTrue(nav.MoveToNext(), "#2-2"); AssertNavigator("#3", nav, XPathNodeType.Element, String.Empty, // Prefix "next_sibling", // LocalName String.Empty, // NamespaceURI "next_sibling", // Name String.Empty, // Value false, // HasAttributes false, // HasChildren true); // IsEmptyElement Assert.IsTrue(nav.MoveToNext(), "#3-2"); AssertNavigator("#4", nav, XPathNodeType.Text, String.Empty, // Prefix String.Empty, // LocalName String.Empty, // NamespaceURI String.Empty, // Name "existing_child", // Value false, // HasAttributes false, // HasChildren false); // IsEmptyElement }
[Test] public void AssertXPathExistsWorksForExistentXPath() { XmlAssert.XPathExists("//planet[@name='Earth']", MY_SOLAR_SYSTEM); }
public void ReturnsSuccessfully_WithEmptyElements(string input1, string input2) { XmlAssert.Equal(input1, input2); }
public void TestMoveUp() { SetUp(); const string expected = @"expected_add.site.config"; var site = Path.Combine("Website1", "web.config"); var document = XDocument.Load(site); var server = document.Root?.XPathSelectElement("/configuration/system.webServer"); server?.Add( new XElement("tracing", new XElement("traceFailedRequests", new XElement("clear"), new XElement("add", new XAttribute("path", "*.aspx"), new XElement("traceAreas", new XElement("add", new XAttribute("provider", "ASP"), new XAttribute("verbosity", "Verbose")), new XElement("add", new XAttribute("provider", "ASPNET"), new XAttribute("areas", "Infrastructure,Module,Page,AppServices"), new XAttribute("verbosity", "Verbose")), new XElement("add", new XAttribute("provider", "ISAPI Extension"), new XAttribute("verbosity", "Verbose")), new XElement("add", new XAttribute("provider", "WWW Server"), new XAttribute("areas", "Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,WebSocket"), new XAttribute("verbosity", "Verbose"))), new XElement("failureDefinitions", new XAttribute("statusCodes", "200-999"))), new XElement("add", new XAttribute("path", "*.asp"), new XElement("traceAreas", new XElement("add", new XAttribute("provider", "ASP"), new XAttribute("verbosity", "Verbose")), new XElement("add", new XAttribute("provider", "ASPNET"), new XAttribute("areas", "Infrastructure,Module,Page,AppServices"), new XAttribute("verbosity", "Verbose")), new XElement("add", new XAttribute("provider", "ISAPI Extension"), new XAttribute("verbosity", "Verbose")), new XElement("add", new XAttribute("provider", "WWW Server"), new XAttribute("areas", "Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,WebSocket"), new XAttribute("verbosity", "Verbose"))), new XElement("failureDefinitions", new XAttribute("statusCodes", "200-999"))) ))); document.Save(expected); var last = 1; var previous = last - 1; _feature.SelectedItem = _feature.Items[last]; var expectedValue = "*.aspx"; Assert.Equal(expectedValue, _feature.Items[last].Path); var original = "*.asp"; Assert.Equal(original, _feature.Items[previous].Path); _feature.MoveUp(); Assert.NotNull(_feature.SelectedItem); Assert.Equal(expectedValue, _feature.SelectedItem.Path); Assert.Equal(expectedValue, _feature.Items[previous].Path); Assert.Equal(original, _feature.Items[last].Path); const string Original = @"original.config"; const string OriginalMono = @"original.mono.config"; XmlAssert.Equal(Helper.IsRunningOnMono() ? OriginalMono : Original, Current); XmlAssert.Equal(expected, site); }
public void ReturnsSuccessfully_WithMatchingContent_IgnoringAttributeOrder(string input1, string input2) { XmlAssert.Equal(input1, input2); }
public void BigXmlDocumentIsSameAsSelfWithLotsOfWhitespaceRemoved() { XmlAssert.AreEqual(bigXml, bigXmlWithLessWhitespace); }