Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key Vault test proxy migration #34321

Merged
merged 24 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1baaf19
Updated Key vault tests to use TestProxyTestBase instead of TestBase.
vcolin7 Apr 4, 2023
21b840f
Re-recorded Key Vault tests.
vcolin7 Apr 4, 2023
48546db
Merge branch 'upstream-main' into kv-test-proxy-migration
vcolin7 Apr 5, 2023
178f8c2
Fixed CredScan issues.
vcolin7 Apr 6, 2023
b497073
Merge branch 'upstream-main' into kv-test-proxy-migration
vcolin7 Apr 6, 2023
67c203f
Added custom matchers to avoid body issues during playback.
vcolin7 Apr 6, 2023
2073901
Merge branch 'upstream-main' into kv-test-proxy-migration
vcolin7 Apr 12, 2023
408b176
Ensured we clear the token cache of tests before running them.
vcolin7 Apr 12, 2023
64aa274
Re-recorded tests.
vcolin7 Apr 12, 2023
80fbe5a
Fixed Checkstyle issue.
vcolin7 Apr 12, 2023
c4b9ddd
Fixed playback issues.
vcolin7 Apr 12, 2023
b51baef
Fixed CheckStyle issues.
vcolin7 Apr 13, 2023
2161755
Fixed CredScan issues.
vcolin7 Apr 13, 2023
35abf88
Made JsonWebKey's logger static and fixed some test playback issues.
vcolin7 Apr 13, 2023
8a718b4
Removed the "logger" key from request bodies.
vcolin7 Apr 14, 2023
098d727
Made all ClientLogger instances static.
vcolin7 Apr 14, 2023
e47c0d1
Added matchers to avoid comparing the body of requests.
vcolin7 Apr 14, 2023
2f00f9e
Added custom matcher to avoid comparing authorization headers.
vcolin7 Apr 14, 2023
c8ba9b6
Merge branch 'main' into kv-test-proxy-migration
vcolin7 Apr 17, 2023
455d0a0
Updated tests to use MockTokenCredential in playback mode.
vcolin7 Apr 17, 2023
677cb76
Removed unused imports.
vcolin7 Apr 17, 2023
fcfb16c
Merge branch 'upstream-main' into kv-test-proxy-migration
vcolin7 Apr 20, 2023
e82f3d0
Removed custom matcher for authorization header.
vcolin7 Apr 20, 2023
50369ed
Revert "Removed custom matcher for authorization header."
vcolin7 Apr 20, 2023
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
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.15.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.16.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core-test;current} -->
vcolin7 marked this conversation as resolved.
Show resolved Hide resolved
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.models.TestProxyRequestMatcher;
import com.azure.core.test.models.TestProxyRequestMatcher.TestProxyRequestMatcherType;
import com.azure.core.test.models.TestProxySanitizer;
import com.azure.core.test.models.TestProxySanitizerType;
import com.azure.core.util.Configuration;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.azure.security.keyvault.administration.implementation.KeyVaultCredentialPolicy;
Expand All @@ -27,7 +32,7 @@
import java.util.Objects;
import java.util.stream.Stream;

