Skip to content

Commit

Permalink
testing new regex
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity authored Jul 18, 2023
1 parent a9e2eea commit bf72f5d
Showing 1 changed file with 1 addition and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,56 +25,6 @@ namespace Azure.Sdk.Tools.TestProxy.Tests
/// </summary>
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()
Expand All @@ -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";
Expand Down

0 comments on commit bf72f5d

Please sign in to comment.