From 44eae7956fd20d644bf236830b1668af4f8058c0 Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Wed, 24 Apr 2024 17:35:04 +0530 Subject: [PATCH 1/9] Added test cases for Application --- .../Get-EntraApplication.Tests.ps1 | 36 +++++++++++++++++++ .../New-EntraApplication.Tests.ps1 | 28 +++++++++++++++ .../Set-EntraApplication.Tests.ps1 | 34 ++++++++++++++++++ test/module/Entra/Integration/setenv.ps1 | 3 ++ 4 files changed, 101 insertions(+) create mode 100644 test/module/Entra/Integration/Get-EntraApplication.Tests.ps1 create mode 100644 test/module/Entra/Integration/New-EntraApplication.Tests.ps1 create mode 100644 test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 create mode 100644 test/module/Entra/Integration/setenv.ps1 diff --git a/test/module/Entra/Integration/Get-EntraApplication.Tests.ps1 b/test/module/Entra/Integration/Get-EntraApplication.Tests.ps1 new file mode 100644 index 0000000000..199acea382 --- /dev/null +++ b/test/module/Entra/Integration/Get-EntraApplication.Tests.ps1 @@ -0,0 +1,36 @@ +Describe "The Get-EntraApplication command executing unmocked" { + + Context "When getting applications" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $testAppName = 'SimpleTestAppRead' + $thisTestInstanceId + $testApp = New-EntraApplication -DisplayName $testAppName + } + + It "should successfully read the application with expected properties when the application ID parameter is used" { + $app = Get-EntraApplication -ObjectId $testApp.Id + $app.Id | Should -Be $testApp.Id + $app.DisplayName | Should -Be $testAppName + } + + It "should throw an exception if a nonexistent object ID parameter is specified" { + $Id = (New-Guid).Guid + Get-EntraApplication -ObjectId $Id -ErrorAction Stop + $Error[0] | Should -match "Resource '([^']+)' does not exist" + } + + AfterAll { + foreach ($app in (Get-EntraApplication -All $true | Where-Object { $_.DisplayName -eq $testAppName})) { + Remove-EntraApplication -ObjectId $app.Id | Out-Null + } + + } + } +} diff --git a/test/module/Entra/Integration/New-EntraApplication.Tests.ps1 b/test/module/Entra/Integration/New-EntraApplication.Tests.ps1 new file mode 100644 index 0000000000..ce3951bac2 --- /dev/null +++ b/test/module/Entra/Integration/New-EntraApplication.Tests.ps1 @@ -0,0 +1,28 @@ +Describe "The Get-EntraApplication command executing unmocked" { + + Context "When creating applications" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + } + + It "should succeed when creating a new application" { + $testAppName = 'SimpleTestApp' + $thisTestInstanceId + $newApp = New-EntraApplication -DisplayName $testAppName + $newApp.DisplayName | Should -Be $testAppName + { Get-EntraApplication -ObjectId $newApp.Id } | Should -Not -BeNullOrEmpty + } + + AfterAll { + foreach ($app in (Get-EntraApplication -All $true | Where-Object { $_.DisplayName -eq $testAppName})) { + Remove-EntraApplication -ObjectId $app.Id | Out-Null + } + } + } +} diff --git a/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 b/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 new file mode 100644 index 0000000000..f7a3425ed1 --- /dev/null +++ b/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 @@ -0,0 +1,34 @@ +Describe "The Get-EntraApplication command executing unmocked" { + + Context "When getting applications" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-MgGraph -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $testAppName = 'SimpleTestAppRead' + $thisTestInstanceId + $testApp = New-EntraApplication -DisplayName $testAppName + } + + It "should successfully update the application with expected properties when the application ID parameter is used" { + $thisTestInstanceId = New-Guid | select -expandproperty guid + $newAppName = 'SimpleTestAppUpdate' + $thisTestInstanceId + Set-EntraApplication -ObjectId $testApp.Id -DisplayName $newAppName | Should -BeNullOrEmpty + + $app = Get-EntraApplication -ObjectId $testApp.Id + $app.Id | Should -Be $testApp.Id + $app.DisplayName | Should -Be $newAppName + } + + AfterAll { + foreach ($app in (Get-EntraApplication -All $true | Where-Object { $_.DisplayName -eq $newAppName})) { + Remove-EntraApplication -ObjectId $app.Id | Out-Null + } + + } + } +} diff --git a/test/module/Entra/Integration/setenv.ps1 b/test/module/Entra/Integration/setenv.ps1 new file mode 100644 index 0000000000..819497c12e --- /dev/null +++ b/test/module/Entra/Integration/setenv.ps1 @@ -0,0 +1,3 @@ +$env:TEST_APPID = "8886ad7b-1795-4542-9808-c85859d97f23" +$env:TEST_TENANTID = "d5aec55f-2d12-4442-8d2f-ccca95d4390e" +$env:CERTIFICATETHUMBPRINT = "714CCF133715A7987BADA4E766FB3E9A1B3D8A6F" \ No newline at end of file From 33d224eeaf91852c473708ab9687ba10b6153a9f Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Thu, 25 Apr 2024 12:23:16 +0530 Subject: [PATCH 2/9] Integration-Testing --- .../Add-EntraGroupMember.Tests.ps1 | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 diff --git a/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 b/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 new file mode 100644 index 0000000000..bc84fac5c1 --- /dev/null +++ b/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 @@ -0,0 +1,45 @@ +Describe "The Get-EntraApplication command executing unmocked" { + + Context "When getting applications" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $groupId = (Get-EntraGroup -Top 1).Id + $user = (Get-EntraUser -Top 1).Id + $servicePrincipal = (Get-EntraServicePrincipal -Top 1).Id + } + + It "should successfully add user to the Group" { + Add-EntraGroupMember -ObjectId $groupId -RefObjectId $memberId + $result = Get-EntraGroupMember -ObjectId $groupId + $result.Id | Should -Contain $memberId + } + + It "should successfully add service principal to the Group" { + Add-EntraGroupMember -ObjectId $groupId -RefObjectId $memberId + $result = Get-EntraGroupMember -ObjectId $servicePrincipal + $result.Id | Should -Contain $memberId + } + + It "should successfully add group to the Group" { + Add-EntraGroupMember -ObjectId $groupId -RefObjectId $memberId + $result = Get-EntraGroupMember -ObjectId $servicePrincipal + $result.Id | Should -Contain $memberId + } + # It "should throw an exception if a nonexistent object ID parameter is specified" { + # $Id = (New-Guid).Guid + # Get-EntraGroupMember -ObjectId $Id -ErrorAction Stop + # $Error[0] | Should -match "Resource '([^']+)' does not exist" + # } + + AfterAll { + Remove-EntraGroupMember -ObjectId $groupId -MemberId $memberId + } + } +} From f61f184314c2e7bc62828f97169d4febfe092453 Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Thu, 25 Apr 2024 15:48:22 +0530 Subject: [PATCH 3/9] added Add-EntraGroupMember --- .../Add-EntraGroupMember.Tests.ps1 | 49 +++++++++---------- .../Set-EntraApplication.Tests.ps1 | 2 +- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 b/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 index bc84fac5c1..87c2f031b8 100644 --- a/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 +++ b/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 @@ -1,6 +1,6 @@ -Describe "The Get-EntraApplication command executing unmocked" { +Describe "The Add-EntraGroupMember command executing unmocked" { - Context "When getting applications" { + Context "When getting user and group" { BeforeAll { $testReportPath = join-path $psscriptroot "\setenv.ps1" Import-Module -Name $testReportPath @@ -10,36 +10,35 @@ Describe "The Get-EntraApplication command executing unmocked" { Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert $thisTestInstanceId = New-Guid | select -expandproperty guid - $groupId = (Get-EntraGroup -Top 1).Id - $user = (Get-EntraUser -Top 1).Id - $servicePrincipal = (Get-EntraServicePrincipal -Top 1).Id - } + $testName = 'SimpleTest' + $thisTestInstanceId - It "should successfully add user to the Group" { - Add-EntraGroupMember -ObjectId $groupId -RefObjectId $memberId - $result = Get-EntraGroupMember -ObjectId $groupId - $result.Id | Should -Contain $memberId + #create test user + $PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile + $PasswordProfile.Password = "Pass@1234" + $global:newUser = New-EntraUser -AccountEnabled $true -DisplayName $testName -PasswordProfile $PasswordProfile -MailNickName $testName -UserPrincipalName "SimpleTestUser@M365x99297270.OnMicrosoft.com" + + #create test group + $global:newGroup = New-EntraGroup -DisplayName $testName -MailEnabled $false -SecurityEnabled $true -MailNickName $testName } - It "should successfully add service principal to the Group" { - Add-EntraGroupMember -ObjectId $groupId -RefObjectId $memberId - $result = Get-EntraGroupMember -ObjectId $servicePrincipal - $result.Id | Should -Contain $memberId - } + It "should successfully add user to new created group" { + $user = Get-EntraUser -ObjectId $newUser.Id + $user.Id | Should -Be $newUser.Id + $user.DisplayName | Should -Be $testName + + $group = Get-EntraGroup -ObjectId $newGroup.Id + $group.Id | Should -Be $newGroup.Id + $group.DisplayName | Should -Be $testName - It "should successfully add group to the Group" { - Add-EntraGroupMember -ObjectId $groupId -RefObjectId $memberId - $result = Get-EntraGroupMember -ObjectId $servicePrincipal - $result.Id | Should -Contain $memberId + Add-EntraGroupMember -ObjectId $group.Id -RefObjectId $user.Id + $result = Get-EntraGroupMember -ObjectId $group.Id + $result.Id | Should -Contain $user.Id } - # It "should throw an exception if a nonexistent object ID parameter is specified" { - # $Id = (New-Guid).Guid - # Get-EntraGroupMember -ObjectId $Id -ErrorAction Stop - # $Error[0] | Should -match "Resource '([^']+)' does not exist" - # } AfterAll { - Remove-EntraGroupMember -ObjectId $groupId -MemberId $memberId + Remove-EntraGroupMember -ObjectId $newGroup.Id -MemberId $newUser.Id + Remove-EntraUser -ObjectId $newUser.Id + Remove-EntraGroup -ObjectId $newGroup.Id } } } diff --git a/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 b/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 index f7a3425ed1..54574437c5 100644 --- a/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 +++ b/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 @@ -7,7 +7,7 @@ Describe "The Get-EntraApplication command executing unmocked" { $appId = $env:TEST_APPID $tenantId = $env:TEST_TENANTID $cert = $env:CERTIFICATETHUMBPRINT - Connect-MgGraph -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert $thisTestInstanceId = New-Guid | select -expandproperty guid $testAppName = 'SimpleTestAppRead' + $thisTestInstanceId From a8b62bf71c8605c4357b9299959d0ee387de494d Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Thu, 2 May 2024 10:22:27 +0530 Subject: [PATCH 4/9] added integration test for ADD-EntraGroupOwner --- .../Integration/Add-EntraGroupOwner.Tests.ps1 | 45 +++++++++++++++++++ test/module/Entra/Integration/setenv.ps1 | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 diff --git a/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 new file mode 100644 index 0000000000..44b5722d40 --- /dev/null +++ b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 @@ -0,0 +1,45 @@ +Describe "The Add-EntraGroupOwner command executing unmocked" { + + Context "When getting user and group" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $testName = 'SimpleTest1' + $thisTestInstanceId + + #create test user + $PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile + $PasswordProfile.Password = "Pass@1234" + $global:newUser = New-EntraUser -AccountEnabled $true -DisplayName $testName -PasswordProfile $PasswordProfile -MailNickName $testName -UserPrincipalName "SimpleTestUser1@M365x99297270.OnMicrosoft.com" + + #create test group + $global:newGroup = New-EntraGroup -DisplayName $testName -MailEnabled $false -SecurityEnabled $true -MailNickName $testName + } + + It "should successfully Adds an owner to a group" { + + $group = Get-EntraGroup -ObjectId $newGroup.Id + $group.Id | Should -Be $newGroup.Id + $group.DisplayName | Should -Be $testName + + $user = Get-EntraUser -ObjectId $newUser.Id + $user.Id | Should -Be $newUser.Id + $user.DisplayName | Should -Be $testName + + Add-EntraGroupOwner -ObjectId $group.Id -RefObjectId $user.Id + $result = Get-EntraGroupOwner -ObjectId $group.Id + $result.Id | Should -Contain $user.Id + } + + AfterAll { + Remove-EntraGroupOwner -ObjectId $newGroup.Id -OwnerId $newUser.Id + Remove-EntraUser -ObjectId $newUser.Id + Remove-EntraGroup -ObjectId $newGroup.Id + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Integration/setenv.ps1 b/test/module/Entra/Integration/setenv.ps1 index 819497c12e..4b38ce162d 100644 --- a/test/module/Entra/Integration/setenv.ps1 +++ b/test/module/Entra/Integration/setenv.ps1 @@ -1,3 +1,3 @@ $env:TEST_APPID = "8886ad7b-1795-4542-9808-c85859d97f23" $env:TEST_TENANTID = "d5aec55f-2d12-4442-8d2f-ccca95d4390e" -$env:CERTIFICATETHUMBPRINT = "714CCF133715A7987BADA4E766FB3E9A1B3D8A6F" \ No newline at end of file +$env:CERTIFICATETHUMBPRINT = "F8813914053FBFB5D84F1EFA9EDB3205621C1126" \ No newline at end of file From 93250bbdf6f45bbd4d19a909af1eb8eb0c6084a0 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Thu, 2 May 2024 11:45:57 +0530 Subject: [PATCH 5/9] updated --- test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 index 44b5722d40..1c2966b28a 100644 --- a/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 +++ b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 @@ -10,12 +10,12 @@ Describe "The Add-EntraGroupOwner command executing unmocked" { Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert $thisTestInstanceId = New-Guid | select -expandproperty guid - $testName = 'SimpleTest1' + $thisTestInstanceId + $testName = 'SimpleTests' + $thisTestInstanceId #create test user $PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile $PasswordProfile.Password = "Pass@1234" - $global:newUser = New-EntraUser -AccountEnabled $true -DisplayName $testName -PasswordProfile $PasswordProfile -MailNickName $testName -UserPrincipalName "SimpleTestUser1@M365x99297270.OnMicrosoft.com" + $global:newUser = New-EntraUser -AccountEnabled $true -DisplayName $testName -PasswordProfile $PasswordProfile -MailNickName $testName -UserPrincipalName "SimpleTestUsers@M365x99297270.OnMicrosoft.com" #create test group $global:newGroup = New-EntraGroup -DisplayName $testName -MailEnabled $false -SecurityEnabled $true -MailNickName $testName From 2d247a2292dcade79f941872cba631d4819120f6 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Thu, 2 May 2024 13:27:30 +0530 Subject: [PATCH 6/9] updated --- .../Integration/Add-EntraGroupOwner.Tests.ps1 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 index 1c2966b28a..892e5b9f50 100644 --- a/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 +++ b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 @@ -11,11 +11,17 @@ Describe "The Add-EntraGroupOwner command executing unmocked" { $thisTestInstanceId = New-Guid | select -expandproperty guid $testName = 'SimpleTests' + $thisTestInstanceId + $testName1 = 'SimpleTests1' + $thisTestInstanceId #create test user $PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile $PasswordProfile.Password = "Pass@1234" - $global:newUser = New-EntraUser -AccountEnabled $true -DisplayName $testName -PasswordProfile $PasswordProfile -MailNickName $testName -UserPrincipalName "SimpleTestUsers@M365x99297270.OnMicrosoft.com" + $global:newUser = New-EntraUser -AccountEnabled $true -DisplayName $testName -PasswordProfile $PasswordProfile -MailNickName $testName -UserPrincipalName $testName"@M365x99297270.OnMicrosoft.com" + + #create test user + $PasswordProfile1 = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile + $PasswordProfile1.Password = "Pass@1234" + $global:newUser1 = New-EntraUser -AccountEnabled $true -DisplayName $testName1 -PasswordProfile $PasswordProfile1 -MailNickName $testName1 -UserPrincipalName $testName1"@M365x99297270.OnMicrosoft.com" #create test group $global:newGroup = New-EntraGroup -DisplayName $testName -MailEnabled $false -SecurityEnabled $true -MailNickName $testName @@ -31,15 +37,26 @@ Describe "The Add-EntraGroupOwner command executing unmocked" { $user.Id | Should -Be $newUser.Id $user.DisplayName | Should -Be $testName + $user1 = Get-EntraUser -ObjectId $newUser1.Id + $user1.Id | Should -Be $newUser1.Id + $user1.DisplayName | Should -Be $testName1 + Add-EntraGroupOwner -ObjectId $group.Id -RefObjectId $user.Id $result = Get-EntraGroupOwner -ObjectId $group.Id $result.Id | Should -Contain $user.Id + + Add-EntraGroupOwner -ObjectId $group.Id -RefObjectId $user1.Id + $result1 = Get-EntraGroupOwner -ObjectId $group.Id + $result1.Id | Should -Contain $user1.Id } AfterAll { Remove-EntraGroupOwner -ObjectId $newGroup.Id -OwnerId $newUser.Id Remove-EntraUser -ObjectId $newUser.Id Remove-EntraGroup -ObjectId $newGroup.Id + Remove-EntraUser -ObjectId $newUser1.Id + + } } } \ No newline at end of file From 329460371f8efa21a44b8de53aba1dea3f535e73 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Fri, 3 May 2024 15:52:27 +0530 Subject: [PATCH 7/9] Added Integration TC For Add-EntraServicePrincipalOwner --- .../Add-EntraServicePrincipalOwner.Tests.ps1 | 54 +++++++++++++++++++ test/module/Entra/Integration/setenv.ps1 | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 diff --git a/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 b/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 new file mode 100644 index 0000000000..4ae75337c5 --- /dev/null +++ b/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 @@ -0,0 +1,54 @@ +Describe "The Add-EntraServicePrincipalOwner command executing unmocked" { + + Context "When getting ServicePrincipal and User" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-MgGraph -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $testName1 = 'DemoTests' + $thisTestInstanceId + $testname2 = 'appTests' + $thisTestInstanceId + + #Create Teste Application + $global:newApplication = New-EntraApplication -DisplayName $testname2 + + #create ServicePrincipal test user + $global:newServicePrincipal = New-EntraServicePrincipal -AccountEnabled $true -AlternativeNames "Demo" -DisplayName $testname2 -AppId $newApplication.AppId + + #create test user + $PasswordProfile1 = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile + $PasswordProfile1.Password = "Pass@1234" + $global:newUser1 = New-EntraUser -AccountEnabled $true -DisplayName $testName1 -PasswordProfile $PasswordProfile1 -MailNickName $testName1 -UserPrincipalName $testName1"@M365x99297270.OnMicrosoft.com" + + } + + It "should successfully Adds an owner to a service principal." { + + $Application = Get-EntraApplication -ObjectId $newApplication.Id + $Application.Id | Should -Be $newApplication.Id + $Application.DisplayName | Should -Be $testName2 + + $ServicePrincipal = Get-EntraServicePrincipal -ObjectId $newServicePrincipal.Id + $ServicePrincipal.Id | Should -Be $newServicePrincipal.Id + $ServicePrincipal.DisplayName | Should -Be $testName2 + + $user1 = Get-EntraUser -ObjectId $newUser1.Id + $user1.Id | Should -Be $newUser1.Id + $user1.DisplayName | Should -Be $testName1 + + Add-EntraServicePrincipalOwner -ObjectId $newServicePrincipal.Id -RefObjectId $newUser1.Id + $result = Get-EntraServicePrincipalOwner -ObjectId $newServicePrincipal.Id + $result.Id | Should -Contain $newUser1.Id + } + + AfterAll { + Remove-EntraServicePrincipalOwner -ObjectId $newServicePrincipal.Id -OwnerId $newUser1.Id + Remove-EntraUser -ObjectId $newUser1.Id + Remove-EntraApplication -ObjectId $newApplication.Id + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Integration/setenv.ps1 b/test/module/Entra/Integration/setenv.ps1 index 4b38ce162d..80c8a6e7ff 100644 --- a/test/module/Entra/Integration/setenv.ps1 +++ b/test/module/Entra/Integration/setenv.ps1 @@ -1,3 +1,3 @@ $env:TEST_APPID = "8886ad7b-1795-4542-9808-c85859d97f23" $env:TEST_TENANTID = "d5aec55f-2d12-4442-8d2f-ccca95d4390e" -$env:CERTIFICATETHUMBPRINT = "F8813914053FBFB5D84F1EFA9EDB3205621C1126" \ No newline at end of file +$env:CERTIFICATETHUMBPRINT = "4000D12C2AB68245A576C0BF167A3C15805F3D5C" \ No newline at end of file From 728d588a9430859fe17ef8746b0da6ade62c4f76 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Mon, 6 May 2024 14:14:53 +0530 Subject: [PATCH 8/9] updated --- .../Integration/Add-EntraGroupOwner.Tests.ps1 | 40 ++++++++++--------- .../Add-EntraServicePrincipalOwner.Tests.ps1 | 25 ++++++++---- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 index 892e5b9f50..6b5dd71a70 100644 --- a/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 +++ b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 @@ -7,7 +7,7 @@ Describe "The Add-EntraGroupOwner command executing unmocked" { $appId = $env:TEST_APPID $tenantId = $env:TEST_TENANTID $cert = $env:CERTIFICATETHUMBPRINT - Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + Connect-MgGraph -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert $thisTestInstanceId = New-Guid | select -expandproperty guid $testName = 'SimpleTests' + $thisTestInstanceId @@ -27,36 +27,40 @@ Describe "The Add-EntraGroupOwner command executing unmocked" { $global:newGroup = New-EntraGroup -DisplayName $testName -MailEnabled $false -SecurityEnabled $true -MailNickName $testName } - It "should successfully Adds an owner to a group" { + It "should update the proprties of user and group" { + $updatedDisplayName = "SimpleTestsUpdated" + Set-EntraGroup -ObjectId $newGroup.Id -DisplayName $updatedDisplayName - $group = Get-EntraGroup -ObjectId $newGroup.Id - $group.Id | Should -Be $newGroup.Id - $group.DisplayName | Should -Be $testName + $result = Get-EntraGroup -ObjectId $newGroup.Id + $result.Id | Should -Contain $newGroup.Id + $result.DisplayName | Should -Contain $updatedDisplayName - $user = Get-EntraUser -ObjectId $newUser.Id - $user.Id | Should -Be $newUser.Id - $user.DisplayName | Should -Be $testName + $updatedDisplayNameInCreatedUser = 'SimpleTests1AnotherTestUser' + Set-EntraUser -ObjectId $newUser.Id -Displayname $updatedDisplayNameInCreatedUser + + $updatedUser = Get-EntraUser -ObjectId $newUser.Id + $updatedUser.Id | Should -Be $newUser.Id + $updatedUser.DisplayName | Should -Be $updatedDisplayNameInCreatedUser $user1 = Get-EntraUser -ObjectId $newUser1.Id $user1.Id | Should -Be $newUser1.Id $user1.DisplayName | Should -Be $testName1 + } + It "Should successfully Adds an owner to a group" { + Add-EntraGroupOwner -ObjectId $newGroup.Id -RefObjectId $newUser.Id + $result = Get-EntraGroupOwner -ObjectId $newGroup.Id + $result.Id | Should -Contain $newUser.Id - Add-EntraGroupOwner -ObjectId $group.Id -RefObjectId $user.Id - $result = Get-EntraGroupOwner -ObjectId $group.Id - $result.Id | Should -Contain $user.Id - - Add-EntraGroupOwner -ObjectId $group.Id -RefObjectId $user1.Id - $result1 = Get-EntraGroupOwner -ObjectId $group.Id - $result1.Id | Should -Contain $user1.Id + Add-EntraGroupOwner -ObjectId $newGroup.Id -RefObjectId $newUser1.Id + $result1 = Get-EntraGroupOwner -ObjectId $newGroup.Id + $result1.Id | Should -Contain $newUser1.Id } AfterAll { Remove-EntraGroupOwner -ObjectId $newGroup.Id -OwnerId $newUser.Id Remove-EntraUser -ObjectId $newUser.Id Remove-EntraGroup -ObjectId $newGroup.Id - Remove-EntraUser -ObjectId $newUser1.Id - - + Remove-EntraUser -ObjectId $newUser1.Id } } } \ No newline at end of file diff --git a/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 b/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 index 4ae75337c5..1db904beac 100644 --- a/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 +++ b/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 @@ -26,20 +26,31 @@ Describe "The Add-EntraServicePrincipalOwner command executing unmocked" { } - It "should successfully Adds an owner to a service principal." { + It "should update the properties of Application , ServicePrincipal and User" { + + $updatedDisplayNameforappUser = 'appTetsUpdatedUser' + Set-EntraApplication -ObjectId $newApplication.Id -Displayname $updatedDisplayNameforappUser $Application = Get-EntraApplication -ObjectId $newApplication.Id $Application.Id | Should -Be $newApplication.Id - $Application.DisplayName | Should -Be $testName2 + $Application.DisplayName | Should -Be $updatedDisplayNameforappUser + + Set-EntraServicePrincipal -ObjectId $newServicePrincipal.Id -Displayname $updatedDisplayNameforappUser + $ServicePrincipal = Get-EntraServicePrincipal -ObjectId $newServicePrincipal.Id $ServicePrincipal.Id | Should -Be $newServicePrincipal.Id - $ServicePrincipal.DisplayName | Should -Be $testName2 + $ServicePrincipal.DisplayName | Should -Be $updatedDisplayNameforappUser - $user1 = Get-EntraUser -ObjectId $newUser1.Id - $user1.Id | Should -Be $newUser1.Id - $user1.DisplayName | Should -Be $testName1 - + $updatedDisplayNameInCreatedUser = 'DemoTestsUpdatedUser' + Set-EntraUser -ObjectId $newUser1.Id -Displayname $updatedDisplayNameInCreatedUser + + $updatedUser = Get-EntraUser -ObjectId $newUser1.Id + $updatedUser.Id | Should -Be $newUser1.Id + $updatedUser.DisplayName | Should -Be $updatedDisplayNameInCreatedUser + } + + It "should successfully Adds an owner to a service principal." { Add-EntraServicePrincipalOwner -ObjectId $newServicePrincipal.Id -RefObjectId $newUser1.Id $result = Get-EntraServicePrincipalOwner -ObjectId $newServicePrincipal.Id $result.Id | Should -Contain $newUser1.Id From 9b7fa114a6e940b5ab259fd467be60c1701135d7 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Mon, 6 May 2024 14:16:38 +0530 Subject: [PATCH 9/9] updated --- .../Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 b/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 index 1db904beac..160a2f20bd 100644 --- a/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 +++ b/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 @@ -27,7 +27,6 @@ Describe "The Add-EntraServicePrincipalOwner command executing unmocked" { } It "should update the properties of Application , ServicePrincipal and User" { - $updatedDisplayNameforappUser = 'appTetsUpdatedUser' Set-EntraApplication -ObjectId $newApplication.Id -Displayname $updatedDisplayNameforappUser @@ -35,7 +34,6 @@ Describe "The Add-EntraServicePrincipalOwner command executing unmocked" { $Application.Id | Should -Be $newApplication.Id $Application.DisplayName | Should -Be $updatedDisplayNameforappUser - Set-EntraServicePrincipal -ObjectId $newServicePrincipal.Id -Displayname $updatedDisplayNameforappUser $ServicePrincipal = Get-EntraServicePrincipal -ObjectId $newServicePrincipal.Id