Example #1
0
        public StorageRecordedTestSanitizer()
        {
            UriRegexSanitizers.Add(UriRegexSanitizer.CreateWithQueryParameter(SignatureQueryName, SanitizeValue));

#if NETFRAMEWORK
            // Uri uses different escaping for some special characters between .NET Framework and Core. Because the Test Proxy runs on .NET
            // Core, we need to normalize to the .NET Core escaping when matching and storing the recordings when running tests on NetFramework.
            UriRegexSanitizers.Add(new UriRegexSanitizer("\\(", "%28"));
            UriRegexSanitizers.Add(new UriRegexSanitizer("\\)", "%29"));
            UriRegexSanitizers.Add(new UriRegexSanitizer("\\!", "%21"));
            UriRegexSanitizers.Add(new UriRegexSanitizer("\\'", "%27"));
            UriRegexSanitizers.Add(new UriRegexSanitizer("\\*", "%2A"));
            // Encode any colons in the Uri except for the one in the scheme
            UriRegexSanitizers.Add(new UriRegexSanitizer("(?<group>:)[^//]", "%3A")
            {
                GroupForReplace = "group"
            });
#endif

            HeaderRegexSanitizers.Add(new HeaderRegexSanitizer("x-ms-encryption-key", SanitizeValue));
            HeaderRegexSanitizers.Add(new HeaderRegexSanitizer(CopySourceAuthorization, SanitizeValue));
            HeaderRegexSanitizers.Add(HeaderRegexSanitizer.CreateWithQueryParameter(CopySourceName, SignatureQueryName, SanitizeValue));
            HeaderRegexSanitizers.Add(HeaderRegexSanitizer.CreateWithQueryParameter(RenameSource, SignatureQueryName, SanitizeValue));
            HeaderRegexSanitizers.Add(HeaderRegexSanitizer.CreateWithQueryParameter(PreviousSnapshotUrl, SignatureQueryName, SanitizeValue));
            HeaderRegexSanitizers.Add(HeaderRegexSanitizer.CreateWithQueryParameter(FileRenameSource, SignatureQueryName, SanitizeValue));

            BodyRegexSanitizers.Add(new BodyRegexSanitizer(@"client_secret=(?<group>.*?)(?=&|$)", SanitizeValue)
            {
                GroupForReplace = "group"
            });
        }
 public BackupRestoreRecordedTestSanitizer()
     : base()
 {
     AddJsonPathSanitizer("$..token");
     UriRegexSanitizers.Add(UriRegexSanitizer.CreateWithQueryParameter("sig", SanitizeValue));
 }
        public void CanSanitizeQueryParamsInUri()
        {
            var sanitizer = UriRegexSanitizer.CreateWithQueryParameter("queryParameter", "value");

            Assert.AreEqual(@"([\x0026|&|?]queryParameter=)(?<group>[\w\d%]+)", sanitizer.Regex);
        }