Skip to content

Commit 25fb72a

Browse files
committed
Add test coverage for no role assignment in default SP creation scenario
1 parent 215888e commit 25fb72a

File tree

8 files changed

+361
-167
lines changed

8 files changed

+361
-167
lines changed

ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Revert change to `New-AzureRmADServicePrincipal` that gave service principals `Contributor` permissions over the current subscription if no values were provided for the `Role` or `Scope` parameters
44
- If no values are provided for `Role` or `Scope`, the service principal is created with no permissions
55
- If a `Role` is provided, but no `Scope`, the service principal is created with the specified `Role` permissions over the current subscription
6-
- If a `Scope` is provided, but no `Scope`, the service principal is created with `Contributor` permissions over the specified `Scope`
6+
- If a `Scope` is provided, but no `Role`, the service principal is created with `Contributor` permissions over the specified `Scope`
77
- If both `Role` and `Scope` are provided, the service principal is created with the specified `Role` permissions over the specified `Scope`
88

99
## 6.1.0 - May 2018

src/ResourceManager/Resources/AzureRM.Resources.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ PrivateData = @{
163163
ReleaseNotes = '* Revert change to `New-AzureRmADServicePrincipal` that gave service principals `Contributor` permissions over the current subscription if no values were provided for the `Role` or `Scope` parameters
164164
- If no values are provided for `Role` or `Scope`, the service principal is created with no permissions
165165
- If a `Role` is provided, but no `Scope`, the service principal is created with the specified `Role` permissions over the current subscription
166-
- If a `Scope` is provided, but no `Scope`, the service principal is created with `Contributor` permissions over the specified `Scope`
166+
- If a `Scope` is provided, but no `Role`, the service principal is created with `Contributor` permissions over the specified `Scope`
167167
- If both `Role` and `Scope` are provided, the service principal is created with the specified `Role` permissions over the specified `Scope`'
168168

169169
# Prerelease string of this module

src/ResourceManager/Resources/ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Revert change to `New-AzureRmADServicePrincipal` that gave service principals `Contributor` permissions over the current subscription if no values were provided for the `Role` or `Scope` parameters
2424
- If no values are provided for `Role` or `Scope`, the service principal is created with no permissions
2525
- If a `Role` is provided, but no `Scope`, the service principal is created with the specified `Role` permissions over the current subscription
26-
- If a `Scope` is provided, but no `Scope`, the service principal is created with `Contributor` permissions over the specified `Scope`
26+
- If a `Scope` is provided, but no `Role`, the service principal is created with `Contributor` permissions over the specified `Scope`
2727
- If both `Role` and `Scope` are provided, the service principal is created with the specified `Role` permissions over the specified `Scope`
2828

2929
## Version 6.0.0

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ActiveDirectoryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public void TestNewADApplication()
599599
ResourcesController.NewInstance.RunPsTest("Test-NewADApplication");
600600
}
601601

602-
[Fact(Skip = "Need AD team to re-record test")]
602+
[Fact]
603603
[Trait(Category.AcceptanceType, Category.CheckIn)]
604604
public void TestNewADServicePrincipalWithoutApp()
605605
{

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ActiveDirectoryTests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,12 @@ function Test-NewADServicePrincipalWithoutApp
549549

550550
# Test
551551
$servicePrincipal = New-AzureRmADServicePrincipal -DisplayName $displayName
552+
$role = Get-AzureRmRoleAssignment -ObjectId $servicePrincipal.Id
552553

553554
# Assert
554555
Assert-NotNull $servicePrincipal
555556
Assert-AreEqual $servicePrincipal.DisplayName $displayName
557+
Assert-Null $role
556558

557559
# GetServicePrincipal by ObjectId
558560
$sp1 = Get-AzureRmADServicePrincipal -ObjectId $servicePrincipal.Id

src/ResourceManager/Resources/Commands.Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests/TestNewADServicePrincipalWithoutApp.json

Lines changed: 342 additions & 161 deletions
Large diffs are not rendered by default.

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/UpdateAzureADServicePrincipalCommand.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override void ExecuteCmdlet()
100100
}
101101

102102
// Get AppObjectId
103-
var applicationObjectId = sp.Id;
103+
var applicationObjectId = GetObjectIdFromApplicationId(sp.ApplicationId.ToString());
104104
ApplicationUpdateParameters parameters = new ApplicationUpdateParameters()
105105
{
106106
DisplayName = DisplayName,
@@ -117,5 +117,16 @@ public override void ExecuteCmdlet()
117117
}
118118
});
119119
}
120+
121+
private Guid GetObjectIdFromApplicationId(string applicationId)
122+
{
123+
var odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.AppId == applicationId);
124+
var app = ActiveDirectoryClient.GetApplicationWithFilters(odataQueryFilter).SingleOrDefault();
125+
if (app == null)
126+
{
127+
throw new InvalidOperationException(String.Format("Application with AppId '{0}' does not exist.", applicationId));
128+
}
129+
return app.ObjectId;
130+
}
120131
}
121132
}

tools/AzureRM/AzureRM.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ AzureRM.Resources
164164
* Revert change to `New-AzureRmADServicePrincipal` that gave service principals `Contributor` permissions over the current subscription if no values were provided for the `Role` or `Scope` parameters
165165
- If no values are provided for `Role` or `Scope`, the service principal is created with no permissions
166166
- If a `Role` is provided, but no `Scope`, the service principal is created with the specified `Role` permissions over the current subscription
167-
- If a `Scope` is provided, but no `Scope`, the service principal is created with `Contributor` permissions over the specified `Scope`
167+
- If a `Scope` is provided, but no `Role`, the service principal is created with `Contributor` permissions over the specified `Scope`
168168
- If both `Role` and `Scope` are provided, the service principal is created with the specified `Role` permissions over the specified `Scope`
169169
'
170170

0 commit comments

Comments
 (0)