Skip to content

Commit

Permalink
Don't sanitize binary data when using BodyStringSanitizer (#2782)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLove-msft authored Feb 17, 2022
1 parent 0095008 commit e697883
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 13 additions & 0 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/SanitizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,19 @@ public void BodyStringSanitizerQuietlyExits(string targetValue, string replaceme
Assert.Equal(0, matcher.CompareBodies(targetUntouchedEntry.Response.Body, targetEntry.Response.Body));
}

[Fact]
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));
}

[Theory]
[InlineData("/v2.0/", "<oath-v2>", "Test.RecordEntries/oauth_request.json")]
[InlineData("https://management.azure.com/subscriptions/12345678-1234-1234-5678-123456789010", "<partofpath>", "Test.RecordEntries/request_with_subscriptionid.json")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,5 @@ public override string SanitizeTextBody(string contentType, string body)
{
return StringSanitizer.ReplaceValue(inputValue: body, targetValue: _targetValue, replacementValue: _newValue);
}


public override byte[] SanitizeBody(string contentType, byte[] body)
{
return Encoding.UTF8.GetBytes(StringSanitizer.ReplaceValue(inputValue: Encoding.UTF8.GetString(body), targetValue: _targetValue, replacementValue: _newValue));
}
}
}

0 comments on commit e697883

Please sign in to comment.