Skip to content

Commit

Permalink
[Test-Proxy] Disable multipart/mixed sanitization until the additiona…
Browse files Browse the repository at this point in the history
…l work is done (#2918)

* disable multipart/mixed sanitization until the additional work is done
  • Loading branch information
scbedd authored Mar 16, 2022
1 parent c12915f commit 9fe86da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
30 changes: 15 additions & 15 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/SanitizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,24 +668,24 @@ public void UriStringSanitizerQuietlyExits(string targetValue, string replacemen
}


[Theory]
[InlineData("batchresponse_00000000-0000-0000-0000-000000000000", "batchresponse_boundary", "Test.RecordEntries/multipart_request.json")]
[InlineData("changesetresponse_955358ab-62b1-4d6c-804b-41cebb7c5e42", "changeset_boundry", "Test.RecordEntries/multipart_request.json")]
public void GeneralRegexSanitizerAffectsMultipartRequest(string regex, string replacementValue, string targetFile)
{
var session = TestHelpers.LoadRecordSession(targetFile);
// Re-enable w/ Azure/azure-sdk-tools#2900
//[Theory]
//[InlineData("batchresponse_00000000-0000-0000-0000-000000000000", "batchresponse_boundary", "Test.RecordEntries/multipart_request.json")]
//[InlineData("changesetresponse_955358ab-62b1-4d6c-804b-41cebb7c5e42", "changeset_boundry", "Test.RecordEntries/multipart_request.json")]
//public void GeneralRegexSanitizerAffectsMultipartRequest(string regex, string replacementValue, string targetFile)
//{
// var session = TestHelpers.LoadRecordSession(targetFile);

var targetEntry = session.Session.Entries[0];
var matcher = new RecordMatcher();

var sanitizer = new GeneralRegexSanitizer(value: replacementValue, regex: regex);
session.Session.Sanitize(sanitizer);
// var targetEntry = session.Session.Entries[0];
// var matcher = new RecordMatcher();

var bodyString = Encoding.UTF8.GetString(session.Session.Entries[0].Response.Body);
// var sanitizer = new GeneralRegexSanitizer(value: replacementValue, regex: regex);
// session.Session.Sanitize(sanitizer);

Assert.DoesNotContain(regex, bodyString);
Assert.Contains(replacementValue, bodyString);
}
// var bodyString = Encoding.UTF8.GetString(session.Session.Entries[0].Response.Body);

// Assert.DoesNotContain(regex, bodyString);
// Assert.Contains(replacementValue, bodyString);
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static bool TryGetTextEncoding(string contentType, out Encoding encoding)
const string appJsonPrefix = "application/json";
const string xmlSuffix = "xml";
const string urlEncodedSuffix = "-urlencoded";
const string multipartMixed = "multipart/mixed";

// Default is technically US-ASCII, but will default to UTF-8 which is a superset.
const string appFormUrlEncoded = "application/x-www-form-urlencoded";
Expand All @@ -46,8 +45,7 @@ public static bool TryGetTextEncoding(string contentType, out Encoding encoding)
contentType.EndsWith(xmlSuffix, StringComparison.OrdinalIgnoreCase) ||
contentType.EndsWith(urlEncodedSuffix, StringComparison.OrdinalIgnoreCase) ||
contentType.StartsWith(appJsonPrefix, StringComparison.OrdinalIgnoreCase) ||
contentType.StartsWith(appFormUrlEncoded, StringComparison.OrdinalIgnoreCase) ||
contentType.StartsWith(multipartMixed, StringComparison.OrdinalIgnoreCase))
contentType.StartsWith(appFormUrlEncoded, StringComparison.OrdinalIgnoreCase))
{
encoding = Encoding.UTF8;
return true;
Expand Down

0 comments on commit 9fe86da

Please sign in to comment.