Skip to content

Commit d13802e

Browse files
authored
add livetest for sp approleassignment (#23770)
1 parent 22fe166 commit d13802e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/Resources/LiveTests/TestLiveScenarios.disabled.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,51 @@ Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process
126126
}
127127
}
128128
}
129+
130+
Invoke-LiveTestScenario -Name "Test Service Principal app role assignment" -Description "Test the process of service principal app role assignment." -NoResourceGroup -ScenarioScript `
131+
{
132+
try {
133+
$today = (Get-Date).tostring('yyyy-MM-dd')
134+
$appName1 = $today + 'testapp' + (New-LiveTestRandomName)
135+
$approleName1 = $today + 'testapprole' + (New-LiveTestRandomName)
136+
$approleName2 = $today + 'testapprole' + (New-LiveTestRandomName)
137+
138+
$spName1 = $today + 'testsp' + (New-LiveTestRandomName)
139+
140+
$approle = New-Object Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10.MicrosoftGraphAppRole
141+
$approle.id = New-Guid
142+
$approle.DisplayName = $approleName1
143+
$approle.Description = $approleName1 + "for test"
144+
$approle.IsEnabled = $true
145+
$approle.AllowedMemberType = @("User", "Application")
146+
$approle.value = New-Guid
147+
148+
$app1 = New-AzADApplication -DisplayName $appName1 -StartDate (Get-Date) -AppRole $approle
149+
$app1 = Get-AzADApplication -DisplayName $appName1
150+
Assert-NotNullOrEmpty $app1.AppRole
151+
$approleId = $app1.AppRole.Id
152+
153+
$resourceSp = New-AzADServicePrincipal -ApplicationObject $app1
154+
$sp1 = New-AzADServicePrincipal -DisplayName $spName1
155+
$sp1 = Get-AzADServicePrincipal -DisplayName $spName1
156+
$approleAssignment1 = New-AzADServicePrincipalAppRoleAssignment -ServicePrincipalDisplayName $spName1 -ResourceId $resourceSp.Id -AppRoleId $approleId
157+
$approleAssignmentId1 = $approleAssignment1.Id
158+
Assert-AreEqual $approleId $approleAssignment1.AppRoleId
159+
160+
$approleAssignment1 = Get-AzADServicePrincipalAppRoleAssignment -AppRoleAssignmentId $approleAssignmentId1 -ServicePrincipalId $sp1.Id
161+
Assert-AreEqual $approleId $approleAssignment1.AppRoleId
162+
Assert-AreEqual $spName1 $approleAssignment1.PrincipalDisplayName
163+
164+
$null = Remove-AzADServicePrincipalAppRoleAssignment -AppRoleAssignmentId $approleAssignmentId1 -ServicePrincipalId $sp1.Id
165+
} finally {
166+
if ($sp1) {
167+
Remove-AzADServicePrincipal -ServicePrincipalName $sp1.ServicePrincipalName[0]
168+
}
169+
if ($resourceSp) {
170+
Remove-AzADServicePrincipal -ObjectId $resourceSp.Id
171+
}
172+
if ($app1) {
173+
Remove-AzADApplication -DisplayName $appName1
174+
}
175+
}
176+
}

0 commit comments

Comments
 (0)