Skip to content

Commit

Permalink
Merge pull request #48 from Azure/dev
Browse files Browse the repository at this point in the history
Upstream
  • Loading branch information
AzureRT committed Oct 20, 2015
2 parents 4ed2091 + 8d44f81 commit 73ebe3a
Show file tree
Hide file tree
Showing 50 changed files with 15,114 additions and 7,719 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.WindowsAzure.Commands.Common.Storage;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.WindowsAzure.Management.Storage;
using Microsoft.Azure.Commands.Management.Storage;
using Microsoft.Azure.Management.Storage;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Compute
Expand All @@ -37,7 +38,7 @@ public class SetAzureVMDiagnosticsExtensionCommand : VirtualMachineExtensionBase
private const string VirtualMachineExtension = "Microsoft.Compute/virtualMachines/extensions";
private const string IaaSDiagnosticsExtension = "IaaSDiagnostics";
private const string ExtensionPublisher = "Microsoft.Azure.Diagnostics";
private StorageManagementClient storageClient;
private IStorageManagementClient storageClient;

[Parameter(
Mandatory = true,
Expand Down Expand Up @@ -154,14 +155,14 @@ public string PrivateConfiguration
}
}

public StorageManagementClient StorageClient
public IStorageManagementClient StorageClient
{
get
{
if (this.storageClient == null)
{
this.storageClient = AzureSession.ClientFactory.CreateClient<StorageManagementClient>(
DefaultProfile.Context, AzureEnvironment.Endpoint.ServiceManagement);
DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager);
}

return this.storageClient;
Expand Down Expand Up @@ -201,15 +202,8 @@ protected string GetStorageKey()

if (!string.IsNullOrEmpty(StorageAccountName))
{
var storageAccount = this.StorageClient.StorageAccounts.Get(StorageAccountName);
if (storageAccount != null)
{
var keys = this.StorageClient.StorageAccounts.GetKeys(StorageAccountName);
if (keys != null)
{
storageKey = !string.IsNullOrEmpty(keys.PrimaryKey) ? keys.PrimaryKey : keys.SecondaryKey;
}
}
var storageCredentials = StorageUtilities.GenerateStorageCredentials(this.StorageClient, this.ResourceGroupName, this.StorageAccountName);
storageKey = storageCredentials.ExportBase64EncodedKey();
}

return storageKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.Authorization">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.1\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.7-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.11-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Test.Framework">
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.5715.36130-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Name": "Another tests role",
"Id": "/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/providers/Microsoft.Authorization/roleDefinitions/85E460B3-89E9-48BA-9DCD-A8A99D64A674",
"Id": "85E460B3-89E9-48BA-9DCD-A8A99D64A674",
"Description": "Test role",
"Actions": [
"Microsoft.Authorization/*/read",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,56 @@ public void RaAuthorizationChangeLog()
ResourcesController.NewInstance.RunPsTest("Test-RaAuthorizationChangeLog");
}

[Fact(Skip = "Need to re-record test")]
[Fact(Skip = "tenantID NullException")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RaClassicAdmins()
{
ResourcesController.NewInstance.RunPsTest("Test-RaClassicAdmins");
}

[Fact(Skip = "Need to re-record test")]
[Fact(Skip = "tenantID NullException")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RaNegativeScenarios()
{
ResourcesController.NewInstance.RunPsTest("Test-RaNegativeScenarios");
}

[Fact(Skip = "Need to re-record test")]
[Fact(Skip = "tenantID NullException")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RaByScope()
{
ResourcesController.NewInstance.RunPsTest("Test-RaByScope");
}

[Fact(Skip = "Need to re-record test")]
[Fact(Skip = "tenantID NullException")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RaByResourceGroup()
{
ResourcesController.NewInstance.RunPsTest("Test-RaByResourceGroup");
}

[Fact(Skip = "Need to re-record test")]
[Fact(Skip = "tenantID NullException")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RaByResource()
{
ResourcesController.NewInstance.RunPsTest("Test-RaByResource");
}

[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
[Fact(Skip = "tenantID NullException")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RaByServicePrincipal()
{
ResourcesController.NewInstance.RunPsTest("Test-RaByServicePrincipal");
}

[Fact(Skip = "Need to re-record test")]
[Fact(Skip = "tenantID NullException")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RaByUpn()
{
ResourcesController.NewInstance.RunPsTest("Test-RaByUpn");
}

[Fact(Skip="Need to re-record test")]
[Fact(Skip = "Need to re-record test")]
public void RaUserPermissions()
{
User newUser = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ function Test-RaClassicAdmins
{
# Setup
Add-Type -Path ".\\Microsoft.Azure.Commands.Resources.dll"
$subscription = Get-AzureRmSubscription -Current
$subscription = Get-AzureRmSubscription

# Test
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("8D7DD69E-9AE2-44A1-94D8-F7BC8E12645E")
$classic = Get-AzureRmRoleAssignment -IncludeClassicAdministrators | Where-Object { $_.Scope -ieq ('/subscriptions/' + $subscription.SubscriptionId) -and $_.RoleDefinitionName.ToLower().Contains('administrator')}

# Assert
Expand All @@ -40,22 +39,20 @@ function Test-RaNegativeScenarios
# Setup
Add-Type -Path ".\\Microsoft.Azure.Commands.Resources.dll"

$subscription = Get-AzureRmSubscription -Current
$subscription = Get-AzureRmSubscription

# Bad OID does not throw when getting a non-existing role assignment
$badOid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
$badOidResult = Get-AzureRmRoleAssignment -ObjectId $badOid
Assert-Null $badOidResult
$badObjectResult = "Cannot find principal using the specified options"
Assert-Throws { Get-AzureRmRoleAssignment -ObjectId $badOid} $badObjectResult

# Bad UPN
$badUpn = '[email protected]'
$badUpnException = "The provided information does not map to an AD object id."
Assert-Throws { Get-AzureRmRoleAssignment -UserPrincipalName $badUpn } $badUpnException
Assert-Throws { Get-AzureRmRoleAssignment -UserPrincipalName $badUpn } $badObjectResult

# Bad SPN
$badSpn = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
$badSpnException = "The provided information does not map to an AD object id."
Assert-Throws { Get-AzureRmRoleAssignment -ServicePrincipalName $badSpn } $badSpnException
Assert-Throws { Get-AzureRmRoleAssignment -ServicePrincipalName $badSpn } $badObjectResult

# Bad Scope
$badScope = '/subscriptions/'+ $subscription.SubscriptionId +'/providers/nonexistent'
Expand All @@ -74,7 +71,7 @@ function Test-RaByScope

$definitionName = 'Reader'
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
$subscription = Get-AzureRmSubscription -Current
$subscription = Get-AzureRmSubscription
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
$scope = '/subscriptions/'+ $subscription.SubscriptionId +'/resourceGroups/' + $resourceGroups[0].ResourceGroupName
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."
Expand Down Expand Up @@ -145,7 +142,7 @@ function Test-RaByResource
Assert-AreEqual 1 $groups.Count "There should be at least one group to run the test."
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
Assert-AreEqual 1 $resourceGroups.Count "No resource group found. Unable to run the test."
$resource = Get-AzureRmResource -ResourceGroupName $resourceGroups[0].ResourceGroupName
$resource = Get-AzureRmResource -ResourceGroupName $resourceGroups[0].ResourceGroupName | Select-Object -Last 1 -Wait
Assert-NotNull $resource "Cannot find any resource to continue test execution."

# Test
Expand Down Expand Up @@ -179,7 +176,7 @@ function Test-RaByServicePrincipal

$definitionName = 'Reader'
$servicePrincipals = Get-AzureRmADServicePrincipal | Select-Object -Last 1 -Wait
$subscription = Get-AzureRmSubscription -Current
$subscription = Get-AzureRmSubscription
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
$scope = '/subscriptions/'+ $subscription.SubscriptionId +'/resourceGroups/' + $resourceGroups[0].ResourceGroupName
Assert-AreEqual 1 $servicePrincipals.Count "No service principals found. Unable to run the test."
Expand Down Expand Up @@ -222,7 +219,7 @@ function Test-RaByUpn
# Test
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("8d7dd69e-9ae2-44a1-94d8-f7bc8e12645e")
$newAssignment = New-AzureRmRoleAssignment `
-UPN $users[0].Mail `
-SignInName $users[0].Mail `
-RoleDefinitionName $definitionName `
-ResourceGroupName $resourceGroups[0].ResourceGroupName

Expand Down Expand Up @@ -310,6 +307,6 @@ function VerifyRoleAssignmentDeleted

$deletedRoleAssignment = Get-AzureRmRoleAssignment -ObjectId $roleAssignment.ObjectId.Guid `
-Scope $roleAssignment.Scope `
-RoleDefinitionName $roleAssignment.RoleDefinitionName
-RoleDefinitionName $roleAssignment.RoleDefinitionName | where {$_.roleAssignmentId -eq $roleAssignment.roleAssignmentId}
Assert-Null $deletedRoleAssignment
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function Test-RdNegativeScenarios

# Throws on trying to delete a role that does not exist
$missingSubscription = "MissingSubscription: The request did not have a provided subscription. All requests must have an associated subscription Id."
Assert-Throws { Remove-AzureRmRoleDefinition -Id $rdId -Force} $missingSubscription
Assert-Throws { Remove-AzureRmRoleDefinition -Id $rdId -Force} $badIdException
}

<#
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 73ebe3a

Please sign in to comment.