Esempio n. 1
0
        public void BodyStringSanitizerIgnoresNonTextualBodies()
        {
            var session     = TestHelpers.LoadRecordSession("Test.RecordEntries/request_with_binary_content.json");
            var targetEntry = session.Session.Entries[0];
            var content     = Encoding.UTF8.GetString(targetEntry.Request.Body);

            var bodyStringSanitizer = new BodyStringSanitizer("content");

            session.Session.Sanitize(bodyStringSanitizer);

            Assert.Equal(content, Encoding.UTF8.GetString(targetEntry.Request.Body));
        }
Esempio n. 2
0
        public void BodyStringSanitizerApplies(string targetValue, string replacementValue, string recordingFile)
        {
            var session           = TestHelpers.LoadRecordSession(recordingFile);
            var targetEntry       = session.Session.Entries[0];
            var originalBodyValue = Encoding.UTF8.GetString(targetEntry.Request.Body);

            var sanitizer = new BodyStringSanitizer(targetValue, value: replacementValue);

            session.Session.Sanitize(sanitizer);

            var resultBodyValue = Encoding.UTF8.GetString(targetEntry.Request.Body);

            Assert.NotEqual(originalBodyValue, resultBodyValue);
            Assert.Contains(replacementValue, resultBodyValue);
            Assert.DoesNotContain(targetValue, resultBodyValue);
        }
Esempio n. 3
0
        public void BodyStringSanitizerQuietlyExits(string targetValue, string replacementValue, string recordingFile)
        {
            var session              = TestHelpers.LoadRecordSession(recordingFile);
            var untouchedSession     = TestHelpers.LoadRecordSession(recordingFile);
            var targetEntry          = session.Session.Entries[0];
            var originalBodyValue    = Encoding.UTF8.GetString(targetEntry.Request.Body);
            var targetUntouchedEntry = untouchedSession.Session.Entries[0];
            var matcher              = new RecordMatcher();

            var sanitizer = new BodyStringSanitizer(targetValue, value: replacementValue);

            session.Session.Sanitize(sanitizer);

            var resultBodyValue = Encoding.UTF8.GetString(targetEntry.Request.Body);

            Assert.Equal(0, matcher.CompareBodies(targetUntouchedEntry.Request.Body, targetEntry.Request.Body));
            Assert.Equal(0, matcher.CompareBodies(targetUntouchedEntry.Response.Body, targetEntry.Response.Body));
        }