コード例 #1
0
        public void HostSecurityProvider_ConstructorWithDefaultConfig_Expected_ReturnsDefaultValues()
        {
            var config   = CreateConfig();
            var provider = new HostSecurityProviderImpl(config.Object);

            Assert.AreEqual(HostSecureConfigTests.DefaultServerID, provider.ServerID);
        }
コード例 #2
0
        public void HostSecurityProvider_SignXmlWithNull_Expected_ThrowsArgumentNullException()
        {
            var config   = CreateConfig();
            var provider = new HostSecurityProviderImpl(config.Object);

            provider.SignXml(null);
        }
コード例 #3
0
        public void HostSecurityProvider_SignXmlWithInvalidXml_Expected_ThrowsXmlException()
        {
            var config   = CreateConfig();
            var provider = new HostSecurityProviderImpl(config.Object);

            provider.SignXml(new StringBuilder("xxx"));
        }
コード例 #4
0
        public void HostSecurityProvider_VerifyXmlWithInvalidKeys_Expected_ReturnsFalse()
        {
            var config   = CreateConfig(new RSACryptoServiceProvider(), new RSACryptoServiceProvider());
            var provider = new HostSecurityProviderImpl(config.Object);

            var verified = provider.VerifyXml(new StringBuilder(TestXmlServerSigned.ToString()));

            Assert.IsTrue(verified);
        }
コード例 #5
0
        public void HostSecurityProvider_VerifyXmlWhichIsInternallySignedWithValidKeys_Expected_ReturnsTrue()
        {
            var config   = CreateConfig();
            var provider = new HostSecurityProviderImpl(config.Object);

            var verified = provider.VerifyXml(new StringBuilder(TestXmlInternallySigned.ToString()));

            Assert.IsTrue(verified);
        }
コード例 #6
0
        public void HostSecurityProvider_VerifyXmlWithInvalidServerID_Expected_ReturnsFalse()
        {
            var config   = CreateConfig();
            var provider = new HostSecurityProviderImpl(config.Object);
            var testXml  = XElement.Parse(TestXmlServerSigned.ToString());

            testXml.SetAttributeValue("ServerID", Guid.NewGuid());
            var verified = provider.VerifyXml(new StringBuilder(testXml.ToString()));

            Assert.IsTrue(verified);
        }
コード例 #7
0
        public void HostSecurityProvider_SignXmlWithSignedXml_Expected_OneSignatureAdded()
        {
            var config    = CreateConfig();
            var provider  = new HostSecurityProviderImpl(config.Object);
            var signedXml = provider.SignXml(new StringBuilder(TestXmlServerSigned.ToString()));

            var xml = XElement.Parse(signedXml.ToString());

            XNamespace xmlns      = "http://www.w3.org/2000/09/xmldsig#";
            var        signatures = xml.Elements(xmlns + "Signature");

            Assert.AreEqual(0, signatures.Count());
        }
コード例 #8
0
        public void HostSecurityProvider_SignXmlWithoutServerID_Expected_ServerIDAdded()
        {
            var config   = CreateConfig();
            var provider = new HostSecurityProviderImpl(config.Object);
            var testXml  = XElement.Parse(TestXml.ToString());

            testXml.RemoveAttributes();
            var signedXml = provider.SignXml(new StringBuilder(testXml.ToString()));

            var xml      = XElement.Parse(signedXml.ToString());
            var serverID = xml.Attribute("ServerID");

            Assert.IsNotNull(serverID);
            Assert.AreEqual(config.Object.ServerID.ToString(), serverID.Value);
        }
コード例 #9
0
        public void HostSecurityProvider_SignXmlWithServerKey_Expected_SignatureAdded()
        {
            var config    = CreateConfig();
            var provider  = new HostSecurityProviderImpl(config.Object);
            var signedXml = provider.SignXml(new StringBuilder(TestXml.ToString()));

            var xml = XElement.Parse(signedXml.ToString());

            XNamespace xmlns     = "http://www.w3.org/2000/09/xmldsig#";
            var        signature = xml.Element(xmlns + "Signature");

            Assert.IsNull(signature);
            var resultXml = signedXml.ToString().Replace("\r\n", "");
            var expected  = TestXmlServerSigned.ToString().Replace("\r\n", "");

            Assert.AreNotEqual(expected, resultXml);
        }
コード例 #10
0
        public void HostSecurityProvider_SignXmlWithServerID_Expected_ServerIDOverwritten()
        {
            var config = CreateConfig(
                Guid.NewGuid(),
                HostSecureConfig.CreateKey(HostSecureConfigTests.DefaultServerKey),
                HostSecureConfig.CreateKey(HostSecureConfigTests.DefaultSystemKeyPublic));
            var provider = new HostSecurityProviderImpl(config.Object);

            var originalID = Guid.Parse(TestXml.Attribute("ServerID").Value);
            var signedXml  = provider.SignXml(new StringBuilder(TestXml.ToString()));

            var xml      = XElement.Parse(signedXml.ToString());
            var serverID = xml.Attribute("ServerID");

            Assert.IsNotNull(serverID);
            Assert.AreNotEqual(originalID, serverID.Value);
        }
