From bf72f5d5ae211eca0e9ef9705639eff26f44b30e Mon Sep 17 00:00:00 2001 From: Sameeksha Vaity Date: Tue, 18 Jul 2023 16:23:08 -0700 Subject: [PATCH] testing new regex --- .../SanitizerTestExample.cs | 52 +------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/SanitizerTestExample.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/SanitizerTestExample.cs index 5563f1d2e8f..02b0afa2603 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/SanitizerTestExample.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/SanitizerTestExample.cs @@ -25,56 +25,6 @@ namespace Azure.Sdk.Tools.TestProxy.Tests /// public class SanitizerTestExample { - [Fact] - public void SanitizerWorksAgainstSample() - { - var session = TestHelpers.LoadRecordSession("Test.RecordEntries/sample_entry.json"); - - var uriRegexSanitizer = new BodyKeySanitizer(jsonPath: "$..trunks", value: "redacted.com"); - - session.Session.Sanitize(uriRegexSanitizer); - var newBody = Encoding.UTF8.GetString(session.Session.Entries[2].Response.Body); - System.Console.WriteLine(newBody); - Assert.Contains("redacted.com", newBody); - } - - [Fact] - public async Task APISanitizerWorksAgainstSample() - { - var session = TestHelpers.LoadRecordSession("Test.RecordEntries/sample_entry.json"); - - // this is what your json body will look like coming over the wire. Notice the double escapes to prevent JSON parse break. - // it is an identical sanitizer registration to the one above - var overTheWire = "{ \"value\": \"redacted.com\", \"jsonPath\": \"$..trunks\" }"; - - // Target the type of sanitizer using this. (This is similar to selecting a constructor above) - var sanitizerName = "BodyKeySanitizer"; - - - #region API registration and running of sanitizer - // feel free to ignore this setup, bunch of implementation details to register as if coming from external request - RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory()); - testRecordingHandler.Sanitizers.Clear(); - var httpContext = new DefaultHttpContext(); - httpContext.Request.Headers["x-abstraction-identifier"] = sanitizerName; - httpContext.Request.Body = TestHelpers.GenerateStreamRequestBody(overTheWire); - httpContext.Request.ContentLength = httpContext.Request.Body.Length; - var controller = new Admin(testRecordingHandler, new NullLoggerFactory()) - { - ControllerContext = new ControllerContext() - { - HttpContext = httpContext - } - }; - await controller.AddSanitizer(); - var registeredSanitizer = testRecordingHandler.Sanitizers[0]; - Assert.NotNull(registeredSanitizer); - #endregion - - session.Session.Sanitize(registeredSanitizer); - var newBody = Encoding.UTF8.GetString(session.Session.Entries[2].Response.Body); - Assert.Contains("redacted.com", newBody); - } [Fact] public async Task ThisShouldWork() @@ -83,7 +33,7 @@ public async Task ThisShouldWork() // this is what your json body will look like coming over the wire. Notice the double escapes to prevent JSON parse break. // it is an identical sanitizer registration to the one above - var overTheWire = "{ \"value\": \".sanitized.com\", \"regex\": \"([0-9a-fA-F]{8}\\\\-[0-9a-fA-F]{4}\\\\-[0-9a-fA-F]{4}\\\\-[0-9a-fA-F]{4}\\\\-[0-9a-fA-F]{12}[^/?]+)\" }"; + var overTheWire = "{ \"value\": \".sanitized.com\", \"regex\": \"(-[0-9a-fA-F]{32}.[0-9a-fA-F]{8}\\\\-[0-9a-fA-F]{4}\\\\-[0-9a-fA-F]{4}\\\\-[0-9a-fA-F]{4}\\\\-[0-9a-fA-F]{12}[^/?]+)\" }"; // Target the type of sanitizer using this. (This is similar to selecting a constructor above) var sanitizerName = "BodyRegexSanitizer";