Skip to content

Commit 0cc5714

Browse files
authored
[MSGraph] add live test for MSGraph (#21656)
* add live test for MSGraph * add live test for MSGraph * remove platform * Update TestLiveScenarios.ps1
1 parent b2442b6 commit 0cc5714

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process of create an application." -NoResourceGroup -ScenarioScript `
2+
{
3+
try {
4+
$today = (Get-Date).tostring('yyyy-MM-dd')
5+
$appName1 = $today + 'testapp' + (New-LiveTestRandomName)
6+
$replyUrl1 = 'https://' + $appName1 + '-reply.com'
7+
$homePage1 = 'https://' + $appName1 + '-home.com'
8+
9+
$appName2 = $today + 'testapp' + (New-LiveTestRandomName)
10+
$replyUrl2 = 'https://' + $appName2 + '-reply.com'
11+
$homePage2 = 'https://' + $appName2 + '-home.com'
12+
13+
$spName1 = $today + 'testsp' + (New-LiveTestRandomName)
14+
$spName2 = $today + 'testsp' + (New-LiveTestRandomName)
15+
16+
$app1 = New-AzADApplication -DisplayName $appName1 -ReplyUrls $replyUrl1 -HomePage $homePage1 -AvailableToOtherTenants $true -StartDate (Get-Date)
17+
$app1 = Get-AzADApplication -DisplayName $appName1
18+
Assert-NotNullOrEmpty $app1
19+
Assert-AreEqual $replyUrl1 $app1.Web.RedirectUri
20+
Assert-AreEqual $homepage1 $app1.Web.HomePageUrl
21+
Assert-AreEqual 'AzureADMultipleOrgs' $app1.SignInAudience
22+
23+
Assert-AreEqual $app1.Id (Get-AzADApplication -ObjectId $app1.id -Select Id).Id
24+
Assert-AreEqual $app1.Id (Get-AzADApplication -ApplicationId $app1.AppId -Select Id).Id
25+
26+
$app1Update = Update-AzADApplication -ObjectId $app1.Id -ReplyUrl $replyUrl2 -HomePage $homepage2 -AvailableToOtherTenants $false
27+
$app1Update = Get-AzADApplication -DisplayName $appName1
28+
29+
Assert-AreEqual $replyUrl2 $app1Update.Web.RedirectUri
30+
Assert-AreEqual $homepage2 $app1Update.Web.HomePageUrl
31+
Assert-AreEqual 'AzureADMyOrg' $app1Update.SignInAudience
32+
Assert-NotNullOrEmpty (Get-AzADAppCredential -ObjectId $app1.Id)
33+
$pw = New-AzADAppCredential -ObjectId $app1.Id -StartDate (get-date)
34+
35+
$certFile = Join-Path $PSScriptRoot 'msgraphtest2.cer'
36+
$content = get-content $certFile -AsByteStream
37+
$certvalue = [System.Convert]::ToBase64String($content)
38+
$cert = New-AzADAppCredential -ObjectId $app1.Id -CertValue $certvalue
39+
40+
Remove-AzADAppCredential -ObjectId $app1.Id -KeyId $pw.KeyId
41+
42+
$sp1 = New-AzADServicePrincipal -ApplicationId $app1.AppId
43+
$sp1 = Get-AzADServicePrincipal -ApplicationId $app1.AppId
44+
$sp2 = New-AzADServicePrincipal -DisplayName $spName2
45+
$sp2 = Get-AzADServicePrincipal -DisplayName $spName2
46+
$app2 = Get-AzADApplication -DisplayName $spName2
47+
} finally {
48+
if ($sp1) {
49+
Remove-AzADServicePrincipal -ServicePrincipalName $sp1.ServicePrincipalName[0]
50+
}
51+
if ($sp2) {
52+
Remove-AzADServicePrincipal -ObjectId $sp2.Id
53+
}
54+
if ($app1) {
55+
Remove-AzADApplication -DisplayName $appName1
56+
}
57+
if ($app2) {
58+
Remove-AzADApplication -DisplayName $spName2
59+
}
60+
}
61+
}
62+
63+
Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process of create groups and members." -NoResourceGroup -ScenarioScript `
64+
{
65+
try {
66+
$today = (Get-Date).tostring('yyyy-MM-dd')
67+
$groupName1 = $today + 'testgroup' + (New-LiveTestRandomName)
68+
$groupName2 = $today + 'testgroup' + (New-LiveTestRandomName)
69+
$userName = $today + 'testuser' + (New-LiveTestRandomName)
70+
71+
$groupMailNickName1 = New-LiveTestRandomName
72+
$groupMailNickName2 = New-LiveTestRandomName
73+
$userMailNickName = New-LiveTestRandomName
74+
$userPrincipalName = $userMailNickName + 'microsoft.com#EXT#@AzureSDKTeam.onmicrosoft.com'
75+
76+
$group1 = New-AzADGroup -DisplayName $groupName1 -MailNickname $groupMailNickName1
77+
$group1 = Get-AzADGroup -DisplayName $groupName1
78+
$group2 = New-AzADGroup -DisplayName $groupName2 -MailNickname $groupMailNickName2
79+
$group2 = Get-AzADGroup -DisplayName $groupName2
80+
81+
$password = 'A' + (New-LiveTestRandomName)
82+
$password = ConvertTo-SecureString -AsPlainText -Force $password
83+
$user = New-AzADUser -DisplayName $userName -Password $password -AccountEnabled $true -MailNickname $userMailNickname -UserPrincipalName $userPrincipalName
84+
$user = Get-AzADUser -DisplayName $userName
85+
86+
Add-AzADGroupMember -TargetGroupObjectId $group1.Id -MemberObjectId $group2.Id, $user.Id
87+
88+
#TODO: test type of group member and properties, for example, user principal name from user
89+
$members = Get-AzADGroupMember -GroupObjectId $group1.Id
90+
foreach ($member in $members) {
91+
switch ($member.OdataType) {
92+
'#microsoft.graph.user' {
93+
Assert-AreEqual $user.Id $member.Id
94+
Remove-AzADGroupMember -GroupObjectId $group1.Id -MemberObjectId $user.Id
95+
}
96+
'#microsoft.graph.group' {
97+
Assert-AreEqual $group2.Id $member.Id
98+
Remove-AzADGroupMember -GroupObjectId $group1.Id -MemberObjectId $group2.Id
99+
}
100+
}
101+
}
102+
} finally {
103+
if ($user) {
104+
Remove-AzADUser -ObjectId $user.Id
105+
}
106+
if ($group2) {
107+
Remove-AzADGroup -ObjectId $group2.Id
108+
}
109+
if ($group1) {
110+
Remove-AzADGroup -ObjectId $group1.Id
111+
}
112+
}
113+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIEGTCCAwGgAwIBAgIQJGmcQ90Ht55ojXCPEWWLQDANBgkqhkiG9w0BAQsFADBN
3+
MUswSQYDVQQDHkIATQBTAC0ATwByAGcAYQBuAGkAegBhAHQAaQBvAG4ALQBQADIA
4+
UAAtAEEAYwB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