Skip to content

Commit

Permalink
[Recorder] RemoveSanitizers API to 3.4.0 hotfix (#29662)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR
`@azure-tools/[email protected]`

### What?

- Added support for the TestProxy/removeSanitizers API, to support the
removing the central sanitizers by id at the test-proxy level.

Cherrypicking from #29661
  • Loading branch information
HarshaNalluru authored May 10, 2024
1 parent e716475 commit 5976943
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions sdk/test-utils/recorder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 3.4.0 (2024-05-08)

### Features Added

- Added support for the TestProxy/removeSanitizers API, to support the removing the central sanitizers by id at the test-proxy level.

## 3.3.0 (2024-05-07)

### Features Added
Expand Down
2 changes: 1 addition & 1 deletion sdk/test-utils/recorder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/test-recorder",
"version": "3.3.0",
"version": "3.4.0",
"sdk-type": "utility",
"description": "This library provides interfaces and helper methods to provide recording and playback capabilities for the tests in Azure JS/TS SDKs",
"main": "dist/index.js",
Expand Down
30 changes: 30 additions & 0 deletions sdk/test-utils/recorder/src/sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,36 @@ function makeBatchSanitizerBody(sanitizers: SanitizerOptions): SanitizerRequestB
);
}

/**
* Makes a /removeSanitizers request to the test proxy
* This API is meant to remove the central sanitizers that were added by the proxy-tool
* You'd need to pass the sanitizer ids that you want the test-proxy to remove for your recording
*
* Read more at https://github.com/Azure/azure-sdk-tools/pull/8142
*/
export async function removeSanitizers(
httpClient: HttpClient,
url: string,
recordingId: string | undefined,
removalList: string[],
): Promise<void> {
const uri = `${url}${paths.admin}${paths.removeSanitizers}`;
const req = createRecordingRequest(uri, undefined, recordingId);
req.headers.set("Content-Type", "application/json");
req.body = JSON.stringify({
Sanitizers: removalList,
});
logger.info("[removeSanitizers] Removing sanitizers", removalList);
const rsp = await httpClient.sendRequest({
...req,
allowInsecureConnection: true,
});
if (rsp.status !== 200) {
logger.error("[removeSanitizers] removeSanitizers request failed", rsp);
throw new RecorderError("removeSanitizers request failed.");
}
}

/**
* Makes an /addSanitizers request to the test proxy
*/
Expand Down
7 changes: 6 additions & 1 deletion sdk/test-utils/recorder/src/utils/fallbackSanitizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.

import { HttpClient } from "@azure/core-rest-pipeline";
import { addSanitizers } from "../sanitizer";
import { addSanitizers, removeSanitizers } from "../sanitizer";
import { BodyKeySanitizer, FindReplaceSanitizer, HeaderSanitizer } from "./utils";

const JSON_BODY_KEYS_TO_REDACT = [
Expand Down Expand Up @@ -125,6 +125,11 @@ export async function fallbackSanitizers(
];

const headersForRemoval: string[] = HEADER_KEYS_TO_REDACT;

// https://github.com/Azure/azure-sdk-tools/pull/8142/
const removalList = ["AZSDK2003"];
await removeSanitizers(httpClient, url, recordingId, removalList);

await addSanitizers(httpClient, url, recordingId, {
bodyKeySanitizers,
generalSanitizers,
Expand Down
1 change: 1 addition & 0 deletions sdk/test-utils/recorder/src/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const paths = {
admin: "/admin",
addSanitizer: "/addSanitizer",
addSanitizers: "/addSanitizers",
removeSanitizers: "/removeSanitizers",
info: "/info",
available: "/available",
active: "/active",
Expand Down

0 comments on commit 5976943

Please sign in to comment.