From 5976943b787fa49db3aa057eca30030fa9ea12c8 Mon Sep 17 00:00:00 2001 From: Harsha Nalluru Date: Fri, 10 May 2024 00:36:40 -0700 Subject: [PATCH] [Recorder] RemoveSanitizers API to 3.4.0 hotfix (#29662) ### Packages impacted by this PR `@azure-tools/test-recorder@3.4.0` ### 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 --- sdk/test-utils/recorder/CHANGELOG.md | 6 ++++ sdk/test-utils/recorder/package.json | 2 +- sdk/test-utils/recorder/src/sanitizer.ts | 30 +++++++++++++++++++ .../recorder/src/utils/fallbackSanitizers.ts | 7 ++++- sdk/test-utils/recorder/src/utils/paths.ts | 1 + 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/sdk/test-utils/recorder/CHANGELOG.md b/sdk/test-utils/recorder/CHANGELOG.md index c3e73ca42a20..e5638cc122ff 100644 --- a/sdk/test-utils/recorder/CHANGELOG.md +++ b/sdk/test-utils/recorder/CHANGELOG.md @@ -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 diff --git a/sdk/test-utils/recorder/package.json b/sdk/test-utils/recorder/package.json index 87adfe35654e..d92ed5dfbbba 100644 --- a/sdk/test-utils/recorder/package.json +++ b/sdk/test-utils/recorder/package.json @@ -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", diff --git a/sdk/test-utils/recorder/src/sanitizer.ts b/sdk/test-utils/recorder/src/sanitizer.ts index e3892fd5503c..153273724f7f 100644 --- a/sdk/test-utils/recorder/src/sanitizer.ts +++ b/sdk/test-utils/recorder/src/sanitizer.ts @@ -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 { + 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 */ diff --git a/sdk/test-utils/recorder/src/utils/fallbackSanitizers.ts b/sdk/test-utils/recorder/src/utils/fallbackSanitizers.ts index d89504750ebe..cde653a65cff 100644 --- a/sdk/test-utils/recorder/src/utils/fallbackSanitizers.ts +++ b/sdk/test-utils/recorder/src/utils/fallbackSanitizers.ts @@ -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 = [ @@ -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, diff --git a/sdk/test-utils/recorder/src/utils/paths.ts b/sdk/test-utils/recorder/src/utils/paths.ts index 19fdebaf07f8..97474a22b35e 100644 --- a/sdk/test-utils/recorder/src/utils/paths.ts +++ b/sdk/test-utils/recorder/src/utils/paths.ts @@ -12,6 +12,7 @@ export const paths = { admin: "/admin", addSanitizer: "/addSanitizer", addSanitizers: "/addSanitizers", + removeSanitizers: "/removeSanitizers", info: "/info", available: "/available", active: "/active",