diff --git a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/Common.ps1 b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/Common.ps1 index ca1be15d8cec..086aee069fd0 100644 --- a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/Common.ps1 +++ b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/Common.ps1 @@ -86,6 +86,31 @@ function Get-ImportKeyFile([string]$filesuffix, [bool] $exists=$true) } } +<# +.SYNOPSIS +Get 1024 bit key file path to be imported +#> +function Get-ImportKeyFile1024([string]$filesuffix, [bool] $exists=$true) +{ + if ($exists) + { + $file = "$filesuffix"+"test1024.$filesuffix" + } + else + { + $file = "notexist" + ".$filesuffix" + } + + if ($global:testEnv -eq 'BVT') + { + return Join-Path $invocationPath "bvtdata\$file" + } + else + { + return Join-Path $invocationPath "proddata\$file" + } +} + <# .SYNOPSIS Remove log file under a folder diff --git a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/RunKeyVaultTests.ps1 b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/RunKeyVaultTests.ps1 index 2f20bca2ab3e..25730dff43e7 100644 --- a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/RunKeyVaultTests.ps1 +++ b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/RunKeyVaultTests.ps1 @@ -79,10 +79,12 @@ Run-TestProtected { Run-KeyTest {Test_CreateSoftwareKeyWithCustomAttributes} "Te Run-TestProtected { Run-KeyTest {Test_CreateHsmKeyWithDefaultAttributes} "Test_CreateHsmKeyWithDefaultAttributes" } "Test_CreateHsmKeyWithDefaultAttributes" Run-TestProtected { Run-KeyTest {Test_CreateHsmKeyWithCustomAttributes} "Test_CreateHsmKeyWithCustomAttributes" } "Test_CreateHsmKeyWithCustomAttributes" Run-TestProtected { Run-KeyTest {Test_ImportPfxWithDefaultAttributes} "Test_ImportPfxWithDefaultAttributes" } "Test_ImportPfxWithDefaultAttributes" +Run-TestProtected { Run-KeyTest {Test_ImportPfxWith1024BitKey} "Test_ImportPfxWith1024BitKey" } "Test_ImportPfxWith1024BitKey" Run-TestProtected { Run-KeyTest {Test_ImportPfxWithCustomAttributes} "Test_ImportPfxWithCustomAttributes" } "Test_ImportPfxWithCustomAttributes" Run-TestProtected { Run-KeyTest {Test_ImportPfxAsHsmWithDefaultAttributes} "Test_ImportPfxAsHsmWithDefaultAttributes" } "Test_ImportPfxAsHsmWithDefaultAttributes" Run-TestProtected { Run-KeyTest {Test_ImportPfxAsHsmWithCustomAttributes} "Test_ImportPfxAsHsmWithCustomAttributes" } "Test_ImportPfxAsHsmWithCustomAttributes" Run-TestProtected { Run-KeyTest {Test_ImportByokWithDefaultAttributes} "Test_ImportByokWithDefaultAttributes" } "Test_ImportByokWithDefaultAttributes" +Run-TestProtected { Run-KeyTest {Test_ImportByokWith1024BitKey} "Test_ImportByokWith1024BitKey" } "Test_ImportByokWith1024BitKey" Run-TestProtected { Run-KeyTest {Test_ImportByokWithCustomAttributes} "Test_ImportByokWithCustomAttributes" } "Test_ImportByokWithCustomAttributes" Run-TestProtected { Run-KeyTest {Test_AddKeyPositionalParameter} "Test_AddKeyPositionalParameter" } "Test_AddKeyPositionalParameter" Run-TestProtected { Run-KeyTest {Test_AddKeyAliasParameter} "Test_AddKeyAliasParameter" } "Test_AddKeyAliasParameter" diff --git a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/VaultKeyTests.ps1 b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/VaultKeyTests.ps1 index 4aa8781c3690..3cb23d06bb5d 100644 --- a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/VaultKeyTests.ps1 +++ b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/VaultKeyTests.ps1 @@ -10,6 +10,7 @@ $delta=[TimeSpan]::FromMinutes(2) $tags=@{"tag1"="value1"; "tag2"=""; "tag3"=$null} $newtags= @{"tag1"="value1"; "tag2"="value2"; "tag3"="value3"; "tag4"="value4"} $emptytags=@{} +$defaultKeySizeInBytes = 256 @@ -67,6 +68,7 @@ function Test_CreateSoftwareKeyWithDefaultAttributes Assert-NotNull $key $global:createdKeys += $keyname Assert-KeyAttributes $key.Attributes 'RSA' $true $null $null $null $null + Assert-AreEqual $key.Key.N.Length $defaultKeySizeInBytes } <# @@ -95,6 +97,7 @@ function Test_CreateHsmKeyWithDefaultAttributes Assert-NotNull $key $global:createdKeys += $keyname Assert-KeyAttributes $key.Attributes 'RSA-HSM' $true $null $null $null $null + Assert-AreEqual $key.Key.N.Length $defaultKeySizeInBytes } <# @@ -124,6 +127,23 @@ function Test_ImportPfxWithDefaultAttributes Assert-NotNull $key $global:createdKeys += $keyname Assert-KeyAttributes $key.Attributes 'RSA' $true $null $null $null $null + Assert-AreEqual $key.Key.N.Length $defaultKeySizeInBytes + } + + <# +.SYNOPSIS +Tests import pfx with default attributes +#> +function Test_ImportPfxWith1024BitKey +{ + $keyVault = Get-KeyVault + $keyname=Get-KeyName 'pfx1024' + $pfxpath = Get-ImportKeyFile1024 'pfx' + $key=Add-AzureKeyVaultKey -VaultName $keyVault -Name $keyname -KeyFilePath $pfxpath -KeyFilePassword $securepfxpwd + Assert-NotNull $key + $global:createdKeys += $keyname + Assert-KeyAttributes $key.Attributes 'RSA' $true $null $null $null $null + Assert-AreEqual $key.Key.N.Length 128 } <# @@ -184,6 +204,23 @@ function Test_ImportByokWithDefaultAttributes Assert-NotNull $key $global:createdKeys += $keyname Assert-KeyAttributes $key.Attributes 'RSA-HSM' $true $null $null $null $null + Assert-AreEqual $key.Key.N.Length $defaultKeySizeInBytes +} + +<# +.SYNOPSIS +Tests import byok with default attributes +#> +function Test_ImportByokWith1024BitKey +{ + $keyVault = Get-KeyVault + $keyname=Get-KeyName 'byok1024' + $byokpath = Get-ImportKeyFile1024 'byok' + $key=Add-AzureKeyVaultKey -VaultName $keyVault -Name $keyname -KeyFilePath $byokpath + Assert-NotNull $key + $global:createdKeys += $keyname + Assert-KeyAttributes $key.Attributes 'RSA-HSM' $true $null $null $null $null + Assert-AreEqual $key.Key.N.Length 128 } <# diff --git a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/bvtdata/byoktest1024.byok b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/bvtdata/byoktest1024.byok new file mode 100644 index 000000000000..787d803c72a0 Binary files /dev/null and b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/bvtdata/byoktest1024.byok differ diff --git a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/bvtdata/pfxtest1024.pfx b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/bvtdata/pfxtest1024.pfx new file mode 100644 index 000000000000..7271ec978e53 Binary files /dev/null and b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/bvtdata/pfxtest1024.pfx differ diff --git a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/proddata/byoktest1024.byok b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/proddata/byoktest1024.byok new file mode 100644 index 000000000000..7d6e2b769989 Binary files /dev/null and b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/proddata/byoktest1024.byok differ diff --git a/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/proddata/pfxtest1024.pfx b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/proddata/pfxtest1024.pfx new file mode 100644 index 000000000000..7271ec978e53 Binary files /dev/null and b/src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/proddata/pfxtest1024.pfx differ