public abstract class KeyVaultAdministrationClientTestBase extends TestBase {
public abstract class KeyVaultAdministrationClientTestBase extends TestProxyTestBase {
private static final String SDK_NAME = "client_name";
private static final String SDK_VERSION = "client_version";
protected static final boolean IS_MANAGED_HSM_DEPLOYED =
Expand All @@ -48,6 +53,14 @@ protected String getTestName() {
protected List<HttpPipelinePolicy> getPolicies() {
TokenCredential credential = null;

List<TestProxySanitizer> customSanitizers = new ArrayList<>();
customSanitizers.add(new TestProxySanitizer("token", "REDACTED", TestProxySanitizerType.BODY_KEY));
interceptorManager.addSanitizers(customSanitizers);

List<TestProxyRequestMatcher> customMatcher = new ArrayList<>();
customMatcher.add(new TestProxyRequestMatcher(TestProxyRequestMatcherType.BODILESS));
interceptorManager.addMatchers(customMatcher);

if (!interceptorManager.isPlaybackMode()) {
String clientId = Configuration.getGlobalConfiguration().get("AZURE_KEYVAULT_CLIENT_ID");
String clientKey = Configuration.getGlobalConfiguration().get("AZURE_KEYVAULT_CLIENT_SECRET");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,109 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://REDACTED.managedhsm.azure.net///providers/Microsoft.Authorization/roleDefinitions/5506a46f-c62b-49af-9f03-3fc36c366e53?api-version=7.4",
"Headers" : {
"User-Agent" : "azsdk-java-client_name/client_version (18.0.2; Windows 11; 10.0)",
"Content-Type" : "application/json"
"Entries": [
{
"RequestUri": "https://REDACTED///providers/Microsoft.Authorization/roleDefinitions/e52e58b6-bced-4b91-8626-3663f2eaa27b?api-version=7.4",
"RequestMethod": "PUT",
"RequestHeaders": {
"Accept": "application/json",
"Content-Length": "0",
"Content-Type": "application/json",
"User-Agent": "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)"
},
"RequestBody": null,
"StatusCode": 401,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "0",
"Content-Security-Policy": "default-src \u0027self\u0027",
"Content-Type": "application/json; charset=utf-8",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"WWW-Authenticate": "Bearer authorization=\u0022https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47\u0022, resource=\u0022https://managedhsm.azure.net\u0022",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "SAMEORIGIN",
"x-ms-request-id": "337b3a42-d29f-11ed-af10-0022488d0014",
"x-ms-server-latency": "7"
},
"ResponseBody": null
},
"Response" : {
"content-length" : "353",
"x-frame-options" : "SAMEORIGIN",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-server-latency" : "38",
"strict-transport-security" : "max-age=31536000; includeSubDomains",
"content-security-policy" : "default-src 'self'",
"x-content-type-options" : "nosniff",
"x-ms-keyvault-network-info" : "conn_type=Ipv4;addr=187.190.190.225;act_addr_fam=Ipv4;",
"x-ms-keyvault-region" : "northcentralus",
"content-type" : "application/json; charset=utf-8",
"cache-control" : "no-cache",
"x-ms-request-id" : "006f261c-c3d2-11ed-8971-0022488d0014",
"Body" : "{\"id\":\"Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/5506a46f-c62b-49af-9f03-3fc36c366e53\",\"name\":\"5506a46f-c62b-49af-9f03-3fc36c366e53\",\"properties\":{\"assignableScopes\":[\"/\"],\"description\":\"\",\"permissions\":[],\"roleName\":\"5506a46f-c62b-49af-9f03-3fc36c366e53\",\"type\":\"CustomRole\"},\"type\":\"Microsoft.Authorization/roleDefinitions\"}"
{
"RequestUri": "https://REDACTED///providers/Microsoft.Authorization/roleAssignments/83b4ba18-ed57-4a13-b9d7-3a08b0698e32?api-version=7.4",
"RequestMethod": "PUT",
"RequestHeaders": {
"Accept": "application/json",
"Authorization": "Sanitized",
"Content-Length": "196",
"Content-Type": "application/json",
"User-Agent": "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)"
},
"RequestBody": {
"properties": {
"roleDefinitionId": "Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/e52e58b6-bced-4b91-8626-3663f2eaa27b",
"principalId": "aed295e0-2ae7-4c2a-9abc-813f0ca233d3"
}
},
"StatusCode": 201,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "398",
"Content-Security-Policy": "default-src \u0027self\u0027",
"Content-Type": "application/json; charset=utf-8",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "SAMEORIGIN",
"x-ms-keyvault-network-info": "conn_type=Ipv4;addr=172.92.148.195;act_addr_fam=Ipv4;",
"x-ms-keyvault-region": "northcentralus",
"x-ms-request-id": "375b6d8a-d29f-11ed-a359-0022488dd761",
"x-ms-server-latency": "40"
},
"ResponseBody": {
"id": "/providers/Microsoft.Authorization/roleAssignments/83b4ba18-ed57-4a13-b9d7-3a08b0698e32",
"name": "83b4ba18-ed57-4a13-b9d7-3a08b0698e32",
"properties": {
"principalId": "aed295e0-2ae7-4c2a-9abc-813f0ca233d3",
"roleDefinitionId": "Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/e52e58b6-bced-4b91-8626-3663f2eaa27b",
"scope": "/"
},
"type": "Microsoft.Authorization/roleAssignments"
}
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.managedhsm.azure.net///providers/Microsoft.Authorization/roleAssignments/c346007a-4692-4bd8-858b-0b7eff82b049?api-version=7.4",
"Headers" : {
"User-Agent" : "azsdk-java-client_name/client_version (18.0.2; Windows 11; 10.0)",
"Content-Type" : "application/json"
},
"Response" : {
"content-length" : "398",
"x-frame-options" : "SAMEORIGIN",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-server-latency" : "39",
"strict-transport-security" : "max-age=31536000; includeSubDomains",
"content-security-policy" : "default-src 'self'",
"x-content-type-options" : "nosniff",
"x-ms-keyvault-network-info" : "conn_type=Ipv4;addr=187.190.190.225;act_addr_fam=Ipv4;",
"x-ms-keyvault-region" : "northcentralus",
"content-type" : "application/json; charset=utf-8",
"cache-control" : "no-cache",
"x-ms-request-id" : "037c0640-c3d2-11ed-8971-0022488d0014",
"Body" : "{\"id\":\"/providers/Microsoft.Authorization/roleAssignments/c346007a-4692-4bd8-858b-0b7eff82b049\",\"name\":\"c346007a-4692-4bd8-858b-0b7eff82b049\",\"properties\":{\"principalId\":\"f84ae8f9-c979-4750-a2fe-b350a00bebff\",\"roleDefinitionId\":\"Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/5506a46f-c62b-49af-9f03-3fc36c366e53\",\"scope\":\"/\"},\"type\":\"Microsoft.Authorization/roleAssignments\"}"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.managedhsm.azure.net///providers/Microsoft.Authorization/roleAssignments/c346007a-4692-4bd8-858b-0b7eff82b049?api-version=7.4",
"Headers" : {
"User-Agent" : "azsdk-java-client_name/client_version (18.0.2; Windows 11; 10.0)",
"Content-Type" : "application/json"
},
"Response" : {
"content-length" : "141",
"content-security-policy" : "default-src 'self'",
"x-content-type-options" : "nosniff",
"x-frame-options" : "SAMEORIGIN",
"content-type" : "application/json; charset=utf-8",
"retry-after" : "0",
"cache-control" : "no-cache",
"StatusCode" : "400",
"x-ms-request-id" : "06876668-c3d2-11ed-8971-0022488d0014",
"Body" : "{\"error\":{\"code\":\"RoleAssignmentExists\",\"message\":\"The role assignment already exists. (Activity ID: 06876668-c3d2-11ed-8971-0022488d0014)\"}}",
"strict-transport-security" : "max-age=31536000; includeSubDomains",
"x-ms-server-latency" : "2"
},
"Exception" : null
} ],
"variables" : [ "5506a46f-c62b-49af-9f03-3fc36c366e53", "c346007a-4692-4bd8-858b-0b7eff82b049" ]
}
{
"RequestUri": "https://REDACTED///providers/Microsoft.Authorization/roleAssignments/83b4ba18-ed57-4a13-b9d7-3a08b0698e32?api-version=7.4",
"RequestMethod": "PUT",
"RequestHeaders": {
"Accept": "application/json",
"Authorization": "Sanitized",
"Content-Length": "196",
"Content-Type": "application/json",
"User-Agent": "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)"
},
"RequestBody": {
"properties": {
"roleDefinitionId": "Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/e52e58b6-bced-4b91-8626-3663f2eaa27b",
"principalId": "aed295e0-2ae7-4c2a-9abc-813f0ca233d3"
}
},
"StatusCode": 400,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "141",
"Content-Security-Policy": "default-src \u0027self\u0027",
"Content-Type": "application/json; charset=utf-8",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "SAMEORIGIN",
"x-ms-request-id": "3a66c4d4-d29f-11ed-a359-0022488dd761",
"x-ms-server-latency": "1"
},
"ResponseBody": {
"error": {
"code": "RoleAssignmentExists",
"message": "The role assignment already exists. (Activity ID: 3a66c4d4-d29f-11ed-a359-0022488dd761)"
}
}
}
],
"Variables": {
"0": "e52e58b6-bced-4b91-8626-3663f2eaa27b",
"1": "83b4ba18-ed57-4a13-b9d7-3a08b0698e32"
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,74 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://REDACTED.managedhsm.azure.net///providers/Microsoft.Authorization/roleDefinitions/dda7d908-8b08-41c9-ac1b-cc255694851e?api-version=7.4",
"Headers" : {
"User-Agent" : "azsdk-java-client_name/client_version (18.0.2; Windows 11; 10.0)",
"Content-Type" : "application/json"
"Entries": [
{
"RequestUri": "https://REDACTED///providers/Microsoft.Authorization/roleDefinitions/cd952fa0-caac-488e-a5af-d57b6af2886d?api-version=7.4",
"RequestMethod": "PUT",
"RequestHeaders": {
"Accept": "application/json",
"Content-Length": "0",
"Content-Type": "application/json",
"User-Agent": "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)"
},
"RequestBody": null,
"StatusCode": 401,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "0",
"Content-Security-Policy": "default-src \u0027self\u0027",
"Content-Type": "application/json; charset=utf-8",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"WWW-Authenticate": "Bearer authorization=\u0022https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47\u0022, resource=\u0022https://managedhsm.azure.net\u0022",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "SAMEORIGIN",
"x-ms-request-id": "c9499956-d29f-11ed-b07e-000d3a610397",
"x-ms-server-latency": "3"
},
"ResponseBody": null
},
"Response" : {
"content-length" : "353",
"x-frame-options" : "SAMEORIGIN",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-server-latency" : "36",
"strict-transport-security" : "max-age=31536000; includeSubDomains",
"content-security-policy" : "default-src 'self'",
"x-content-type-options" : "nosniff",
"x-ms-keyvault-network-info" : "conn_type=Ipv4;addr=187.190.190.225;act_addr_fam=Ipv4;",
"x-ms-keyvault-region" : "northcentralus",
"content-type" : "application/json; charset=utf-8",
"cache-control" : "no-cache",
"x-ms-request-id" : "0703f958-c3d2-11ed-8971-0022488d0014",
"Body" : "{\"id\":\"Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/dda7d908-8b08-41c9-ac1b-cc255694851e\",\"name\":\"dda7d908-8b08-41c9-ac1b-cc255694851e\",\"properties\":{\"assignableScopes\":[\"/\"],\"description\":\"\",\"permissions\":[],\"roleName\":\"dda7d908-8b08-41c9-ac1b-cc255694851e\",\"type\":\"CustomRole\"},\"type\":\"Microsoft.Authorization/roleDefinitions\"}"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.managedhsm.azure.net///providers/Microsoft.Authorization/roleAssignments/e2e57ce5-fd1b-43d9-987a-1c431b1437fd?api-version=7.4",
"Headers" : {
"User-Agent" : "azsdk-java-client_name/client_version (18.0.2; Windows 11; 10.0)",
"Content-Type" : "application/json"
},
"Response" : {
"content-length" : "398",
"x-frame-options" : "SAMEORIGIN",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-server-latency" : "39",
"strict-transport-security" : "max-age=31536000; includeSubDomains",
"content-security-policy" : "default-src 'self'",
"x-content-type-options" : "nosniff",
"x-ms-keyvault-network-info" : "conn_type=Ipv4;addr=187.190.190.225;act_addr_fam=Ipv4;",
"x-ms-keyvault-region" : "northcentralus",
"content-type" : "application/json; charset=utf-8",
"cache-control" : "no-cache",
"x-ms-request-id" : "0a10f4ac-c3d2-11ed-8971-0022488d0014",
"Body" : "{\"id\":\"/providers/Microsoft.Authorization/roleAssignments/e2e57ce5-fd1b-43d9-987a-1c431b1437fd\",\"name\":\"e2e57ce5-fd1b-43d9-987a-1c431b1437fd\",\"properties\":{\"principalId\":\"aed295e0-2ae7-4c2a-9abc-813f0ca233d3\",\"roleDefinitionId\":\"Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/dda7d908-8b08-41c9-ac1b-cc255694851e\",\"scope\":\"/\"},\"type\":\"Microsoft.Authorization/roleAssignments\"}"
},
"Exception" : null
} ],
"variables" : [ "dda7d908-8b08-41c9-ac1b-cc255694851e", "e2e57ce5-fd1b-43d9-987a-1c431b1437fd" ]
{
"RequestUri": "https://REDACTED///providers/Microsoft.Authorization/roleAssignments/a72c9f2d-bfbc-421f-b70e-336f00469d8d?api-version=7.4",
"RequestMethod": "PUT",
"RequestHeaders": {
"Accept": "application/json",
"Authorization": "Sanitized",
"Content-Length": "196",
"Content-Type": "application/json",
"User-Agent": "azsdk-java-client_name/client_version (11.0.6; Windows 10; 10.0)"
},
"RequestBody": {
"properties": {
"roleDefinitionId": "Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/cd952fa0-caac-488e-a5af-d57b6af2886d",
"principalId": "aed295e0-2ae7-4c2a-9abc-813f0ca233d3"
}
},
"StatusCode": 201,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "398",
"Content-Security-Policy": "default-src \u0027self\u0027",
"Content-Type": "application/json; charset=utf-8",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "SAMEORIGIN",
"x-ms-keyvault-network-info": "conn_type=Ipv4;addr=172.92.148.195;act_addr_fam=Ipv4;",
"x-ms-keyvault-region": "northcentralus",
"x-ms-request-id": "cd2a3f8a-d29f-11ed-b07e-000d3a610397",
"x-ms-server-latency": "73"
},
"ResponseBody": {
"id": "/providers/Microsoft.Authorization/roleAssignments/a72c9f2d-bfbc-421f-b70e-336f00469d8d",
"name": "a72c9f2d-bfbc-421f-b70e-336f00469d8d",
"properties": {
"principalId": "aed295e0-2ae7-4c2a-9abc-813f0ca233d3",
"roleDefinitionId": "Microsoft.KeyVault/providers/Microsoft.Authorization/roleDefinitions/cd952fa0-caac-488e-a5af-d57b6af2886d",
"scope": "/"
},
"type": "Microsoft.Authorization/roleAssignments"
}
}
],
"Variables": {
"0": "cd952fa0-caac-488e-a5af-d57b6af2886d",
"1": "a72c9f2d-bfbc-421f-b70e-336f00469d8d"
}
}
Loading