Skip to content

Commit

Permalink
Key Vault test proxy migration (#34321)
Browse files Browse the repository at this point in the history
* Updated Key vault tests to use TestProxyTestBase instead of TestBase.

* Re-recorded Key Vault tests.

* Fixed CredScan issues.

* Added custom matchers to avoid body issues during playback.

* Ensured we clear the token cache of tests before running them.

* Re-recorded tests.

* Fixed Checkstyle issue.

* Fixed playback issues.

* Fixed CheckStyle issues.

* Fixed CredScan issues.

* Made JsonWebKey's logger static and fixed some test playback issues.

* Removed the "logger" key from request bodies.

* Made all ClientLogger instances static.

* Added matchers to avoid comparing the body of requests.

* Added custom matcher to avoid comparing authorization headers.

* Updated tests to use MockTokenCredential in playback mode.

* Removed unused imports.

* Removed custom matcher for authorization header.

* Revert "Removed custom matcher for authorization header."

This reverts commit e82f3d0.
  • Loading branch information
vcolin7 authored Apr 20, 2023
1 parent 09844b9 commit 12c1488
Show file tree
Hide file tree
Showing 336 changed files with 63,743 additions and 32,366 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public final class KeyVaultAccessControlAsyncClient {
/**
* The logger to be used.
*/
private final ClientLogger logger = new ClientLogger(KeyVaultAccessControlAsyncClient.class);
private static final ClientLogger LOGGER = new ClientLogger(KeyVaultAccessControlAsyncClient.class);

/**
* The underlying AutoRest client used to interact with the Key Vault service.
Expand Down Expand Up @@ -196,14 +196,14 @@ Mono<PagedResponse<KeyVaultRoleDefinition>> listRoleDefinitionsFirstPage(String
return clientImpl.getRoleDefinitions()
.listSinglePageAsync(vaultUrl, roleScope.toString(), null,
context)
.doOnRequest(ignored -> logger.verbose("Listing role definitions for roleScope - {}", roleScope))
.doOnSuccess(response -> logger.verbose("Listed role definitions for roleScope - {}", roleScope))
.doOnError(error -> logger.warning("Failed to list role definitions for roleScope - {}", roleScope,
.doOnRequest(ignored -> LOGGER.verbose("Listing role definitions for roleScope - {}", roleScope))
.doOnSuccess(response -> LOGGER.verbose("Listed role definitions for roleScope - {}", roleScope))
.doOnError(error -> LOGGER.warning("Failed to list role definitions for roleScope - {}", roleScope,
error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultAdministrationUtil::transformRoleDefinitionsPagedResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}

Expand All @@ -226,15 +226,15 @@ Mono<PagedResponse<KeyVaultRoleDefinition>> listRoleDefinitionsNextPage(String c
return clientImpl.getRoleDefinitions()
.listNextSinglePageAsync(continuationToken, vaultUrl, context)
.doOnRequest(ignored ->
logger.verbose("Listing next role definitions page - Page {}", continuationToken))
LOGGER.verbose("Listing next role definitions page - Page {}", continuationToken))
.doOnSuccess(response ->
logger.verbose("Listed next role definitions page - Page {}", continuationToken))
LOGGER.verbose("Listed next role definitions page - Page {}", continuationToken))
.doOnError(error ->
logger.warning("Failed to list next role definitions page - Page {}", continuationToken, error))
LOGGER.warning("Failed to list next role definitions page - Page {}", continuationToken, error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultAdministrationUtil::transformRoleDefinitionsPagedResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}

Expand Down Expand Up @@ -380,14 +380,14 @@ Mono<Response<KeyVaultRoleDefinition>> setRoleDefinitionWithResponse(SetRoleDefi
options.getRoleDefinitionName(), parameters,
context)
.doOnRequest(ignored ->
logger.verbose("Creating role definition - {}", options.getRoleDefinitionName()))
.doOnSuccess(response -> logger.verbose("Created role definition - {}", response.getValue().getName()))
LOGGER.verbose("Creating role definition - {}", options.getRoleDefinitionName()))
.doOnSuccess(response -> LOGGER.verbose("Created role definition - {}", response.getValue().getName()))
.doOnError(error ->
logger.warning("Failed to create role definition - {}", options.getRoleDefinitionName(), error))
LOGGER.warning("Failed to create role definition - {}", options.getRoleDefinitionName(), error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultAdministrationUtil::transformRoleDefinitionResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}

Expand Down Expand Up @@ -481,15 +481,15 @@ Mono<Response<KeyVaultRoleDefinition>> getRoleDefinitionWithResponse(KeyVaultRol
return clientImpl.getRoleDefinitions()
.getWithResponseAsync(vaultUrl, roleScope.toString(), roleDefinitionName,
context)
.doOnRequest(ignored -> logger.verbose("Retrieving role definition - {}", roleDefinitionName))
.doOnRequest(ignored -> LOGGER.verbose("Retrieving role definition - {}", roleDefinitionName))
.doOnSuccess(response ->
logger.verbose("Retrieved role definition - {}", response.getValue().getName()))
LOGGER.verbose("Retrieved role definition - {}", response.getValue().getName()))
.doOnError(error ->
logger.warning("Failed to retrieved role definition - {}", roleDefinitionName, error))
LOGGER.warning("Failed to retrieved role definition - {}", roleDefinitionName, error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultAdministrationUtil::transformRoleDefinitionResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}

Expand Down Expand Up @@ -576,15 +576,15 @@ Mono<Response<Void>> deleteRoleDefinitionWithResponse(KeyVaultRoleScope roleScop
return clientImpl.getRoleDefinitions()
.deleteWithResponseAsync(vaultUrl, roleScope.toString(), roleDefinitionName,
context)
.doOnRequest(ignored -> logger.verbose("Deleting role definition - {}", roleDefinitionName))
.doOnSuccess(response -> logger.verbose("Deleted role definition - {}", response.getValue().getName()))
.doOnError(error -> logger.warning("Failed to delete role definition - {}", roleDefinitionName, error))
.doOnRequest(ignored -> LOGGER.verbose("Deleting role definition - {}", roleDefinitionName))
.doOnSuccess(response -> LOGGER.verbose("Deleted role definition - {}", response.getValue().getName()))
.doOnError(error -> LOGGER.warning("Failed to delete role definition - {}", roleDefinitionName, error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(response -> (Response<Void>) new SimpleResponse<Void>(response, null))
.onErrorResume(KeyVaultAdministrationException.class, e ->
swallowExceptionForStatusCodeAsync(404, e, logger));
swallowExceptionForStatusCodeAsync(404, e, LOGGER));
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}

Expand Down Expand Up @@ -651,14 +651,14 @@ Mono<PagedResponse<KeyVaultRoleAssignment>> listRoleAssignmentsFirstPage(String
return clientImpl.getRoleAssignments()
.listForScopeSinglePageAsync(vaultUrl, roleScope.toString(), null,
context)
.doOnRequest(ignored -> logger.verbose("Listing role assignments for roleScope - {}", roleScope))
.doOnSuccess(response -> logger.verbose("Listed role assignments for roleScope - {}", roleScope))
.doOnError(error -> logger.warning("Failed to list role assignments for roleScope - {}", roleScope,
.doOnRequest(ignored -> LOGGER.verbose("Listing role assignments for roleScope - {}", roleScope))
.doOnSuccess(response -> LOGGER.verbose("Listed role assignments for roleScope - {}", roleScope))
.doOnError(error -> LOGGER.warning("Failed to list role assignments for roleScope - {}", roleScope,
error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultAdministrationUtil::transformRoleAssignmentsPagedResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}

Expand All @@ -681,15 +681,15 @@ Mono<PagedResponse<KeyVaultRoleAssignment>> listRoleAssignmentsNextPage(String c
.listForScopeNextSinglePageAsync(continuationToken, vaultUrl,
context)
.doOnRequest(ignored ->
logger.verbose("Listing next role assignments page - Page {}", continuationToken))
LOGGER.verbose("Listing next role assignments page - Page {}", continuationToken))
.doOnSuccess(response ->
logger.verbose("Listed next role assignments page - Page {}", continuationToken))
.doOnError(error -> logger.warning("Failed to list next role assignments page - Page {}",
LOGGER.verbose("Listed next role assignments page - Page {}", continuationToken))
.doOnError(error -> LOGGER.warning("Failed to list next role assignments page - Page {}",
continuationToken, error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultAdministrationUtil::transformRoleAssignmentsPagedResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}

Expand Down Expand Up @@ -845,13 +845,13 @@ Mono<Response<KeyVaultRoleAssignment>> createRoleAssignmentWithResponse(KeyVault
return clientImpl.getRoleAssignments()
.createWithResponseAsync(vaultUrl, roleScope.toString(), roleAssignmentName, parameters,
context)
.doOnRequest(ignored -> logger.verbose("Creating role assignment - {}", roleAssignmentName))
.doOnSuccess(response -> logger.verbose("Created role assignment - {}", response.getValue().getName()))
.doOnError(error -> logger.warning("Failed to create role assignment - {}", roleAssignmentName, error))
.doOnRequest(ignored -> LOGGER.verbose("Creating role assignment - {}", roleAssignmentName))
.doOnSuccess(response -> LOGGER.verbose("Created role assignment - {}", response.getValue().getName()))
.doOnError(error -> LOGGER.warning("Failed to create role assignment - {}", roleAssignmentName, error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultAdministrationUtil::transformRoleAssignmentResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}

Expand Down Expand Up @@ -942,15 +942,15 @@ Mono<Response<KeyVaultRoleAssignment>> getRoleAssignmentWithResponse(KeyVaultRol
return clientImpl.getRoleAssignments()
.getWithResponseAsync(vaultUrl, roleScope.toString(), roleAssignmentName,
context)
.doOnRequest(ignored -> logger.verbose("Retrieving role assignment - {}", roleAssignmentName))
.doOnRequest(ignored -> LOGGER.verbose("Retrieving role assignment - {}", roleAssignmentName))
.doOnSuccess(response ->
logger.verbose("Retrieved role assignment - {}", response.getValue().getName()))
LOGGER.verbose("Retrieved role assignment - {}", response.getValue().getName()))
.doOnError(error ->
logger.warning("Failed to retrieve role assignment - {}", roleAssignmentName, error))
LOGGER.warning("Failed to retrieve role assignment - {}", roleAssignmentName, error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(KeyVaultAdministrationUtil::transformRoleAssignmentResponse);
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}

Expand Down Expand Up @@ -1036,15 +1036,15 @@ Mono<Response<Void>> deleteRoleAssignmentWithResponse(KeyVaultRoleScope roleScop
return clientImpl.getRoleAssignments()
.deleteWithResponseAsync(vaultUrl, roleScope.toString(), roleAssignmentName,
context)
.doOnRequest(ignored -> logger.verbose("Deleting role assignment - {}", roleAssignmentName))
.doOnSuccess(response -> logger.verbose("Deleted role assignment - {}", response.getValue().getName()))
.doOnError(error -> logger.warning("Failed to delete role assignment - {}", roleAssignmentName, error))
.doOnRequest(ignored -> LOGGER.verbose("Deleting role assignment - {}", roleAssignmentName))
.doOnSuccess(response -> LOGGER.verbose("Deleted role assignment - {}", response.getValue().getName()))
.doOnError(error -> LOGGER.warning("Failed to delete role assignment - {}", roleAssignmentName, error))
.onErrorMap(KeyVaultAdministrationUtils::mapThrowableToKeyVaultAdministrationException)
.map(response -> (Response<Void>) new SimpleResponse<Void>(response, null))
.onErrorResume(KeyVaultAdministrationException.class, e ->
swallowExceptionForStatusCodeAsync(404, e, logger));
swallowExceptionForStatusCodeAsync(404, e, LOGGER));
} catch (RuntimeException e) {
return monoError(logger, e);
return monoError(LOGGER, e);
}
}
}
Loading

0 comments on commit 12c1488

Please sign in to comment.