-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Key Vault] Add Secret URI Parameter to Key Vault Secret Cmdlets (#26222
) * Added secretUri support for all the 'secret' cmdlets * Updated Changelog * Added ResourceId aliases for backwards compatibility * Added Tests, Secret Data Class * Updated Help Docs * Use Typed varaibles * Add example usages in help docs * Error Suppression * Change Data Class Accessibility * Move Split Logic to Constructor * Added uri format to help docs
- Loading branch information
Showing
19 changed files
with
933 additions
and
213 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/KeyVault/KeyVault.Test/PesterTests/KeyVaultSecretUri.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
BeforeAll { | ||
. "$PSScriptRoot\..\Scripts\Common.ps1" # Common setup script | ||
|
||
# Load the Az.KeyVault module from the debug artifacts | ||
$psd1Path = Join-Path $PSScriptRoot "../../../../artifacts/Debug/" -Resolve | ||
$keyVaultPsd1 = Join-Path $psd1Path "./Az.KeyVault/Az.KeyVault.psd1" -Resolve | ||
Import-Module $keyVaultPsd1 -Force | ||
|
||
# Define key variables | ||
$resourceGroupName = "yash-rg$(Get-Random)" # Use existing resource group | ||
$location = "eastus" | ||
$vaultName = "yashkv$(Get-Random)" # Generate unique Key Vault name | ||
$secretName = "TestSecret" | ||
$secretValue = ConvertTo-SecureString "InitialSecretValue" -AsPlainText -Force | ||
|
||
# Set up resource group | ||
New-AzResourceGroup -Name $resourceGroupName -Location $location | ||
|
||
# Create a Key Vault in the existing resource group | ||
New-AzKeyVault -ResourceGroupName $resourceGroupName -VaultName $vaultName -Location $location | ||
|
||
# Create a new secret in the Key Vault | ||
Set-AzKeyVaultSecret -VaultName $vaultName -Name $secretName -SecretValue $secretValue | ||
} | ||
|
||
|
||
Describe 'Azure KeyVault Secret URI Live Tests' { | ||
|
||
It 'should retrieve the secret using the Secret URI with Get-AzKeyVaultSecret' { | ||
# Construct the secret URI | ||
$secretUri = "https://$vaultName.vault.azure.net/secrets/$secretName" | ||
|
||
# Retrieve the secret using its URI | ||
$retrievedSecret = Get-AzKeyVaultSecret -Id $secretUri -AsPlainText | ||
|
||
# Validate that the secret is retrieved successfully | ||
$retrievedSecret | Should -Be "InitialSecretValue" | ||
} | ||
|
||
It 'should update the secret value using Set-AzKeyVaultSecret' { | ||
# Update the secret value | ||
$newSecretValue = ConvertTo-SecureString "UpdatedSecretValue" -AsPlainText -Force | ||
Set-AzKeyVaultSecret -VaultName $vaultName -Name $secretName -SecretValue $newSecretValue | ||
|
||
# Retrieve the updated secret | ||
$retrievedSecret = Get-AzKeyVaultSecret -VaultName $vaultName -Name $secretName -AsPlainText | ||
|
||
# Validate the secret has been updated | ||
$retrievedSecret | Should -Be "UpdatedSecretValue" | ||
} | ||
|
||
It 'should remove the secret using Remove-AzKeyVaultSecret' { | ||
# Remove the secret | ||
Remove-AzKeyVaultSecret -VaultName $vaultName -Name $secretName -Force | ||
|
||
# Ensure the secret is deleted | ||
Get-AzKeyVaultSecret -VaultName $vaultName -Name $secretName | Should -BeNullOrEmpty | ||
} | ||
} | ||
|
||
AfterAll { | ||
# Clean up Key Vault & Resource Group) | ||
Remove-AzKeyVault -VaultName $vaultName -ResourceGroupName $resourceGroupName -Force | ||
Remove-AzResourceGroup -Name $resourceGroupName -Force | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.