Пример #1
0
        public void GenStringSanitizerQuietExitForAllHttpComponents()
        {
            var session          = TestHelpers.LoadRecordSession("Test.RecordEntries/post_delete_get_content.json");
            var untouchedSession = TestHelpers.LoadRecordSession("Test.RecordEntries/post_delete_get_content.json");

            var targetString         = ".*";
            var replacementString    = "<thistablehasbeenreplaced!>";
            var targetEntry          = session.Session.Entries[0];
            var targetUntouchedEntry = untouchedSession.Session.Entries[0];
            var matcher = new RecordMatcher();

            var sanitizer = new GeneralStringSanitizer(targetString, replacementString);

            session.Session.Sanitize(sanitizer);

            var resultRequestBody  = Encoding.UTF8.GetString(targetEntry.Request.Body);
            var resultResponseBody = Encoding.UTF8.GetString(targetEntry.Response.Body);
            var resultLocation     = targetEntry.Response.Headers["Location"].First().ToString();

            Assert.DoesNotContain(targetString, resultRequestBody);
            Assert.DoesNotContain(targetString, resultResponseBody);
            Assert.DoesNotContain(targetString, resultLocation);

            Assert.Equal(0, matcher.CompareHeaderDictionaries(targetUntouchedEntry.Request.Headers, targetEntry.Request.Headers, new HashSet <string>(), new HashSet <string>()));
            Assert.Equal(0, matcher.CompareHeaderDictionaries(targetUntouchedEntry.Response.Headers, targetEntry.Response.Headers, new HashSet <string>(), new HashSet <string>()));
            Assert.Equal(0, matcher.CompareBodies(targetUntouchedEntry.Request.Body, targetEntry.Request.Body));
            Assert.Equal(0, matcher.CompareBodies(targetUntouchedEntry.Response.Body, targetEntry.Response.Body));
            Assert.Equal(targetUntouchedEntry.RequestUri, targetEntry.RequestUri);
        }
Пример #2
0
        public void GenStringSanitizerAppliesForMultipleComponents()
        {
            var session           = TestHelpers.LoadRecordSession("Test.RecordEntries/post_delete_get_content.json");
            var targetString      = "listtable09bf2a3d";
            var replacementString = "<thistablehasbeenreplaced!>";
            var targetEntry       = session.Session.Entries[0];

            var originalRequestBody  = Encoding.UTF8.GetString(targetEntry.Request.Body);
            var originalResponseBody = Encoding.UTF8.GetString(targetEntry.Response.Body);
            var originalLocation     = targetEntry.Response.Headers["Location"].First().ToString();

            var sanitizer = new GeneralStringSanitizer(targetString, replacementString);

            session.Session.Sanitize(sanitizer);

            var resultRequestBody  = Encoding.UTF8.GetString(targetEntry.Request.Body);
            var resultResponseBody = Encoding.UTF8.GetString(targetEntry.Response.Body);
            var resultLocation     = targetEntry.Response.Headers["Location"].First().ToString();


            // request body
            Assert.NotEqual(originalRequestBody, resultRequestBody);
            Assert.DoesNotContain(targetString, resultRequestBody);
            Assert.Contains(replacementString, resultRequestBody);

            // result body
            Assert.NotEqual(originalResponseBody, resultResponseBody);
            Assert.DoesNotContain(targetString, resultResponseBody);
            Assert.Contains(replacementString, resultResponseBody);

            // uri
            Assert.NotEqual(originalLocation, resultLocation);
            Assert.DoesNotContain(targetString, resultLocation);
            Assert.Contains(replacementString, resultLocation);
        }