Skip to content

Commit a1b08f2

Browse files
committed
Merge pull request #251 from huangpf/dev
Dev
2 parents 04763e4 + cb434db commit a1b08f2

File tree

7 files changed

+55
-33
lines changed

7 files changed

+55
-33
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/Common.ps1

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,7 @@ function Get-KeyVault([bool] $haspermission=$true)
2626
if ($global:testVault -ne "" -and $haspermission)
2727
{
2828
return $global:testVault
29-
}
30-
elseif ($global:testEnv -eq 'BVT' -and $haspermission)
31-
{
32-
return 'powershellbvt'
33-
}
34-
elseif ($global:testEnv -eq 'BVT')
35-
{
36-
return 'azkmstestbvteu2'
37-
}
29+
}
3830
elseif ($haspermission)
3931
{
4032
return 'azkmspsprodeus'

src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/RunUITests.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
Param(
22
[Parameter(Mandatory=$True,Position=0)]
3-
[ValidateSet('BVT','PROD')]
4-
[string]$testenv,
5-
[Parameter(Mandatory=$True,Position=1)]
63
[string]$testns
74
)
85

@@ -17,7 +14,6 @@ $global:passedCount = 0;
1714
$global:passedTests = @()
1815
$global:failedTests = @()
1916
$global:times = @{}
20-
$global:testEnv = $testenv.ToUpperInvariant()
2117
$global:testns = $testns+"UI"
2218

2319
function Run-TestProtected

src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/VaultUITests.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Tests remove a key with two confirmations
99
#>
1010
function Test_RemoveKeyWithTwoConfirmations
1111
{
12-
Write-Host "Type 'Yes' twice"
12+
Write-Host -ForegroundColor Yellow "Type 'Yes' twice"
1313
$keyVault = Get-KeyVault
1414
$keyname=Get-KeyName 'remove'
1515
$key=Add-AzureKeyVaultKey -VaultName $keyVault -Name $keyname -Destination 'Software'
@@ -30,7 +30,7 @@ Tests remove a key with one confirmation
3030
#>
3131
function Test_RemoveKeyWithOneConfirmations
3232
{
33-
Write-Host "Type 'Yes' once"
33+
Write-Host -ForegroundColor Yellow "Type 'Yes' once"
3434
$keyVault = Get-KeyVault
3535
$keyname=Get-KeyName 'remove'
3636
$key=Add-AzureKeyVaultKey -VaultName $keyVault -Name $keyname -Destination 'Software'
@@ -51,7 +51,7 @@ Tests cancel removing a key with once
5151
#>
5252
function Test_CancelKeyRemovalOnce
5353
{
54-
Write-Host "Type 'No' once"
54+
Write-Host -ForegroundColor Yellow "Type 'No' once"
5555
$keyVault = Get-KeyVault
5656
$keyname=Get-KeyName 'remove'
5757
$key=Add-AzureKeyVaultKey -VaultName $keyVault -Name $keyname -Destination 'Software'
@@ -73,7 +73,7 @@ Tests cancel removing a key with two prompts
7373
#>
7474
function Test_ConfirmThenCancelKeyRemoval
7575
{
76-
Write-Host "Type 'Yes' first. Then type 'No'"
76+
Write-Host -ForegroundColor Yellow "Type 'Yes' first. Then type 'No'"
7777
$keyVault = Get-KeyVault
7878
$keyname=Get-KeyName 'remove'
7979
$key=Add-AzureKeyVaultKey -VaultName $keyVault -Name $keyname -Destination 'Software'
@@ -97,7 +97,7 @@ Tests remove a secret with two confirmations
9797
#>
9898
function Test_RemoveSecretWithTwoConfirmations
9999
{
100-
Write-Host "Type 'Yes' twice"
100+
Write-Host -ForegroundColor Yellow "Type 'Yes' twice"
101101
$keyVault = Get-KeyVault
102102
$secretname= Get-SecretName 'remove'
103103
$sec=Set-AzureKeyVaultSecret -VaultName $keyVault -Name $secretname -SecretValue $securedata
@@ -118,7 +118,7 @@ Tests remove a secret with one confirmations
118118
#>
119119
function Test_RemoveSecretWithOneConfirmations
120120
{
121-
Write-Host "Type 'Yes' once"
121+
Write-Host -ForegroundColor Yellow "Type 'Yes' once"
122122
$keyVault = Get-KeyVault
123123
$secretname= Get-SecretName 'remove'
124124
$sec=Set-AzureKeyVaultSecret -VaultName $keyVault -Name $secretname -SecretValue $securedata
@@ -139,7 +139,7 @@ Tests cancel removing a secret with once
139139
#>
140140
function Test_CancelSecretRemovalOnce
141141
{
142-
Write-Host "Type 'No' once"
142+
Write-Host -ForegroundColor Yellow "Type 'No' once"
143143
$keyVault = Get-KeyVault
144144
$secretname= Get-SecretName 'remove'
145145
$sec=Set-AzureKeyVaultSecret -VaultName $keyVault -Name $secretname -SecretValue $securedata
@@ -161,7 +161,7 @@ Tests cancel removing a secret with two prompts
161161
#>
162162
function Test_ConfirmThenCancelSecretRemoval
163163
{
164-
Write-Host "Type 'Yes' first. Then type 'No'"
164+
Write-Host -ForegroundColor Yellow "Type 'Yes' first. Then type 'No'"
165165
$keyVault = Get-KeyVault
166166
$secretname= Get-SecretName 'remove'
167167
$sec=Set-AzureKeyVaultSecret -VaultName $keyVault -Name $secretname -SecretValue $securedata

src/ResourceManager/KeyVault/Commands.KeyVault.Test/Scripts/readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ This folder contains ps1 scripts testing Azure Key Vault cmdlets.
22
Test environments and accounts:
33
1. Copy this folder on a server 2012 R2 and windows 8.1 machine with Azure Powershell msi installed.
44
2. Setup Azure account. Please refer to "Key Vault Powershell Sign-off criteria" in spec store for user account setup.
5-
Both OrgId user and Live user need to be tested.
5+
Run tests for three types of account:
6+
- Service principal (DataPlane tests)
7+
- OrgId
8+
- LiveId
69
Run testing scripts:
710
1. Run scripting tests using RunKeyVaultTests.ps1.
811
2. Run tests required user inputs using RunUITests.ps1.

src/ResourceManager/KeyVault/Commands.KeyVault/Models/DataServiceCredential.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,24 @@ public Task<string> OnAuthentication(string authority, string resource, string s
5555

5656
private Tuple<IAccessToken, string> GetToken(IAuthenticationFactory authFactory, AzureContext context)
5757
{
58-
if (context.Subscription == null)
59-
throw new ArgumentException(KeyVaultProperties.Resources.InvalidCurrentSubscription);
6058
if (context.Account == null)
61-
throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState);
62-
if (context.Account.Type != AzureAccount.AccountType.User)
59+
throw new ArgumentException(KeyVaultProperties.Resources.ArmAccountNotFound);
60+
61+
if (context.Account.Type != AzureAccount.AccountType.User &&
62+
context.Account.Type != AzureAccount.AccountType.ServicePrincipal )
6363
throw new ArgumentException(string.Format(KeyVaultProperties.Resources.UnsupportedAccountType, context.Account.Type));
64-
var tenant = context.Subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants)
65-
.Intersect(context.Account.GetPropertyAsArray(AzureAccount.Property.Tenants))
66-
.FirstOrDefault();
67-
if (tenant == null)
68-
throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState);
64+
65+
string tenant = null;
66+
if (context.Subscription != null && context.Account != null)
67+
tenant = context.Subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants)
68+
.Intersect(context.Account.GetPropertyAsArray(AzureAccount.Property.Tenants))
69+
.FirstOrDefault();
70+
71+
if (tenant == null && context.Tenant != null && context.Tenant.Id != Guid.Empty)
72+
tenant = context.Tenant.Id.ToString();
73+
74+
if (string.IsNullOrWhiteSpace(tenant))
75+
throw new ArgumentException(KeyVaultProperties.Resources.NoTenantInContext);
6976

7077
try
7178
{

src/ResourceManager/KeyVault/Commands.KeyVault/Properties/Resources.Designer.cs

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/KeyVault/Commands.KeyVault/Properties/Resources.resx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
<data name="ADObjectNotFound" xml:space="preserve">
121121
<value>Cannot find the Active Directory object '{0}' in tenant '{1}'. Please make sure that the user or application service principal you are authorizing is registered in the current subscription's Azure Active directory. The TenantID displayed by the cmdlet 'Get-AzureRmContext' is the current subscription's Azure Active directory.</value>
122122
</data>
123+
<data name="ArmAccountNotFound" xml:space="preserve">
124+
<value>No account found in the context. Please login using Login-AzureRMAccount.</value>
125+
</data>
123126
<data name="BackupKeyFileAlreadyExists" xml:space="preserve">
124127
<value>The backup key file '{0}' already exists.</value>
125128
</data>
@@ -178,7 +181,7 @@
178181
<value>No subscription is currently selected. Use Set-AzureRmContext to activate a subscription.</value>
179182
</data>
180183
<data name="InvalidSubscriptionState" xml:space="preserve">
181-
<value>Your Azure credentials have not been set up or have expired, please run Add-AzureRmAccount to set up your Azure credentials.</value>
184+
<value>Your Azure credentials have not been set up or have expired, please run Login-AzureRmAccount to set up your Azure credentials.</value>
182185
</data>
183186
<data name="InvalidTagFormat" xml:space="preserve">
184187
<value>Invalid tag format. Expect @{Name = "tagName"} or @{Name = "tagName"; Value = "tagValue"}</value>
@@ -195,6 +198,9 @@
195198
<data name="NoDefaultUserAccount" xml:space="preserve">
196199
<value>There is no default user account associated with this subscription. Certificate accounts are not supported with Azure Key Vault.</value>
197200
</data>
201+
<data name="NoTenantInContext" xml:space="preserve">
202+
<value>No tenant found in the context. Please ensure that the credentials you provided are authorized to access an Azure subscription, then run Login-AzureRMAccount to login.</value>
203+
</data>
198204
<data name="PermissionSetIncludesAllPlusOthers" xml:space="preserve">
199205
<value>Invalid permissions to {0}. The list contains "all" along with other permissions. Please remove "all" from the list or include only "all" in the list.</value>
200206
</data>

0 commit comments

Comments
 (0)