Skip to content

Commit

Permalink
feat: Upgrade Az.* dependent modules (#439)
Browse files Browse the repository at this point in the history
* update az packages

* add Az.Storage to required modules

* unit tests on windows

* revert unit test image change

* remove unnecessary code from beforeach

* fix storage fileshare test

* fixed api management unit tests
  • Loading branch information
pim-simons authored Nov 29, 2024
1 parent de395da commit 9a81242
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 60 deletions.
Binary file not shown.
Binary file modified src/Arcus.Scripting.AppService/Arcus.Scripting.AppService.psd1
Binary file not shown.
Binary file modified src/Arcus.Scripting.DataFactory/Arcus.Scripting.DataFactory.psd1
Binary file not shown.
Binary file modified src/Arcus.Scripting.KeyVault/Arcus.Scripting.KeyVault.psd1
Binary file not shown.
Binary file modified src/Arcus.Scripting.LogicApps/Arcus.Scripting.LogicApps.psd1
Binary file not shown.
Binary file modified src/Arcus.Scripting.Security/Arcus.Scripting.Security.psd1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
Import-Module Az.Storage
Import-Module -Name $PSScriptRoot\..\Arcus.Scripting.ApiManagement -ErrorAction Stop
Import-Module -Name $PSScriptRoot\..\Arcus.Scripting.ApiManagement -ErrorAction Stop

InModuleScope Arcus.Scripting.ApiManagement {
Describe "Arcus Azure API Management unit tests" {
Context "Back up Azure API Management instance" {
BeforeEach {
# Test values, not really pointing to anything
$testSasToken = "?st=2013-09-03T04%3A12%3A15Z&se=2013-09-03T05%3A12%3A15Z&sr=c&sp=r&sig=fN2NPxLK99tR2%2BWnk48L3lMjutEj7nOwBo7MXs2hEV8%3D"
$testEndpoint = "http://storageaccountname.blob.core.windows.net"
$testConnection = [System.String]::Format("BlobEndpoint={0};QueueEndpoint={0};TableEndpoint={0};SharedAccessSignature={1}", $testEndpoint, $testSasToken)
$storageAccount = [Microsoft.Azure.Storage.CloudStorageAccount]::Parse($testConnection)
$expectedStorageContext = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext -ArgumentList $storageAccount
$expectedStorageAccountName = "shopping-storage"
$storageKeyValue = "mystoragekey"
$expectedStorageContext = New-AzStorageContext -StorageAccountName $expectedStorageAccountName -StorageAccountKey $storageKeyValue
}
It "Creates storage context during API management backup" {
# Arrange
$resourceGroup = "shopping"
$storageAccountResourceGroup = "stock"
$expectedStorageAccountName = "shopping-storage"
$storageAccountResourceGroup = "stock"
$serviceName = "shopping-API-management"
$targetContainerName = "backup-storage"
$storageKeyValue = "my-storage-key"
$targetContainerName = "backup-storage"
$storageKey = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccountKey -ArgumentList @($null, $storageKeyValue, $null)
$accessType = 'SystemAssignedManagedIdentity'

Expand Down Expand Up @@ -54,11 +49,9 @@ InModuleScope Arcus.Scripting.ApiManagement {
# Arrange
$resourceGroup = "shopping"
$storageAccountResourceGroup = "stock"
$expectedStorageAccountName = "shopping-storage"
$serviceName = "shopping-API-management"
$targetContainerName = "backup-storage"
$targetBlobName = "backup-storage-blob"
$storageKeyValue = "my-storage-key"
$storageKey = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccountKey -ArgumentList @($null, $storageKeyValue, $null)
$accessType = 'SystemAssignedManagedIdentity'

Expand Down Expand Up @@ -93,10 +86,8 @@ InModuleScope Arcus.Scripting.ApiManagement {
# Arrange
$resourceGroup = "shopping"
$storageAccountResourceGroup = "stock"
$expectedStorageAccountName = "shopping-storage"
$serviceName = "shopping-API-management"
$targetContainerName = "backup-storage"
$storageKeyValue = "my-storage-key"
$storageKey = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccountKey -ArgumentList @($null, $storageKeyValue, $null)
$accessType = 'SystemAssignedManagedIdentity'

Expand Down Expand Up @@ -131,10 +122,8 @@ InModuleScope Arcus.Scripting.ApiManagement {
# Arrange
$resourceGroup = "shopping"
$storageAccountResourceGroup = "stock"
$expectedStorageAccountName = "shopping-storage"
$serviceName = "shopping-API-management"
$targetContainerName = "backup-storage"
$storageKeyValue = "my-storage-key"
$storageKey = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccountKey -ArgumentList @($null, $storageKeyValue, $null)
$defaultProfile = New-Object -TypeName Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile
$accessType = 'SystemAssignedManagedIdentity'
Expand Down Expand Up @@ -170,10 +159,8 @@ InModuleScope Arcus.Scripting.ApiManagement {
# Arrange
$resourceGroup = "shopping"
$storageAccountResourceGroup = "stock"
$expectedStorageAccountName = "shopping-storage"
$serviceName = "shopping-API-management"
$targetContainerName = "backup-storage"
$storageKeyValue = "my-storage-key"
$storageKey = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccountKey -ArgumentList @($null, $storageKeyValue, $null)
$accessType = 'UserAssignedManagedIdentity'
$identityClientId = 'someidentityid'
Expand Down Expand Up @@ -788,24 +775,21 @@ InModuleScope Arcus.Scripting.ApiManagement {
}
}
Context "Restore Azure API Management instance" {
BeforeEach {
# Test values, not really pointing to anything
$expectedStorageAccountName = "shopping-storage"
$storageKeyValue = "mystoragekey"
$expectedStorageContext = New-AzStorageContext -StorageAccountName $expectedStorageAccountName -StorageAccountKey $storageKeyValue
}
It "Restores API management service w/o pass thru and profile" {
# Arrange
$resourceGroup = "shopping"
$storageAccountResourceGroup = "stock"
$expectedStorageAccountName = "shopping-storage"
$serviceName = "shopping-API-management"
$containerName = "backup-storage"
$blobName = "backup-storage-blob"
$storageKeyValue = "my-storage-key"
$storageKey = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccountKey -ArgumentList @($null, $storageKeyValue, $null)

# Test values, not really pointing to anything
$testSasToken = "?st=2013-09-03T04%3A12%3A15Z&se=2013-09-03T05%3A12%3A15Z&sr=c&sp=r&sig=fN2NPxLK99tR2%2BWnk48L3lMjutEj7nOwBo7MXs2hEV8%3D"
$testEndpoint = "http://storageaccountname.blob.core.windows.net"
$testConnection = [System.String]::Format("BlobEndpoint={0};QueueEndpoint={0};TableEndpoint={0};SharedAccessSignature={1}", $testEndpoint, $testSasToken)
$storageAccount = [Microsoft.Azure.Storage.CloudStorageAccount]::Parse($testConnection)
$expectedStorageContext = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext -ArgumentList $storageAccount

Mock Get-AzStorageAccountKey {
$ResourceGroupName | Should -Be $storageAccountResourceGroup
$StorageAccountName | Should -Be $expectedStorageAccountName
Expand Down Expand Up @@ -836,20 +820,11 @@ InModuleScope Arcus.Scripting.ApiManagement {
# Arrange
$resourceGroup = "shopping"
$storageAccountResourceGroup = "stock"
$expectedStorageAccountName = "shopping-storage"
$serviceName = "shopping-API-management"
$containerName = "backup-storage"
$blobName = "backup-storage-blob"
$storageKeyValue = "my-storage-key"
$storageKey = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccountKey -ArgumentList @($null, $storageKeyValue, $null)

# Test values, not really pointing to anything
$testSasToken = "?st=2013-09-03T04%3A12%3A15Z&se=2013-09-03T05%3A12%3A15Z&sr=c&sp=r&sig=fN2NPxLK99tR2%2BWnk48L3lMjutEj7nOwBo7MXs2hEV8%3D"
$testEndpoint = "http://storageaccountname.blob.core.windows.net"
$testConnection = [System.String]::Format("BlobEndpoint={0};QueueEndpoint={0};TableEndpoint={0};SharedAccessSignature={1}", $testEndpoint, $testSasToken)
$storageAccount = [Microsoft.Azure.Storage.CloudStorageAccount]::Parse($testConnection)
$expectedStorageContext = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext -ArgumentList $storageAccount

Mock Get-AzStorageAccountKey {
$ResourceGroupName | Should -Be $storageAccountResourceGroup
$StorageAccountName | Should -Be $expectedStorageAccountName
Expand Down Expand Up @@ -880,21 +855,12 @@ InModuleScope Arcus.Scripting.ApiManagement {
# Arrange
$resourceGroup = "shopping"
$storageAccountResourceGroup = "stock"
$expectedStorageAccountName = "shopping-storage"
$serviceName = "shopping-API-management"
$containerName = "backup-storage"
$blobName = "backup-storage-blob"
$storageKeyValue = "my-storage-key"
$storageKey = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccountKey -ArgumentList @($null, $storageKeyValue, $null)
$defaultProfile = New-Object -TypeName Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile

# Test values, not really pointing to anything
$testSasToken = "?st=2013-09-03T04%3A12%3A15Z&se=2013-09-03T05%3A12%3A15Z&sr=c&sp=r&sig=fN2NPxLK99tR2%2BWnk48L3lMjutEj7nOwBo7MXs2hEV8%3D"
$testEndpoint = "http://storageaccountname.blob.core.windows.net"
$testConnection = [System.String]::Format("BlobEndpoint={0};QueueEndpoint={0};TableEndpoint={0};SharedAccessSignature={1}", $testEndpoint, $testSasToken)
$storageAccount = [Microsoft.Azure.Storage.CloudStorageAccount]::Parse($testConnection)
$expectedStorageContext = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext -ArgumentList $storageAccount

Mock Get-AzStorageAccountKey {
$ResourceGroupName | Should -Be $storageAccountResourceGroup
$StorageAccountName | Should -Be $expectedStorageAccountName
Expand Down Expand Up @@ -925,21 +891,12 @@ InModuleScope Arcus.Scripting.ApiManagement {
# Arrange
$resourceGroup = "shopping"
$storageAccountResourceGroup = "stock"
$expectedStorageAccountName = "shopping-storage"
$serviceName = "shopping-API-management"
$containerName = "backup-storage"
$blobName = "backup-storage-blob"
$storageKeyValue = "my-storage-key"
$storageKey = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccountKey -ArgumentList @($null, $storageKeyValue, $null)
$defaultProfile = New-Object -TypeName Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile

# Test values, not really pointing to anything
$testSasToken = "?st=2013-09-03T04%3A12%3A15Z&se=2013-09-03T05%3A12%3A15Z&sr=c&sp=r&sig=fN2NPxLK99tR2%2BWnk48L3lMjutEj7nOwBo7MXs2hEV8%3D"
$testEndpoint = "http://storageaccountname.blob.core.windows.net"
$testConnection = [System.String]::Format("BlobEndpoint={0};QueueEndpoint={0};TableEndpoint={0};SharedAccessSignature={1}", $testEndpoint, $testSasToken)
$storageAccount = [Microsoft.Azure.Storage.CloudStorageAccount]::Parse($testConnection)
$expectedStorageContext = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext -ArgumentList $storageAccount

Mock Get-AzStorageAccountKey {
$ResourceGroupName | Should -Be $storageAccountResourceGroup
$StorageAccountName | Should -Be $expectedStorageAccountName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ InModuleScope Arcus.Scripting.Storage.FileShare {
$testConnection = [System.String]::Format("BlobEndpoint={0};QueueEndpoint={0};TableEndpoint={0};SharedAccessSignature={1}", $testEndpoint, $testSasToken)
$storageAccount = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccount
$psStorageAccount = New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount -ArgumentList $storageAccount

$cloudShare = New-Object -TypeName Microsoft.Azure.Storage.File.CloudFileShare -ArgumentList (New-Object -TypeName System.Uri "https://something")
$fileShare = New-Object -TypeName Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileShare -ArgumentList $cloudShare, $storageContext
}
Context "Creating Azure File Share folder" {
It "Create new folder on Azure File Share succeeds" {
Expand Down Expand Up @@ -55,9 +52,11 @@ InModuleScope Arcus.Scripting.Storage.FileShare {
$fileAddress = "http://test.file.core.windows.net/$fileShareName/$folderName"
Write-Host $fileAddress


$storageUri = New-Object -TypeName System.Uri -ArgumentList $fileAddress
$cloudFileDirectory = New-Object -TypeName Microsoft.Azure.Storage.File.CloudFileDirectory -ArgumentList $storageUri
$fileShareDirectory = New-Object -TypeName Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileDirectory -ArgumentList $cloudFileDirectory, $psStorageAccount.Context
$shareClientOptions = New-Object -TypeName Azure.Storage.Files.Shares.ShareClientOptions('V2023_08_03')
$shareDirectoryClient = New-Object -TypeName Azure.Storage.Files.Shares.ShareDirectoryClient($storageUri, $shareClientOptions)
$fileShareDirectory = New-Object -TypeName Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileDirectory -ArgumentList $shareDirectoryClient, $psStorageAccount.Context
Write-Host "Name: " $fileShareDirectory.Name

Mock Get-AzStorageAccount {
Expand Down

0 comments on commit 9a81242

Please sign in to comment.