Skip to content

Commit

Permalink
allow the sanitizers to clear
Browse files Browse the repository at this point in the history
  • Loading branch information
scbedd committed Aug 2, 2024
1 parent 812273d commit d420268
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ public async Task RemoveSanitizerErrorsForInvalidIdOnRecording()
}

[Fact]
public async Task RemoveSanitizerErrorsForInvalidId()
public async Task RemoveSanitizersSilentlyAcceptsInvalidSanitizer()
{
RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory());
var httpContext = new DefaultHttpContext();
Expand All @@ -980,11 +980,9 @@ public async Task RemoveSanitizerErrorsForInvalidId()

var testSet = new RemoveSanitizerList() { Sanitizers = new List<string>() { "AZSDK00-1" } };

var assertion = await Assert.ThrowsAsync<HttpException>(
async () => await controller.RemoveSanitizers(testSet)
);
await controller.RemoveSanitizers(testSet);

Assert.Equal("Unable to remove 1 sanitizer. Detailed list follows: \nThe requested sanitizer for removal \"AZSDK00-1\" is not active at the session level.", assertion.Message);
Assert.Equal(200, httpContext.Response.StatusCode);
}

[Fact]
Expand Down
25 changes: 6 additions & 19 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy/Admin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,39 +70,26 @@ public async Task RemoveSanitizers([FromBody]RemoveSanitizerList sanitizerList)
var recordingId = RecordingHandler.GetHeader(Request, "x-recording-id", allowNulls: true);

var removedSanitizers = new List<string>();
var exceptionsList = new List<string>();

if (sanitizerList.Sanitizers.Count == 0)
{
throw new HttpException(HttpStatusCode.BadRequest, "At least one sanitizerId for removal must be provided.");
}

foreach(var sanitizerId in sanitizerList.Sanitizers) {
try
var removedId = await _recordingHandler.UnregisterSanitizer(sanitizerId, recordingId);
if (!string.IsNullOrWhiteSpace(removedId))
{
var removedId = await _recordingHandler.UnregisterSanitizer(sanitizerId, recordingId);
removedSanitizers.Add(sanitizerId);
}
catch (HttpException ex) {
exceptionsList.Add(ex.Message);
}
}

if (exceptionsList.Count > 0)
{
var varExceptionMessage = $"Unable to remove {exceptionsList.Count} sanitizer{(exceptionsList.Count > 1 ? 's' : string.Empty)}. Detailed list follows: \n"
+ string.Join("\n", exceptionsList);
throw new HttpException(HttpStatusCode.BadRequest, varExceptionMessage);
}
else
{
var json = JsonSerializer.Serialize(new { Removed = removedSanitizers });
var json = JsonSerializer.Serialize(new { Removed = removedSanitizers });

Response.ContentType = "application/json";
Response.ContentLength = json.Length;
Response.ContentType = "application/json";
Response.ContentLength = json.Length;

await Response.WriteAsync(json);
}
await Response.WriteAsync(json);
}

[HttpGet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ public async Task<string> Unregister(string sanitizerId)
SessionSanitizerLock.Release();
}

throw new HttpException(System.Net.HttpStatusCode.BadRequest, $"The requested sanitizer for removal \"{sanitizerId}\" is not active at the session level.");
return string.Empty;
}

/// <summary>
Expand All @@ -918,7 +918,7 @@ public async Task<string> Unregister(string sanitizerId, ModifiableRecordSession
session.SanitizerLock.Release();
}

throw new HttpException(System.Net.HttpStatusCode.BadRequest, $"The requested sanitizer for removal \"{sanitizerId}\" is not active on recording/playback with id \"{session.SessionId}\".");
return string.Empty;
}

/// <summary>
Expand Down

0 comments on commit d420268

Please sign in to comment.