Skip to content
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
a2988e0
add common sanitizer for x-ms-encryption-key header
scbedd Apr 9, 2024
0cb116c
add accountkey sanitizer, tho this has never leaked
scbedd Apr 9, 2024
d149dbc
Merge remote-tracking branch 'upstream/main' into add-common-sanitizers
scbedd Apr 10, 2024
6072ccd
few more sanitizers added
scbedd Apr 10, 2024
52ea9dd
adding a few more sanitizers in order of the excel spreadsheet
scbedd Apr 11, 2024
84db37b
repair the tests so they are tolerant of changing number of default s…
scbedd Apr 11, 2024
1ed676e
bunch more bodyKey and HeaderRegex sanitizers
scbedd Apr 11, 2024
e640827
Update tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs
scbedd Apr 11, 2024
fc120e8
add the rest of the easy sanitizer adds
scbedd Apr 11, 2024
2ddae00
Merge branch 'add-common-sanitizers' of https://github.com/azure/azur…
scbedd Apr 11, 2024
1a61b39
just a few remaining to fullly finalize, then test stabilization and …
scbedd Apr 11, 2024
dac6ba7
add remaining sanitizers
scbedd Apr 11, 2024
57cd17b
add remainder of common sanitizers. time to get the tests repaired
scbedd Apr 17, 2024
1c3a6b0
fix the issues with regexes failing to compile
scbedd Apr 17, 2024
eca14ae
repair unit tests after finishing adding last remaining regexes from …
scbedd Apr 17, 2024
f4df80a
Merge remote-tracking branch 'upstream/main' into add-common-sanitizers
scbedd Apr 17, 2024
e330f7a
sanitize when loading up a recording session
scbedd Apr 17, 2024
09416c1
repair broken test
scbedd Apr 17, 2024
86e3060
actually fix the tests
scbedd Apr 17, 2024
bb0fc1e
ensure that some of the more generic bodyregexsanitizers properly onl…
scbedd Apr 18, 2024
318d6cf
add client_id and containerUrl to sanitizer defaults
scbedd Apr 19, 2024
f0c2464
Merge remote-tracking branch 'upstream/main' into add-common-sanitizers
scbedd Apr 19, 2024
c5aef35
fix the pattern
scbedd Apr 19, 2024
94dce9c
original commit without proper registration ids added yet
scbedd Apr 22, 2024
024e6d7
finish the merge, time to update the default list to be grouped by ty…
scbedd Apr 22, 2024
0859d84
uniquely label all the default sanitizers
scbedd Apr 22, 2024
d4a2a77
repair tests
scbedd Apr 22, 2024
424760b
properly fix the tests without skipping the assertions
scbedd Apr 22, 2024
957cc16
redact the hostname of all uris
scbedd Apr 22, 2024
414dfff
fix the tests. ensure that Location gets a valid sub value
scbedd Apr 22, 2024
a36890e
Location replacement value example.com->https://example.com
scbedd Apr 22, 2024
d2b3352
add remaining missing sanitiers
scbedd Apr 23, 2024
151ba1e
organize the default sanitizer list by type of sanitizer. will re-num…
scbedd Apr 23, 2024
ce71c08
categorize the sanitizers and give them gaps in numbering to allow ne…
scbedd Apr 23, 2024
098b92b
update some spacing, etc
scbedd Apr 23, 2024
5a1c65a
ensure that tenantId is an empty guid
scbedd Apr 24, 2024
077bb4f
remove duplicate sanitizer 3434
scbedd Apr 24, 2024
ef474db
BodyKeySanitizer doesn't handle it when no jtokens are parsed. fix that.
scbedd Apr 24, 2024
c701942
clean up bodyregex sanitizers
scbedd Apr 25, 2024
4fba36e
add a sanitizer test to exercise the encoded ampersand question that …
scbedd Apr 26, 2024
d443c3e
add general SAS url sanitizer
scbedd Apr 26, 2024
d813352
applicable sanitizers now apply to the entire playback session at res…
scbedd Apr 30, 2024
610758d
repair test again
scbedd Apr 30, 2024
e97e7f2
Apply suggestions from code review
scbedd Apr 30, 2024
3da60f4
Update tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/SanitizerDic…
scbedd Apr 30, 2024
eecb65a
adjust default sanitizers
scbedd May 1, 2024
6b05161
new sanitizer added pre feedback from joshlove
scbedd May 1, 2024
55c9c57
REDACTED in hostname sanitizer now defaults to 'Sanitized' like every…
scbedd May 2, 2024
89a0dd6
repair the tests
scbedd May 2, 2024
0792b7a
Update tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/SanitizerDic…
scbedd May 2, 2024
0f10c38
Update tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/SanitizerDic…
scbedd May 3, 2024
f9d6098
add some judicious locking
semick-dev May 3, 2024
9fb2313
Update tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/SanitizerDic…
scbedd May 3, 2024
4b1b0a3
encapsulate the newed up objects as well. why not
scbedd May 3, 2024
e2b5e19
ensure that we don't double sanitizer or _not_ sanitizer on parallel …
scbedd May 3, 2024
01ab1a2
Update the BodyRegex sanitizers for token strings to end on a few add…
scbedd May 6, 2024
afd8602
update the string to properly escape newline
scbedd May 6, 2024
c1c068b
repair broken regex pattern
scbedd May 6, 2024
f814fbe
adding two headerRegexSanitizers
scbedd May 6, 2024
477bcc9
update the token sanitization
scbedd May 6, 2024
7cd07c4
all glob uses + instead of *
scbedd May 6, 2024
31b4772
add a lock instead of an init queue to the restore() operation.
scbedd May 8, 2024
980d20a
fix multiple sanitizers registering to a single recording
scbedd May 8, 2024
d0d0a91
add a unit test to double check encoding
scbedd May 9, 2024
09f178b
Update tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitAssetsConf…
scbedd May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/InfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Azure.Sdk.Tools.TestProxy.Tests
{
public class InfoTests
{
private int DefaultExtensionCount { get { return new RecordingHandler(null).SanitizerRegistry.GetSanitizers().Count; } }

[Fact]
public void TestReflectionModelBuild()
{
Expand Down Expand Up @@ -79,17 +81,17 @@ public async Task TestReflectionModelWithTargetRecordSession()
var model = new ActiveMetadataModel(testRecordingHandler, recordingId);
var descriptions = model.Descriptions.ToList();

// we should have exactly 6 if we're counting all the customizations appropriately
Assert.True(descriptions.Count == 6);
// we should have exactly DefaultExtensionCount + 2 if we're counting all the customizations appropriately
Assert.True(descriptions.Count == DefaultExtensionCount + 3);
Assert.True(model.Matchers.Count() == 1);
Assert.True(model.Sanitizers.Count() == 5);
Assert.True(model.Sanitizers.Count() == DefaultExtensionCount + 2);

// confirm that the overridden matcher is showing up
Assert.True(descriptions[3].ConstructorDetails.Arguments[1].Item2 == "\"ABC123\"");
Assert.True(descriptions[4].ConstructorDetails.Arguments[1].Item2 == "\".+?\"");
Assert.True(descriptions[DefaultExtensionCount].ConstructorDetails.Arguments[1].Item2 == "\"ABC123\"");
Assert.True(descriptions[DefaultExtensionCount + 1].ConstructorDetails.Arguments[1].Item2 == "\".+?\"");

// and finally confirm our sanitizers are what we expect
Assert.True(descriptions[5].Name == "CustomDefaultMatcher");
Assert.True(descriptions[DefaultExtensionCount + 2].Name == "CustomDefaultMatcher");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task PlaybackLogsSanitizedRequest()
HttpResponse response = new DefaultHttpContext().Response;
await testRecordingHandler.HandlePlaybackRequest(recordingId, request, response);

AssertLogs(logger, 4, 8);
AssertLogs(logger, 4, 8, 7);
}
finally
{
Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task RecordingHandlerLogsSanitizedRequests()

try
{
AssertLogs(logger, 2, 8);
AssertLogs(logger, 2, 8, 12);
}
finally
{
Expand All @@ -101,7 +101,7 @@ public async Task RecordingHandlerLogsSanitizedRequests()
}
}

private static void AssertLogs(TestLogger logger, int offset, int expectedLength)
private static void AssertLogs(TestLogger logger, int offset, int expectedLength, int expectedContentLength)
{
Assert.Equal(expectedLength, logger.Logs.Count);
Assert.Equal(
Expand All @@ -116,10 +116,10 @@ private static void AssertLogs(TestLogger logger, int offset, int expectedLength
Assert.Equal(
"Request Body Content{\"key\":\"Location\",\"value\":\"https://fakeazsdktestaccount.table.core.windows.net/Tables\"}",
logger.Logs[2 + offset].ToString());
Assert.Equal("URI: [ https://fakeazsdktestaccount.table.core.windows.net/Tables]" +
Assert.Equal("URI: [ https://REDACTED.table.core.windows.net/Tables]" +
Environment.NewLine + "Headers: [{\"Accept\":[\"application/json;odata=minimalmetadata\"],\"Accept-Encoding\":[\"gzip, deflate\"],\"Authorization\":[\"Sanitized\"],\"Connection\":[\"keep-alive\"]," +
"\"Content-Length\":[\"12\"],\"Content-Type\":[\"application/octet-stream\"],\"DataServiceVersion\":[\"3.0\"],\"Date\":[\"Tue, 18 May 2021 23:27:42 GMT\"]," +
"\"User-Agent\":[\"azsdk-python-data-tables/12.0.0b7 Python/3.8.6 (Windows-10-10.0.19041-SP0)\"],\"x-ms-client-request-id\":[\"a4c24b7a-b830-11eb-a05e-10e7c6392c5a\"]," +
"\"Content-Length\":[\"" + expectedContentLength + "\"],\"Content-Type\":[\"application/octet-stream\"],\"DataServiceVersion\":[\"3.0\"],\"Date\":[\"Tue, 18 May 2021 23:27:42 GMT\"]," +
"\"User-Agent\":[\"azsdk-python-data-tables/12.0.0b7 Python/3.8.6 (Windows-10-10.0.19041-SP0)\"],\"x-ms-client-request-id\":[\"Sanitized\"]," +
"\"x-ms-date\":[\"Tue, 18 May 2021 23:27:42 GMT\"],\"x-ms-version\":[\"2019-02-02\"]}]" + Environment.NewLine,
logger.Logs[3 + offset].ToString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace Azure.Sdk.Tools.TestProxy.Tests
{
public class RecordingHandlerTests
{
private int DefaultExtensionCount { get { return new RecordingHandler(null).SanitizerRegistry.DefaultSanitizerList.Count; } }

#region helpers and private test fields
private HttpContext GenerateHttpRequestContext(string[] headerValueStrings)
{
Expand Down Expand Up @@ -97,11 +99,15 @@ private void _checkDefaultExtensions(RecordingHandler handlerForTest, CheckSkips

if (skipsToCheck.HasFlag(CheckSkips.IncludeSanitizers))
{
var sessionSanitizers = handlerForTest.SanitizerRegistry.GetSanitizers();
Assert.Equal(3, sessionSanitizers.Count);
Assert.IsType<RecordedTestSanitizer>(sessionSanitizers[0]);
Assert.IsType<BodyKeySanitizer>(sessionSanitizers[1]);
Assert.IsType<BodyKeySanitizer>(sessionSanitizers[2]);

var sanitizers = handlerForTest.SanitizerRegistry.GetSanitizers();

Assert.Equal(DefaultExtensionCount, sanitizers.Count);
Assert.IsType<RecordedTestSanitizer>(sanitizers[0]);
Assert.IsType<BodyKeySanitizer>(sanitizers[1]);
Assert.IsType<BodyKeySanitizer>(sanitizers[2]);
Assert.IsType<HeaderRegexSanitizer>(sanitizers[75]);
Assert.IsType<BodyRegexSanitizer>(sanitizers[108]);
}
}
#endregion
Expand Down Expand Up @@ -302,7 +308,7 @@ public async Task TestLoadOfAbsoluteRecording()
var playbackSession = recordingHandler.PlaybackSessions.First();
var entry = playbackSession.Value.Session.Entries.First();

Assert.Equal("https://login.microsoftonline.com/12345678-1234-1234-1234-123456789012/oauth2/v2.0/token", entry.RequestUri);
Assert.Equal("https://REDACTED.microsoftonline.com/12345678-1234-1234-1234-123456789012/oauth2/v2.0/token", entry.RequestUri);
}

[Fact]
Expand All @@ -318,7 +324,7 @@ public async Task TestLoadOfRelativeRecording()
var playbackSession = recordingHandler.PlaybackSessions.First();
var entry = playbackSession.Value.Session.Entries.First();

Assert.Equal("https://login.microsoftonline.com/12345678-1234-1234-1234-123456789012/oauth2/v2.0/token", entry.RequestUri);
Assert.Equal("https://REDACTED.microsoftonline.com/12345678-1234-1234-1234-123456789012/oauth2/v2.0/token", entry.RequestUri);
}

[Fact]
Expand Down Expand Up @@ -445,7 +451,7 @@ public async Task TestCanSkipRecordingEntireRequestResponse()
var record = RecordSession.Deserialize(doc.RootElement);
Assert.Single(record.Entries);
var entry = record.Entries.First();
Assert.Equal("value", JsonDocument.Parse(entry.Request.Body).RootElement.GetProperty("key").GetString());
Assert.Equal("Sanitized", JsonDocument.Parse(entry.Request.Body).RootElement.GetProperty("key").GetString());
Assert.Equal(MockHttpHandler.DefaultResponse, Encoding.UTF8.GetString(entry.Response.Body));
}
finally
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Azure.Sdk.Tools.TestProxy.Common;
using Azure.Sdk.Tools.TestProxy.Common;
using Azure.Sdk.Tools.TestProxy.Transforms;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -132,14 +132,14 @@ public async Task ApiTransformPullsFromRequest()
public async Task CanApplyHeaderTransformWithCondition()
{
var headerTransform = new HeaderTransform(
"Location",
"http://localhost",
"X-Content-Type-Options",
"replaced",
condition: new ApplyCondition
{
ResponseHeader = new HeaderCondition
{
Key = "Location",
ValueRegex = @".*/Tables\(.*"
Key = "X-Content-Type-Options",
ValueRegex = ".*nosniff.*"
}
});
RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory());
Expand Down Expand Up @@ -170,15 +170,15 @@ public async Task CanApplyHeaderTransformWithCondition()
HttpRequest request = TestHelpers.CreateRequestFromEntry(transformedEntry);
HttpResponse response = new DefaultHttpContext().Response;
await testRecordingHandler.HandlePlaybackRequest(recordingId, request, response);
Assert.Equal("http://localhost", response.Headers["Location"]);
Assert.Equal("replaced", response.Headers["X-Content-Type-Options"]);

// this one should keep the original Location value
request = TestHelpers.CreateRequestFromEntry(untransformedEntry);
response = new DefaultHttpContext().Response;
await testRecordingHandler.HandlePlaybackRequest(recordingId, request, response);
var originalLocation = untransformedEntry.Response.Headers["Location"];

Assert.Equal(originalLocation, response.Headers["Location"]);
Assert.NotEqual(originalLocation, response.Headers["Location"]);
}
}
}
Loading