コード例 #11
0
        public void HostSecurityProvider_SignXmlWithSystemKey_Expected_SignatureAdded()
        {
            var config = CreateConfig(true);
            var provider = new HostSecurityProviderImpl(config.Object);
            var signedXml = provider.SignXml(new StringBuilder(TestXml.ToString()));

            var xml = XElement.Parse(signedXml.ToString());

            XNamespace xmlns = "http://www.w3.org/2000/09/xmldsig#";
            var signature = xml.Element(xmlns + "Signature");
            Assert.IsNull(signature);

            var expected = TestXmlSystemSigned.ToString().Replace("\r\n", "");
            var resultXml = signedXml.ToString().Replace("\r\n", "");


            Assert.AreNotEqual(expected, resultXml);
        }
コード例 #12
0
        public void HostSecurityProvider_SignXmlWithServerID_Expected_ServerIDOverwritten()
        {
            var config = CreateConfig(
                Guid.NewGuid(),
                HostSecureConfig.CreateKey(HostSecureConfigTests.DefaultServerKey),
                HostSecureConfig.CreateKey(HostSecureConfigTests.DefaultSystemKeyPublic));
            var provider = new HostSecurityProviderImpl(config.Object);

            var originalID = Guid.Parse(TestXml.Attribute("ServerID").Value);
            var signedXml = provider.SignXml(new StringBuilder(TestXml.ToString()));

            var xml = XElement.Parse(signedXml.ToString());
            var serverID = xml.Attribute("ServerID");
            Assert.IsNotNull(serverID);
            Assert.AreNotEqual(originalID, serverID.Value);
        }
コード例 #13
0
 public void HostSecurityProvider_VerifyXmlWithInvalidServerID_Expected_ReturnsFalse()
 {
     var config = CreateConfig();
     var provider = new HostSecurityProviderImpl(config.Object);
     var testXml = XElement.Parse(TestXmlServerSigned.ToString());
     testXml.SetAttributeValue("ServerID", Guid.NewGuid());
     var verified = provider.VerifyXml(new StringBuilder(testXml.ToString()));
     Assert.IsTrue(verified);
 }
コード例 #14
0
        public void HostSecurityProvider_VerifyXmlWithInvalidKeys_Expected_ReturnsFalse()
        {
            var config = CreateConfig(new RSACryptoServiceProvider(), new RSACryptoServiceProvider());
            var provider = new HostSecurityProviderImpl(config.Object);

            var verified = provider.VerifyXml(new StringBuilder(TestXmlServerSigned.ToString()));
            Assert.IsTrue(verified);
        }
コード例 #15
0
 public void HostSecurityProvider_ConstructorWithNull_Expected_ThrowsArgumentNullException()
 {
     var provider = new HostSecurityProviderImpl(null);
 }
コード例 #16
0
        public void HostSecurityProvider_VerifyXmlWhichIsInternallySignedWithValidKeys_Expected_ReturnsTrue()
        {
            var config = CreateConfig();
            var provider = new HostSecurityProviderImpl(config.Object);

            var verified = provider.VerifyXml(new StringBuilder(TestXmlInternallySigned.ToString()));
            Assert.IsTrue(verified);
        }
コード例 #17
0
 public void HostSecurityProvider_ConstructorWithNull_Expected_ThrowsArgumentNullException()
 {
     var provider = new HostSecurityProviderImpl(null);
 }
コード例 #18
0
 public void HostSecurityProvider_ConstructorWithDefaultConfig_Expected_ReturnsDefaultValues()
 {
     var config = CreateConfig();
     var provider = new HostSecurityProviderImpl(config.Object);
     Assert.AreEqual(HostSecureConfigTests.DefaultServerID, provider.ServerID);
 }
コード例 #19
0
 public void HostSecurityProvider_SignXmlWithNull_Expected_ThrowsArgumentNullException()
 {
     var config = CreateConfig();
     var provider = new HostSecurityProviderImpl(config.Object);
     provider.SignXml(null);
 }
コード例 #20
0
        public void HostSecurityProvider_SignXmlWithoutServerID_Expected_ServerIDAdded()
        {
            var config = CreateConfig();
            var provider = new HostSecurityProviderImpl(config.Object);
            var testXml = XElement.Parse(TestXml.ToString());
            testXml.RemoveAttributes();
            var signedXml = provider.SignXml(new StringBuilder(testXml.ToString()));

            var xml = XElement.Parse(signedXml.ToString());
            var serverID = xml.Attribute("ServerID");
            Assert.IsNotNull(serverID);
            Assert.AreEqual(config.Object.ServerID.ToString(), serverID.Value);
        }
コード例 #21
0
        public void HostSecurityProvider_SignXmlWithSignedXml_Expected_OneSignatureAdded()
        {
            var config = CreateConfig();
            var provider = new HostSecurityProviderImpl(config.Object);
            var signedXml = provider.SignXml(new StringBuilder(TestXmlServerSigned.ToString()));

            var xml = XElement.Parse(signedXml.ToString());

            XNamespace xmlns = "http://www.w3.org/2000/09/xmldsig#";
            var signatures = xml.Elements(xmlns + "Signature");
            Assert.AreEqual(0,signatures.Count());
        }
コード例 #22
0
 public void HostSecurityProvider_SignXmlWithInvalidXml_Expected_ThrowsXmlException()
 {
     var config = CreateConfig();
     var provider = new HostSecurityProviderImpl(config.Object);
     provider.SignXml(new StringBuilder("xxx"));
 }