public void WsTrustRequestXmlFormatTest()
        {
            UserCredential cred = new UserPasswordCredential("user", "pass&<>\"'");
            StringBuilder  sb   = WsTrustRequest.BuildMessage("https://appliesto",
                                                              new WsTrustAddress {
                Uri = new Uri("some://resource")
            }, cred);

            // Expecting XML to be valid
            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<?xml version=\"1.0\"?>" + sb.ToString());
        }
Example #2
0
        public void WsTrustRequestXmlFormatTest()
        {
            // Arrange
            UserCredential cred = new UserPasswordCredential("user", "pass&<>\"'");

            // Act
            StringBuilder sb = WsTrustRequest.BuildMessage("https://appliesto",
                                                           new WsTrustAddress {
                Uri = new Uri("some://resource")
            }, cred);

            // Assert
            XmlReaderSettings readerSettings = new XmlReaderSettings();

            readerSettings.XmlResolver      = null;
            readerSettings.IgnoreWhitespace = true;
            readerSettings.ConformanceLevel = ConformanceLevel.Fragment;
            readerSettings.DtdProcessing    = DtdProcessing.Ignore;

            // Load the fragment, validating it against the XSDs
            List <string> validationIssues = new List <string>();

            readerSettings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
            readerSettings.ValidationType  = ValidationType.Schema;
            readerSettings.Schemas         = CreateWsTrustEnvelopeSchemaSet();

            readerSettings.ValidationEventHandler += (s, e) =>
            {
                validationIssues.Add(e.Severity + " " + e.Message);
            };


            XmlDocument document = new XmlDocument();

            using (var xmlReader = XmlTextReader.Create(new StringReader(sb.ToString()), readerSettings))
            {
                document.Load(xmlReader);
            }


            Debug.WriteLine("All validation issues:");
            Debug.WriteLine(string.Join("\r\n", validationIssues.ToArray()));

            // Filter out "expected" schema-validation messages.
            // The real ws-trust XML namespace is http://docs.oasis-open.org/ws-sx/ws-trust/200512/ i.e. with a trailing slash. However, we use
            // the namespace without a trailing slash as this is what the server expects, so we expect validation messages about missing elements
            const string  invalidTrustNamespaceMessageContent = "Could not find schema information for the element 'http://docs.oasis-open.org/ws-sx/ws-trust/200512:";
            List <string> unexpectedValidationIssues          = validationIssues.Where(i => !i.Contains(invalidTrustNamespaceMessageContent)).ToList();

            Assert.AreEqual(0, unexpectedValidationIssues.Count, "Not expecting any XML schema validation errors. See the test output for the validation errors.");
        }
        public async Task WsTrustRequestXmlFormatTest()
        {
            UserCredential cred = new UserCredential("user", "pass&<>\"'");
            StringBuilder  sb   = WsTrustRequest.BuildMessage("https://appliesto", new WsTrustAddress {
                Uri = new Uri("resource")
            }, cred);

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml("<?xml version=\"1.0\"?>" + sb.ToString());
            }
            catch (Exception ex)
            {
                Verify.Fail("Not expected");
            }
        }
        public void WsTrustRequestXmlFormatTest()
        {
            // Arrange
            UserCredential cred = new UserPasswordCredential("user", "pass&<>\"'");

            // Act
            StringBuilder sb = WsTrustRequest.BuildMessage("https://appliesto",
                                                           new WsTrustAddress {
                Uri = new Uri("some://resource")
            }, cred);

            // Assert
            XmlReaderSettings readerSettings = new XmlReaderSettings();

            readerSettings.XmlResolver      = null;
            readerSettings.IgnoreWhitespace = true;
            readerSettings.ConformanceLevel = ConformanceLevel.Fragment;
            readerSettings.DtdProcessing    = DtdProcessing.Ignore;

            // Load the fragment, validating it against the XSDs
            List <string> validationIssues = new List <string>();

            readerSettings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
            readerSettings.ValidationType  = ValidationType.Schema;
            readerSettings.Schemas         = CreateWsTrustEnvelopeSchemaSet();

            readerSettings.ValidationEventHandler += (s, e) =>
            {
                validationIssues.Add(e.Severity + " " + e.Message);
            };


            XmlDocument document = new XmlDocument();

            using (var xmlReader = XmlTextReader.Create(new StringReader(sb.ToString()), readerSettings))
            {
                document.Load(xmlReader);
            }

            Debug.WriteLine("Validation issues:");
            Debug.WriteLine(string.Join("\r\n", validationIssues.ToArray()));

            Assert.AreEqual(0, validationIssues.Count, "Not expecting any XML schema validation errors. See the test output for the validation errors.");
        }
 public async Task WsTrustRequestXmlFormatTest()
 {
     await Task.Factory.StartNew(() =>
     {
         UserCredential cred = new UserPasswordCredential("user", "pass&<>\"'");
         StringBuilder sb    = WsTrustRequest.BuildMessage("https://appliesto",
                                                           new WsTrustAddress {
             Uri = new Uri("some://resource")
         }, cred);
         try
         {
             XmlDocument doc = new XmlDocument();
             doc.LoadXml("<?xml version=\"1.0\"?>" + sb.ToString());
         }
         catch (Exception ex)
         {
             Assert.Fail("Not expected -- " + ex.Message);
         }
     });
 }
Example #6
0
        public void WsTrustRequestXmlFormatTest()
        {
            UserCredential cred = new UserPasswordCredential("user", "pass&<>\"'");
            StringBuilder  sb   = WsTrustRequest.BuildMessage("https://appliesto",
                                                              new WsTrustAddress {
                Uri = new Uri("some://resource")
            }, cred);

            try
            {
                XmlDocument document = new XmlDocument();
                document.XmlResolver        = null;
                document.PreserveWhitespace = false;
                using (var xmlReader = new XmlTextReader(new StringReader("<?xml version=\"1.0\"?>" + sb)))
                {
                    xmlReader.DtdProcessing = DtdProcessing.Ignore;
                    document.Load(xmlReader);
                }
            }
            catch (Exception)
            {
                Assert.Fail("Not expected");
            }
        }