public void Signing() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument); Assert.AreNotEqual(xDocument.ToString(), signedDocument.Sign().ToString()); }
public void CloneConstructor() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml, LoadOptions.PreserveWhitespace); var signedDocument = new SignedXDocument(xDocument); Assert.AreEqual(xDocument.ToString(), signedDocument.ToString()); }
public void Verification() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument); var withSignature = signedDocument.Sign(); Assert.IsTrue(SignedXDocument.Verify(withSignature)); }
public void VerificationAltered() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument); var withSignature = signedDocument.Sign(); var altered = new XDocument(withSignature); altered.Root?.Add(new XElement(@"dummy")); Assert.IsFalse(SignedXDocument.Verify(altered)); }
public void VerificationWithProperties() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument) { SignatureProperties = new List <XElement> { new XElement(@"SomeProperty", @"SomeValue") } }; var withSignature = signedDocument.Sign(); Assert.IsTrue(SignedXDocument.Verify(withSignature)); }
public void SigningWithProperties() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument) { SignatureProperties = new List <XElement> { new XElement(@"Property1", @"SomeValue1"), new XElement(@"Property2", @"SomeValue2") } }; Assert.AreNotEqual(xDocument.ToString(), signedDocument.Sign().ToString()); }
public void VerificationWithPropertiesAltered() { const string xml = @"<!-- root comment --> <root> <child>content</child> </root>"; var xDocument = XDocument.Parse(xml); var signedDocument = new SignedXDocument(xDocument) { SignatureProperties = new List <XElement> { new XElement(@"SomeProperty", @"SomeValue", new [] { new XAttribute(@"Id", @"property") }) } }; var withSignature = signedDocument.Sign(); var altered = new XDocument(withSignature); var propertyNode = altered.XPathSelectElement(@"//*[@Id='property']"); propertyNode?.SetValue(@"SomeAlteredValue"); Assert.IsFalse(SignedXDocument.Verify(altered)); }