@@ -33,10 +33,10 @@ function Test-GetAllADGroups
33
33
. SYNOPSIS
34
34
Tests getting Active Directory groups.
35
35
#>
36
- function Test-GetADGroupWithSearchString
36
+ function Test-GetADGroupWithSearchString
37
37
{
38
38
param ([string ]$displayName )
39
-
39
+
40
40
# Test
41
41
# Select at most 10 groups. Groups are restricted to contain "test" to fasten the test
42
42
$groups = Get-AzureRmADGroup - SearchString $displayName
@@ -68,7 +68,7 @@ Tests getting Active Directory groups.
68
68
function Test-GetADGroupWithObjectId
69
69
{
70
70
param ([string ]$objectId )
71
-
71
+
72
72
# Test
73
73
$groups = Get-AzureRmADGroup - ObjectId $objectId
74
74
@@ -85,7 +85,7 @@ Tests getting Active Directory group with security enabled .
85
85
function Test-GetADGroupSecurityEnabled
86
86
{
87
87
param ([string ]$objectId , [string ]$securityEnabled )
88
-
88
+
89
89
# Test
90
90
$groups = Get-AzureRmADGroup - ObjectId $objectId
91
91
@@ -134,8 +134,8 @@ function Test-GetADGroupMemberWithGroupObjectId
134
134
135
135
# Test
136
136
$members = Get-AzureRmADGroupMember - GroupObjectId $groupObjectId
137
-
138
- # Assert
137
+
138
+ # Assert
139
139
Assert-AreEqual $members.Count 1
140
140
Assert-AreEqual $members [0 ].Id $userObjectId
141
141
Assert-AreEqual $members [0 ].DisplayName $userName
@@ -148,7 +148,7 @@ Tests getting members from an Active Directory group.
148
148
function Test-GetADGroupMemberWithBadGroupObjectId
149
149
{
150
150
# Test
151
- Assert-Throws { Get-AzureRmADGroupMember - GroupObjectId " baadc0de-baad-c0de-baad-c0debaadc0de" }
151
+ Assert-Throws { Get-AzureRmADGroupMember - GroupObjectId " baadc0de-baad-c0de-baad-c0debaadc0de" }
152
152
}
153
153
154
154
<#
@@ -160,7 +160,7 @@ function Test-GetADGroupMemberWithUserObjectId
160
160
param ([string ]$objectId )
161
161
162
162
# Test
163
- Assert-Throws { Get-AzureRmADGroupMember - GroupObjectId $objectId }
163
+ Assert-Throws { Get-AzureRmADGroupMember - GroupObjectId $objectId }
164
164
}
165
165
166
166
<#
@@ -173,8 +173,8 @@ function Test-GetADGroupMemberFromEmptyGroup
173
173
174
174
# Test
175
175
$members = Get-AzureRmADGroupMember - GroupObjectId $objectId
176
-
177
- # Assert
176
+
177
+ # Assert
178
178
Assert-Null ($members )
179
179
}
180
180
@@ -462,7 +462,7 @@ function Test-NewADApplication
462
462
463
463
# Assert
464
464
Assert-NotNull $application
465
- $apps = Get-AzureRmADApplication
465
+ $apps = Get-AzureRmADApplication
466
466
Assert-NotNull $apps
467
467
Assert-True { $apps.Count -ge 0 }
468
468
@@ -489,13 +489,13 @@ function Test-NewADApplication
489
489
$newDisplayName = getAssetName
490
490
$newHomePage = " http://" + $newDisplayName + " .com"
491
491
$newIdentifierUri = " http://" + $newDisplayName
492
-
492
+
493
493
# Update displayName and HomePage
494
494
Set-AzureRmADApplication - ObjectId $application.ObjectId - DisplayName $newDisplayName - HomePage $newHomePage
495
495
496
- # Update identifierUri
496
+ # Update identifierUri
497
497
Set-AzureRmADApplication - ApplicationId $application.ApplicationId - IdentifierUris $newIdentifierUri
498
-
498
+
499
499
# Get application and verify updated properties
500
500
$app1 = Get-AzureRmADApplication - ObjectId $application.ObjectId
501
501
Assert-NotNull $app1
@@ -504,7 +504,7 @@ function Test-NewADApplication
504
504
Assert-AreEqual $app1.HomePage $newHomePage
505
505
Assert-AreEqual $app1.IdentifierUris [0 ] $newIdentifierUri
506
506
507
- # Delete
507
+ # Delete
508
508
Remove-AzureRmADApplication - ObjectId $application.ObjectId - Force
509
509
}
510
510
@@ -543,7 +543,7 @@ function Test-NewADServicePrincipal
543
543
Tests Creating and deleting service principal without an exisitng application.
544
544
#>
545
545
function Test-NewADServicePrincipalWithoutApp
546
- {
546
+ {
547
547
# Setup
548
548
$displayName = getAssetName
549
549
@@ -573,7 +573,7 @@ function Test-NewADServicePrincipalWithoutApp
573
573
574
574
# update SP displayName
575
575
$newDisplayName = getAssetName
576
-
576
+
577
577
Set-AzureRmADServicePrincipal - ObjectId $servicePrincipal.Id - DisplayName $newDisplayName
578
578
579
579
# Get SP and verify updated name
@@ -588,12 +588,78 @@ function Test-NewADServicePrincipalWithoutApp
588
588
Assert-Throws { Remove-AzureRmADServicePrincipal - ObjectId $servicePrincipal.Id - Force}
589
589
}
590
590
591
+ <#
592
+ . SYNOPSIS
593
+ Tests creating a service principal with reader permissions
594
+ #>
595
+ function Test-NewADServicePrincipalWithReaderRole
596
+ {
597
+ # Setup
598
+ $displayName = getAssetName
599
+ $roleDefinitionName = " Reader"
600
+
601
+ # Test
602
+ $servicePrincipal = New-AzureRmADServicePrincipal - DisplayName $displayName - Role $roleDefinitionName
603
+ Assert-NotNull $servicePrincipal
604
+ Assert-AreEqual $servicePrincipal.DisplayName $displayName
605
+
606
+ try
607
+ {
608
+ $role = Get-AzureRmRoleAssignment - ObjectId $servicePrincipal.Id
609
+ Assert-AreEqual $role.Count 1
610
+ Assert-AreEqual $role.DisplayName $servicePrincipal.DisplayName
611
+ Assert-AreEqual $role.ObjectId $servicePrincipal.Id
612
+ Assert-AreEqual $role.RoleDefinitionName $roleDefinitionName
613
+ Assert-AreEqual $role.ObjectType " ServicePrincipal"
614
+ }
615
+ finally
616
+ {
617
+ Remove-AzureRmADApplication - ApplicationId $servicePrincipal.ApplicationId - Force
618
+ Remove-AzureRmRoleAssignment - ObjectId $servicePrincipal.Id - RoleDefinitionName $roleDefinitionName
619
+ }
620
+ }
621
+
622
+ <#
623
+ . SYNOPSIS
624
+ Tests creating a service principal with permissions over a custom scope
625
+ #>
626
+ function Test-NewADServicePrincipalWithCustomScope
627
+ {
628
+ # Setup
629
+ $displayName = getAssetName
630
+ $defaultRoleDefinitionName = " Contributor"
631
+ $subscription = Get-AzureRmSubscription | Select - Last 1 - Wait
632
+ $resourceGroup = Get-AzureRmResourceGroup | Select - Last 1 - Wait
633
+ $scope = " /subscriptions/" + $subscription.Id + " /resourceGroups/" + $resourceGroup.ResourceGroupName
634
+
635
+ # Test
636
+ $servicePrincipal = New-AzureRmADServicePrincipal - DisplayName $displayName - Scope $scope
637
+ Assert-NotNull $servicePrincipal
638
+ Assert-AreEqual $servicePrincipal.DisplayName $displayName
639
+
640
+ try
641
+ {
642
+ $role = Get-AzureRmRoleAssignment - ObjectId $servicePrincipal.Id
643
+ Assert-AreEqual $role.Count 1
644
+ Assert-AreEqual $role.DisplayName $servicePrincipal.DisplayName
645
+ Assert-AreEqual $role.ObjectId $servicePrincipal.Id
646
+ Assert-AreEqual $role.RoleDefinitionName $defaultRoleDefinitionName
647
+ Assert-AreEqual $role.Scope $scope
648
+ Assert-AreEqual $role.ObjectType " ServicePrincipal"
649
+ }
650
+ finally
651
+ {
652
+ Remove-AzureRmADApplication - ApplicationId $servicePrincipal.ApplicationId - Force
653
+ Remove-AzureRmRoleAssignment - ObjectId $servicePrincipal.Id - Scope $scope - RoleDefinitionName $defaultRoleDefinitionName
654
+ }
655
+ }
656
+
591
657
<#
592
658
. SYNOPSIS
593
659
Tests Creating and deleting application using Password Credentials.
594
660
#>
595
661
function Test-CreateDeleteAppPasswordCredentials
596
- {
662
+ {
597
663
# Setup
598
664
$displayName = getAssetName
599
665
$identifierUri = " http://" + $displayName
@@ -629,7 +695,7 @@ function Test-CreateDeleteAppPasswordCredentials
629
695
630
696
# Remove cred by KeyId
631
697
Remove-AzureRmADAppCredential - ApplicationId $application.ApplicationId - KeyId $cred.KeyId - Force
632
- $cred3 = Get-AzureRmADAppCredential - ApplicationId $application.ApplicationId
698
+ $cred3 = Get-AzureRmADAppCredential - ApplicationId $application.ApplicationId
633
699
Assert-NotNull $cred3
634
700
Assert-AreEqual $cred3.Count 1
635
701
Assert-AreEqual $cred3 [0 ].KeyId $cred1.KeyId
@@ -642,7 +708,7 @@ function Test-CreateDeleteAppPasswordCredentials
642
708
$newApplication = Get-AzureRmADApplication - DisplayNameStartWith " PowershellTestingApp"
643
709
Assert-Throws { New-AzureRmADAppCredential - ApplicationId $newApplication.ApplicationId - Password " Somedummypwd" }
644
710
645
- # Remove App
711
+ # Remove App
646
712
Remove-AzureRmADApplication - ObjectId $application.ObjectId - Force
647
713
}
648
714
@@ -652,7 +718,7 @@ function Test-CreateDeleteAppPasswordCredentials
652
718
Tests Creating and deleting application using Service Principal Credentials.
653
719
#>
654
720
function Test-CreateDeleteSpPasswordCredentials
655
- {
721
+ {
656
722
# Setup
657
723
$displayName = getAssetName
658
724
$password = getAssetName
@@ -689,7 +755,7 @@ function Test-CreateDeleteSpPasswordCredentials
689
755
690
756
# Remove cred by KeyId
691
757
Remove-AzureRmADSpCredential - ServicePrincipalName $servicePrincipal.ServicePrincipalNames [0 ] - KeyId $cred.KeyId - Force
692
- $cred3 = Get-AzureRmADSpCredential - ServicePrincipalName $servicePrincipal.ServicePrincipalNames [0 ]
758
+ $cred3 = Get-AzureRmADSpCredential - ServicePrincipalName $servicePrincipal.ServicePrincipalNames [0 ]
693
759
Assert-NotNull $cred3
694
760
Assert-AreEqual $cred3.Count 1
695
761
Assert-AreEqual $cred3 [0 ].KeyId $cred1.KeyId
@@ -701,7 +767,7 @@ function Test-CreateDeleteSpPasswordCredentials
701
767
}
702
768
Finally
703
769
{
704
- # Remove App
770
+ # Remove App
705
771
$app = Get-AzureRmADApplication - ApplicationId $servicePrincipal.ApplicationId
706
772
Remove-AzureRmADApplication - ObjectId $app.ObjectId - Force
707
773
}
0 commit comments