Skip to content

Commit

Permalink
Add removeSanitizer API, with default removed list + azure-core-test …
Browse files Browse the repository at this point in the history
…update
  • Loading branch information
samvaity committed May 10, 2024
1 parent d1849ed commit 1df09f3
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 18 deletions.
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ com.azure.tools:azure-sdk-build-tool;1.0.0;1.1.0-beta.1
# note: The unreleased dependencies will not be manipulated with the automatic PR creation code.
# In the pom, the version update tag after the version should name the unreleased package and the dependency version:
# <!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
unreleased_com.azure:azure-core-test;1.26.0-beta.1

# Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current
# version and set the version to the released beta. Released beta dependencies are only valid
Expand Down
2 changes: 1 addition & 1 deletion sdk/appconfiguration/azure-data-appconfiguration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/azure-communication-email/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/azure-communication-jobrouter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Base64;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand All @@ -37,6 +38,7 @@

import static com.azure.core.test.implementation.TestingHelpers.X_RECORDING_FILE_LOCATION;
import static com.azure.core.test.implementation.TestingHelpers.X_RECORDING_ID;
import static com.azure.core.test.utils.TestProxyUtils.DEFAULT_REMOVE_SANITIZER_LIST;
import static com.azure.core.test.utils.TestProxyUtils.checkForTestProxyErrors;
import static com.azure.core.test.utils.TestProxyUtils.createAddSanitizersRequest;
import static com.azure.core.test.utils.TestProxyUtils.getAssetJsonFile;
Expand Down Expand Up @@ -99,6 +101,7 @@ public Queue<String> startPlayback(File recordFile, Path testClassPath) {
= new String(Base64.getUrlDecoder().decode(response.getHeaders().getValue(X_RECORDING_FILE_LOCATION)),
StandardCharsets.UTF_8);
addProxySanitization(this.sanitizers);
removeProxySanitization(DEFAULT_REMOVE_SANITIZER_LIST);
addMatcherRequests(this.matchers);
String body = response.getBodyAsString().block();
// The test proxy stores variables in a map with no guaranteed order.
Expand Down Expand Up @@ -227,6 +230,34 @@ public void addProxySanitization(List<TestProxySanitizer> sanitizers) {
}
}

/**
* Removes the list of sanitizers from the current playback session.
* @param sanitizers The sanitizers to remove.
* @throws RuntimeException if an {@link IOException} is thrown.
*/
public void removeProxySanitization(List<String> sanitizers) {
if (isPlayingBack()) {
Map<String, List<String>> data = new HashMap<>();
data.put("Sanitizers", sanitizers);

HttpRequest request;
try {
request = new HttpRequest(HttpMethod.POST, proxyUrl + "/Admin/RemoveSanitizers")
.setBody(SERIALIZER.serialize(data, SerializerEncoding.JSON))
.setHeader(X_RECORDING_ID, xRecordingId)
.setHeader(HttpHeaderName.CONTENT_TYPE, "application/json");
} catch (IOException e) {
throw new RuntimeException(e);
}

HttpResponse response = client.sendSync(request, Context.NONE);
if (response.getStatusCode() != 200) {
throw new RuntimeException("Failed to remove sanitizers. " + response.getBodyAsBinaryData().toString());
}
response.close();
}
}

/**
* Add a list of {@link TestProxyRequestMatcher} to the current playback session.
* @param matchers The matchers to add.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
Expand All @@ -45,6 +46,9 @@ public class TestProxyUtils {
private static final HttpHeaderName X_RECORDING_SKIP = HttpHeaderName.fromString("x-recording-skip");
private static final String REDACTED_VALUE = "REDACTED";
private static final String URL_REGEX = "(?<=http://|https://)([^/?]+)";
// Removing `Operation-Location` and `$..id` from the default list of sanitizers as they are used in the SDK.
public static final List<String> DEFAULT_REMOVE_SANITIZER_LIST
= Collections.unmodifiableList(Arrays.asList("AZSDK2030", "AZSDK3430"));

// These are prepended with "$.." creating a Jsonpath expression.
private static final List<String> JSON_BODY_KEYS_TO_REDACT = Arrays.asList("authHeader", "accountKey",
Expand Down
2 changes: 1 addition & 1 deletion sdk/devcenter/azure-developer-devcenter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/digitaltwins/azure-digitaltwins-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/formrecognizer/azure-ai-formrecognizer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/azure-security-keyvault-certificates/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/azure-security-keyvault-keys/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/azure-security-keyvault-secrets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion sdk/maps/azure-maps-weather/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/openai/azure-ai-openai-assistants/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/personalizer/azure-ai-personalizer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/purview/azure-analytics-purview-sharing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sdk/resourcemanager/azure-resourcemanager-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.25.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.26.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit 1df09f3

Please sign in to comment.