|
| 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 | +} |
0 commit comments