From 32dd0dcd48f72ec95a99dbbb46dcce3f3d426901 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Mon, 24 Apr 2023 14:20:10 +0800 Subject: [PATCH 1/4] add live test for MSGraph --- src/Resources/LiveTests/TestLiveScenarios.ps1 | 112 ++++++++++++++++++ src/Resources/LiveTests/msgraphtest2.cer | 24 ++++ 2 files changed, 136 insertions(+) create mode 100644 src/Resources/LiveTests/TestLiveScenarios.ps1 create mode 100644 src/Resources/LiveTests/msgraphtest2.cer diff --git a/src/Resources/LiveTests/TestLiveScenarios.ps1 b/src/Resources/LiveTests/TestLiveScenarios.ps1 new file mode 100644 index 000000000000..e9f9dda9fc36 --- /dev/null +++ b/src/Resources/LiveTests/TestLiveScenarios.ps1 @@ -0,0 +1,112 @@ +Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process of create an application." -Platform Linux -PowerShellVersion Latest -ScenarioScript ` +{ + try { + $today = (Get-Date).tostring('yyyy-MM-dd') + $appName1 = $today + 'testapp' + ${New-LiveTestRandomName} + $replyUrl1 = 'https://' + $appName1 + '-reply.com' + $homePage1 = 'https://' + $appName1 + '-home.com' + + $appName2 = $today + 'testapp' + ${New-LiveTestRandomName} + $replyUrl2 = 'https://' + $appName2 + '-reply.com' + $homePage2 = 'https://' + $appName2 + '-home.com' + + $spName1 = $today + 'testsp' + ${New-LiveTestRandomName} + $spName2 = $today + 'testsp' + ${New-LiveTestRandomName} + + New-AzADApplication -DisplayName $appName1 -ReplyUrls $replyUrl1 -HomePage $homePage1 -AvailableToOtherTenants $true -StartDate (Get-Date) + $app1 = Get-AzADApplication -DisplayName $appName1 + Assert-NotNullOrEmpty $app1 + Assert-AreEqual $replyUrl1 $app1.Web.RedirectUri + Assert-AreEqual $homepage1 $app1.Web.HomePageUrl + Assert-AreEqual 'AzureADMultipleOrgs' $app1.SignInAudience + + Assert-AreEqual $app1.Id (Get-AzADApplication -ObjectId $app1.id -Select Id).Id + Assert-AreEqual $app1.Id (Get-AzADApplication -ApplicationId $app1.AppId -Select Id).Id + + Update-AzADApplication -ObjectId $app1.Id -ReplyUrl $replyUrl2 -HomePage $homepage2 -AvailableToOtherTenants $false + $app1Update = Get-AzADApplication -DisplayName $appName1 + + Assert-AreEqual $replyUrl2 $app1Update.Web.RedirectUri + Assert-AreEqual $homepage2 $app1Update.Web.HomePageUrl + Assert-AreEqual 'AzureADMyOrg' $app1Update.SignInAudience + Assert-NotNullOrEmpty (Get-AzADAppCredential -ObjectId $app1.Id) + $pw = New-AzADAppCredential -ObjectId $app1.Id -StartDate (get-date) + + $certFile = Join-Path $PSScriptRoot 'msgraphtest2.cer' + $content = get-content $certFile -AsByteStream + $certvalue = [System.Convert]::ToBase64String($content) + $cert = New-AzADAppCredential -ObjectId $app1.Id -CertValue $certvalue + + Remove-AzADAppCredential -ObjectId $app1.Id -KeyId $pw.KeyId + + New-AzADServicePrincipal -ApplicationId $app1.AppId + $sp1 = Get-AzADServicePrincipal -ApplicationId $app1.AppId + New-AzADServicePrincipal -DisplayName $spName2 + $sp2 = Get-AzADServicePrincipal -ApplicationId -DisplayName $spName2 + $app2 = Get-AzADApplication -DisplayName $spName2 + } finally { + if ($sp1) { + Remove-AzADServicePrincipal -ServicePrincipalName $sp1.ServicePrincipalName[0] + } + if ($sp2) { + Remove-AzADServicePrincipal -ObjectId $sp2.Id + } + if ($app1) { + Remove-AzADApplication -DisplayName $appName1 + } + if ($app2) { + Remove-AzADApplication -DisplayName $spName2 + } + } +} + +Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process of create groups and members." -Platform Linux -PowerShellVersion Latest -ScenarioScript ` +{ + try { + $today = (Get-Date).tostring('yyyy-MM-dd') + $groupName1 = $today + 'testgroup' + ${New-LiveTestRandomName} + $groupName2 = $today + 'testgroup' + ${New-LiveTestRandomName} + $userName = $today + 'testuser' + ${New-LiveTestRandomName} + + $groupMailNickName1 = New-LiveTestRandomName + $groupMailNickName2 = New-LiveTestRandomName + $userMailNickName = New-LiveTestRandomName + $userPrincipalName = $userMailNickName + 'microsoft.com#EXT#@AzureSDKTeam.onmicrosoft.com' + + New-AzADGroup -DisplayName $groupName1 -MailNickname $groupMailNickName1 + $group1 = Get-AzADGroup -DisplayName $groupName1 + New-AzADGroup -DisplayName $groupName2 -MailNickname $groupMailNickName2 + $group2 = Get-AzADGroup -DisplayName $groupName2 + + $password = New-LiveTestRandomName + $password = ConvertTo-SecureString -AsPlainText -Force $password + New-AzADUser -DisplayName $userName -Password $password -AccountEnabled $true -MailNickname $userMailNickname -UserPrincipalName $userPrincipalName + $user = Get-AzADUser -DisplayName $userName + + Add-AzADGroupMember -TargetGroupObjectId $group1.Id -MemberObjectId $group2.Id, $user.Id + + #TODO: test type of group member and properties, for example, user principal name from user + Get-AzADGroupMember -GroupObjectId $group1.Id | ForEach-Object { + switch ($_.OdataType) { + '#microsoft.graph.user' { + Assert-AreEqual $user.Id $_.Id + Remove-AzADGroupMember -MemberObjectId $user.Id + } + '#microsoft.graph.group' { + Assert-AreEqual $group2.Id $_.Id + Remove-AzADGroupMember -MemberObjectId $group2.Id + } + } + } + } finally { + if ($user) { + Remove-AzADUser -ObjectId $user.Id + } + if ($group2) { + Remove-AzADGroup -ObjectId $group2.Id + } + if ($group1) { + Remove-AzADGroup -ObjectId $group1.Id + } + } +} \ No newline at end of file diff --git a/src/Resources/LiveTests/msgraphtest2.cer b/src/Resources/LiveTests/msgraphtest2.cer new file mode 100644 index 000000000000..0962c2e729c2 --- /dev/null +++ b/src/Resources/LiveTests/msgraphtest2.cer @@ -0,0 +1,24 @@ +-----BEGIN CERTIFICATE----- +MIIEGTCCAwGgAwIBAgIQJGmcQ90Ht55ojXCPEWWLQDANBgkqhkiG9w0BAQsFADBN +MUswSQYDVQQDHkIATQBTAC0ATwByAGcAYQBuAGkAegBhAHQAaQBvAG4ALQBQADIA +UAAtAEEAYwBjAGUAcwBzACAAWwAyADAAMgAxAF0wHhcNMjEwOTI3MDQxNTQ1WhcN +MjEwOTI4MDQyMDQ1WjBlMTQw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U4XFHPQxW+mR11QuUja +gar3muui3dsRAMOYslaL+bRONWvjPuPLbCFCSExl65/CZo9TjtUUTPnksB2zQhOl +jt9bt64s4pJoGyGDFeu1g4PJDzR2E1oqRTs2KVAptBvU5RHgky3Y1nHRdfhL +-----END CERTIFICATE----- From 2294874d3c56a84f86f08e86d282fc8e16f0d702 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Wed, 26 Apr 2023 16:50:25 +0800 Subject: [PATCH 2/4] add live test for MSGraph --- src/Resources/LiveTests/TestLiveScenarios.ps1 | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Resources/LiveTests/TestLiveScenarios.ps1 b/src/Resources/LiveTests/TestLiveScenarios.ps1 index e9f9dda9fc36..9d1ee8d26235 100644 --- a/src/Resources/LiveTests/TestLiveScenarios.ps1 +++ b/src/Resources/LiveTests/TestLiveScenarios.ps1 @@ -1,19 +1,19 @@ -Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process of create an application." -Platform Linux -PowerShellVersion Latest -ScenarioScript ` +Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process of create an application." -NoResourceGroup -Platform Windows -PowerShellVersion Latest -ScenarioScript ` { try { $today = (Get-Date).tostring('yyyy-MM-dd') - $appName1 = $today + 'testapp' + ${New-LiveTestRandomName} + $appName1 = $today + 'testapp' + (New-LiveTestRandomName) $replyUrl1 = 'https://' + $appName1 + '-reply.com' $homePage1 = 'https://' + $appName1 + '-home.com' - $appName2 = $today + 'testapp' + ${New-LiveTestRandomName} + $appName2 = $today + 'testapp' + (New-LiveTestRandomName) $replyUrl2 = 'https://' + $appName2 + '-reply.com' $homePage2 = 'https://' + $appName2 + '-home.com' - $spName1 = $today + 'testsp' + ${New-LiveTestRandomName} - $spName2 = $today + 'testsp' + ${New-LiveTestRandomName} + $spName1 = $today + 'testsp' + (New-LiveTestRandomName) + $spName2 = $today + 'testsp' + (New-LiveTestRandomName) - New-AzADApplication -DisplayName $appName1 -ReplyUrls $replyUrl1 -HomePage $homePage1 -AvailableToOtherTenants $true -StartDate (Get-Date) + $app1 = New-AzADApplication -DisplayName $appName1 -ReplyUrls $replyUrl1 -HomePage $homePage1 -AvailableToOtherTenants $true -StartDate (Get-Date) $app1 = Get-AzADApplication -DisplayName $appName1 Assert-NotNullOrEmpty $app1 Assert-AreEqual $replyUrl1 $app1.Web.RedirectUri @@ -23,7 +23,7 @@ Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process Assert-AreEqual $app1.Id (Get-AzADApplication -ObjectId $app1.id -Select Id).Id Assert-AreEqual $app1.Id (Get-AzADApplication -ApplicationId $app1.AppId -Select Id).Id - Update-AzADApplication -ObjectId $app1.Id -ReplyUrl $replyUrl2 -HomePage $homepage2 -AvailableToOtherTenants $false + $app1Update = Update-AzADApplication -ObjectId $app1.Id -ReplyUrl $replyUrl2 -HomePage $homepage2 -AvailableToOtherTenants $false $app1Update = Get-AzADApplication -DisplayName $appName1 Assert-AreEqual $replyUrl2 $app1Update.Web.RedirectUri @@ -39,10 +39,10 @@ Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process Remove-AzADAppCredential -ObjectId $app1.Id -KeyId $pw.KeyId - New-AzADServicePrincipal -ApplicationId $app1.AppId + $sp1 = New-AzADServicePrincipal -ApplicationId $app1.AppId $sp1 = Get-AzADServicePrincipal -ApplicationId $app1.AppId - New-AzADServicePrincipal -DisplayName $spName2 - $sp2 = Get-AzADServicePrincipal -ApplicationId -DisplayName $spName2 + $sp2 = New-AzADServicePrincipal -DisplayName $spName2 + $sp2 = Get-AzADServicePrincipal -DisplayName $spName2 $app2 = Get-AzADApplication -DisplayName $spName2 } finally { if ($sp1) { @@ -60,41 +60,42 @@ Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process } } -Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process of create groups and members." -Platform Linux -PowerShellVersion Latest -ScenarioScript ` +Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process of create groups and members." -NoResourceGroup -Platform Windows -PowerShellVersion Latest -ScenarioScript ` { try { $today = (Get-Date).tostring('yyyy-MM-dd') - $groupName1 = $today + 'testgroup' + ${New-LiveTestRandomName} - $groupName2 = $today + 'testgroup' + ${New-LiveTestRandomName} - $userName = $today + 'testuser' + ${New-LiveTestRandomName} + $groupName1 = $today + 'testgroup' + (New-LiveTestRandomName) + $groupName2 = $today + 'testgroup' + (New-LiveTestRandomName) + $userName = $today + 'testuser' + (New-LiveTestRandomName) $groupMailNickName1 = New-LiveTestRandomName $groupMailNickName2 = New-LiveTestRandomName $userMailNickName = New-LiveTestRandomName $userPrincipalName = $userMailNickName + 'microsoft.com#EXT#@AzureSDKTeam.onmicrosoft.com' - New-AzADGroup -DisplayName $groupName1 -MailNickname $groupMailNickName1 + $group1 = New-AzADGroup -DisplayName $groupName1 -MailNickname $groupMailNickName1 $group1 = Get-AzADGroup -DisplayName $groupName1 - New-AzADGroup -DisplayName $groupName2 -MailNickname $groupMailNickName2 + $group2 = New-AzADGroup -DisplayName $groupName2 -MailNickname $groupMailNickName2 $group2 = Get-AzADGroup -DisplayName $groupName2 - $password = New-LiveTestRandomName + $password = 'A' + (New-LiveTestRandomName) $password = ConvertTo-SecureString -AsPlainText -Force $password - New-AzADUser -DisplayName $userName -Password $password -AccountEnabled $true -MailNickname $userMailNickname -UserPrincipalName $userPrincipalName + $user = New-AzADUser -DisplayName $userName -Password $password -AccountEnabled $true -MailNickname $userMailNickname -UserPrincipalName $userPrincipalName $user = Get-AzADUser -DisplayName $userName Add-AzADGroupMember -TargetGroupObjectId $group1.Id -MemberObjectId $group2.Id, $user.Id #TODO: test type of group member and properties, for example, user principal name from user - Get-AzADGroupMember -GroupObjectId $group1.Id | ForEach-Object { - switch ($_.OdataType) { + $members = Get-AzADGroupMember -GroupObjectId $group1.Id + foreach ($member in $members) { + switch ($member.OdataType) { '#microsoft.graph.user' { - Assert-AreEqual $user.Id $_.Id - Remove-AzADGroupMember -MemberObjectId $user.Id + Assert-AreEqual $user.Id $member.Id + Remove-AzADGroupMember -GroupObjectId $group1.Id -MemberObjectId $user.Id } '#microsoft.graph.group' { - Assert-AreEqual $group2.Id $_.Id - Remove-AzADGroupMember -MemberObjectId $group2.Id + Assert-AreEqual $group2.Id $member.Id + Remove-AzADGroupMember -GroupObjectId $group1.Id -MemberObjectId $group2.Id } } } From 9ab158bb1cb101f0544f871fb3cd5bcedc0fa6e8 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Thu, 4 May 2023 10:47:44 +0800 Subject: [PATCH 3/4] remove platform --- src/Resources/LiveTests/TestLiveScenarios.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Resources/LiveTests/TestLiveScenarios.ps1 b/src/Resources/LiveTests/TestLiveScenarios.ps1 index 9d1ee8d26235..d98913de4cff 100644 --- a/src/Resources/LiveTests/TestLiveScenarios.ps1 +++ b/src/Resources/LiveTests/TestLiveScenarios.ps1 @@ -1,4 +1,4 @@ -Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process of create an application." -NoResourceGroup -Platform Windows -PowerShellVersion Latest -ScenarioScript ` +Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process of create an application." -NoResourceGroup -PowerShellVersion Latest -ScenarioScript ` { try { $today = (Get-Date).tostring('yyyy-MM-dd') @@ -60,7 +60,7 @@ Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process } } -Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process of create groups and members." -NoResourceGroup -Platform Windows -PowerShellVersion Latest -ScenarioScript ` +Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process of create groups and members." -NoResourceGroup -PowerShellVersion Latest -ScenarioScript ` { try { $today = (Get-Date).tostring('yyyy-MM-dd') From 1f440156897cd46eebcc493881160af000e58f23 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Thu, 4 May 2023 16:52:46 +0800 Subject: [PATCH 4/4] Update TestLiveScenarios.ps1 --- src/Resources/LiveTests/TestLiveScenarios.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Resources/LiveTests/TestLiveScenarios.ps1 b/src/Resources/LiveTests/TestLiveScenarios.ps1 index d98913de4cff..1a0c34fd48f0 100644 --- a/src/Resources/LiveTests/TestLiveScenarios.ps1 +++ b/src/Resources/LiveTests/TestLiveScenarios.ps1 @@ -1,4 +1,4 @@ -Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process of create an application." -NoResourceGroup -PowerShellVersion Latest -ScenarioScript ` +Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process of create an application." -NoResourceGroup -ScenarioScript ` { try { $today = (Get-Date).tostring('yyyy-MM-dd') @@ -60,7 +60,7 @@ Invoke-LiveTestScenario -Name "Test Application" -Description "Test the process } } -Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process of create groups and members." -NoResourceGroup -PowerShellVersion Latest -ScenarioScript ` +Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process of create groups and members." -NoResourceGroup -ScenarioScript ` { try { $today = (Get-Date).tostring('yyyy-MM-dd') @@ -110,4 +110,4 @@ Invoke-LiveTestScenario -Name "Test Group Member" -Description "Test the process Remove-AzADGroup -ObjectId $group1.Id } } -} \ No newline at end of file +}