Skip to content

Commit 1344698

Browse files
committed
Check for null RoleDefinitionName in GetAzureRoleAssignmentCommand
Added tests for GetAzRoleAssingments using only the role name Fix tests Add region for parameter in GetAzureRoleAssignmentCommand
1 parent 5da83e3 commit 1344698

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/Resources/Resources.Test/ScenarioTests/RoleAssignmentTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ----------------------------------------------------------------------------------
1+
// ----------------------------------------------------------------------------------
22
//
33
// Copyright Microsoft Corporation
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -159,6 +159,13 @@ public void RaGetByScope()
159159
TestRunner.RunTestScript("Test-RaGetByScope");
160160
}
161161

162+
[Fact(Skip = "Needs recording. PS-VSPrompt link and TestFramework are broken at time of commit")]
163+
[Trait(Category.AcceptanceType, Category.CheckIn)]
164+
public void RaGetOnlyByRoleDefinitionName()
165+
{
166+
TestRunner.RunTestScript("Test-RaGetOnlyByRoleDefinitionName");
167+
}
168+
162169
[Fact]
163170
[Trait(Category.AcceptanceType, Category.CheckIn)]
164171
public void RaGetByUPNWithExpandPrincipalGroups()

src/Resources/Resources.Test/ScenarioTests/RoleAssignmentTests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,21 @@ function Test-RaGetByScope
639639
VerifyRoleAssignmentDeleted $newAssignment1
640640
}
641641

642+
<#
643+
.SYNOPSIS
644+
Tests verifies get of RoleAssignment using only the role definition name
645+
#>
646+
function Test-RaGetOnlyByRoleDefinitionName
647+
{
648+
# Setup
649+
$definitionName = 'Owner'
650+
651+
$ras = Get-AzRoleAssignment -RoleDefinitionName $definitionName
652+
653+
Assert-NotNull $ras
654+
Assert-AreEqual $definitionName $ras[0].RoleDefinitionName
655+
}
656+
642657
<#
643658
.SYNOPSIS
644659
Creates role assignment

src/Resources/Resources/Models.Authorization/AuthorizationClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
226226

227227
if (!string.IsNullOrEmpty(options.RoleDefinitionName))
228228
{
229-
result = result.Where(r => r.RoleDefinitionName.Equals(options.RoleDefinitionName, StringComparison.OrdinalIgnoreCase)).ToList();
229+
result = result.Where(r => r.RoleDefinitionName?.Equals(options.RoleDefinitionName, StringComparison.OrdinalIgnoreCase) ?? false).ToList();
230230
}
231231

232232
if (options.IncludeClassicAdministrators)

src/Resources/Resources/RoleAssignments/GetAzureRoleAssignmentCommand.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ namespace Microsoft.Azure.Commands.Resources
2929
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RoleAssignment", DefaultParameterSetName = ParameterSet.Empty), OutputType(typeof(PSRoleAssignment))]
3030
public class GetAzureRoleAssignmentCommand : ResourcesBaseCmdlet
3131
{
32+
#region Cmdlet Parameters
33+
3234
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ObjectId,
3335
HelpMessage = "The user or group object id.")]
3436
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ResourceGroupWithObjectId,
@@ -214,6 +216,9 @@ public class GetAzureRoleAssignmentCommand : ResourcesBaseCmdlet
214216
HelpMessage = "If specified, also returns the subscription classic administrators as role assignments.")]
215217
public SwitchParameter IncludeClassicAdministrators { get; set; }
216218

219+
#endregion
220+
221+
217222
public override void ExecuteCmdlet()
218223
{
219224
FilterRoleAssignmentsOptions options = new FilterRoleAssignmentsOptions()

0 commit comments

Comments
 (0)