From afde25b4adeafdafee462fbae114d08142b4f918 Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Tue, 30 Apr 2024 11:06:06 +0530 Subject: [PATCH 01/10] added integration test --- .../Entra/Integration/EntraGroup.Tests.ps1 | 35 ++++++++++++++ .../Integration/EntraMSApplication.Tests.ps1 | 38 +++++++++++++++ .../Entra/Integration/EntraMSGroup.Tests.ps1 | 36 +++++++++++++++ .../EntraMSGroupLifecyclePolicy.Tests.ps1 | 46 +++++++++++++++++++ .../EntraMSLifecyclePolicyGroup.Tests.ps1 | 40 ++++++++++++++++ test/module/Entra/Integration/env.ps1 | 3 ++ 6 files changed, 198 insertions(+) create mode 100644 test/module/Entra/Integration/EntraGroup.Tests.ps1 create mode 100644 test/module/Entra/Integration/EntraMSApplication.Tests.ps1 create mode 100644 test/module/Entra/Integration/EntraMSGroup.Tests.ps1 create mode 100644 test/module/Entra/Integration/EntraMSGroupLifecyclePolicy.Tests.ps1 create mode 100644 test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 create mode 100644 test/module/Entra/Integration/env.ps1 diff --git a/test/module/Entra/Integration/EntraGroup.Tests.ps1 b/test/module/Entra/Integration/EntraGroup.Tests.ps1 new file mode 100644 index 000000000..eec4f8ef6 --- /dev/null +++ b/test/module/Entra/Integration/EntraGroup.Tests.ps1 @@ -0,0 +1,35 @@ +Describe "The EntraGroup command executing unmocked" { + + Context "When getting user and group" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\env.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-Object -expandproperty guid + $testName = 'Demo Name' + $thisTestInstanceId + + #create test group + $global:newGroup = New-EntraGroup -DisplayName $testName -MailEnabled $false -SecurityEnabled $true -MailNickName "NotSet" + } + + It "should successfully get a specific group by using an Id" { + $group = Get-EntraGroup -ObjectId $newGroup.Id + $group.Id | Should -Be $newGroup.Id + $group.DisplayName | Should -Be $testName + } + + It "should successfully update a group display name" { + Set-EntraGroup -ObjectId $newGroup.Id -DisplayName "Demo Name 2" + $result = Get-EntraGroup -ObjectId $newGroup.Id + $result.Id | Should -Contain $newGroup.Id + } + + AfterAll { + Remove-EntraGroup -ObjectId $newGroup.Id + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 b/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 new file mode 100644 index 000000000..81b1446e2 --- /dev/null +++ b/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 @@ -0,0 +1,38 @@ +Describe "The EntraMSApplication command executing unmocked" { + + Context "When getting application" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\env.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-Object -expandproperty guid + $testApplicationName = 'Demo Name' + $thisTestInstanceId + + # Create an application + $global:newMSApplication = New-EntraMSApplication -DisplayName $testApplicationName + } + + It "should successfully get an application by display name" { + $application = Get-EntraMSApplication -Filter "DisplayName eq '$($newMSApplication.DisplayName)'" + $application.ObjectId | Should -Be $newMSApplication.Id + $application.AppId | Should -Be $newMSApplication.AppId + $application.DisplayName | Should -Be $newMSApplication.DisplayName + } + + It "should successfully update a application display name" { + Set-EntraMSApplication -ObjectId $newMSApplication.ObjectId -DisplayName "Update Application Name" + $result = Get-EntraMSApplication -Filter "AppId eq '$($newMSApplication.AppId)'" + $result.ObjectId | Should -Be $newMSApplication.Id + $result.AppId | Should -Be $newMSApplication.AppId + $result.DisplayName | Should -Be "Update Application Name" + } + + AfterAll { + Remove-EntraMSApplication -ObjectId $newMSApplication.ObjectId + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 b/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 new file mode 100644 index 000000000..c5a8b4110 --- /dev/null +++ b/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 @@ -0,0 +1,36 @@ +Describe "The EntraMSGroup command executing unmocked" { + + Context "When getting user and group" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\env.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-Object -expandproperty guid + $testName = 'Demo Help Group' + $thisTestInstanceId + $testNickname = "helpDeskAdminGroup" + + #Create a group with Description parameter. + $global:newMSGroup = New-EntraMSGroup -DisplayName $testName -MailEnabled $False -MailNickname $testNickname -SecurityEnabled $True + } + + It "should successfully get a specific group by using an Id" { + $group = Get-EntraMSGroup -Id $newMSGroup.Id + $group.ObjectId | Should -Be $newMSGroup.Id + $group.DisplayName | Should -Be $testName + } + + It "should successfully update a group display name" { + Set-EntraMSGroup -Id $newMSGroup.Id -DisplayName "Update Help Group Name" + $result = Get-EntraGroup -ObjectId $newMSGroup.Id + $result.Id | Should -Contain $newMSGroup.Id + } + + AfterAll { + Remove-EntraMSGroup -Id $newMSGroup.Id + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/Integration/EntraMSGroupLifecyclePolicy.Tests.ps1 new file mode 100644 index 000000000..f59df6c6a --- /dev/null +++ b/test/module/Entra/Integration/EntraMSGroupLifecyclePolicy.Tests.ps1 @@ -0,0 +1,46 @@ +Describe "The EntraMSGroupLifecyclePolicy command executing unmocked" { + + Context "When getting groupLifecyclePolicy" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\env.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $global:testGroupPolicy = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.en" + } + + It "should successfully retrieve properties of an groupLifecyclePolicy" { + $groupLifecyclePolicy = Get-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id + + # Ensure that the retrieved group lifecycle policy matches the expected one + $groupLifecyclePolicy.Id | Should -Be $testGroupPolicy.Id + $groupLifecyclePolicy.GroupLifetimeInDays | Should -Be 99 + $groupLifecyclePolicy.ManagedGroupTypes | Should -Contain "Selected" + $groupLifecyclePolicy.AlternateNotificationEmails | Should -Contain "example@contoso.en" + } + + It "should successfully update group lifecycle policy" { + $updatedGroupLifecyclePolicy = Set-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.en" -ManagedGroupTypes "All" + + # Ensure that the retrieved group lifecycle policy matches the expected one + $updatedGroupLifecyclePolicy.Id | Should -Be $testGroupPolicy.Id + $updatedGroupLifecyclePolicy.GroupLifetimeInDays | Should -Be 200 + $updatedGroupLifecyclePolicy.ManagedGroupTypes | Should -Contain "All" + $updatedGroupLifecyclePolicy.AlternateNotificationEmails | Should -Contain "admingroup@contoso.en" + } + + # It "should throw an exception if a nonexistent ID parameter is specified" { + # $Id = (New-Guid).Guid + # Get-EntraMSGroupLifecyclePolicy -Id $Id -ErrorAction ignore + # $errorMessage = $Error[0].Exception.Message + # $errorMessage | Should -match "([\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12})" + # } + + AfterAll { + Remove-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id | Out-Null + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 new file mode 100644 index 000000000..cc879f0c3 --- /dev/null +++ b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 @@ -0,0 +1,40 @@ +Describe "The EntraMSLifecyclePolicyGroup command executing unmocked" { + + Context "When getting LifecyclePolicyGroup" { + BeforeAll { + $testReportPath = Join-Path $PSScriptRoot "\env.ps1" + Import-Module -Name $testReportPath + + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + # Create a group with Description parameter. + $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid + $testName = 'Demo Help Group' + $thisTestInstanceId + $testNickname = "helpDeskAdminGroup" + $global:newMSGroup = New-EntraMSGroup -DisplayName $testName -MailEnabled $false -MailNickname $testNickname -SecurityEnabled $true + Write-host $newMSGroup + + $global:testGroupPolicy = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.un" + Write-host $testGroupPolicy + + $global:testLifePolicyGroup = Add-EntraMSLifecyclePolicyGroup -Id $testGroupPolicy.Id -GroupId $newMSGroup.Id + Write-host $testLifePolicyGroup + } + + It "should successfully retrieve details of a LifecyclePolicyGroup" { + $lifecyclePolicyGroup = Get-EntraMSLifecyclePolicyGroup -Id $testLifePolicyGroup.Id + + # Ensure that the retrieved group lifecycle policy matches the expected one + $lifecyclePolicyGroup.Id | Should -Be $testLifePolicyGroup.Id + Write-Host $lifecyclePolicyGroup + } + + AfterAll { + Remove-EntraMSLifecyclePolicyGroup -Id $testLifePolicyGroup.Id -GroupId $newMSGroup.Id | Out-Null + } + } +} diff --git a/test/module/Entra/Integration/env.ps1 b/test/module/Entra/Integration/env.ps1 new file mode 100644 index 000000000..627531ad0 --- /dev/null +++ b/test/module/Entra/Integration/env.ps1 @@ -0,0 +1,3 @@ +$env:TEST_APPID = "8886ad7b-1795-4542-9808-c85859d97f23" +$env:TEST_TENANTID = "d5aec55f-2d12-4442-8d2f-ccca95d4390e" +$env:CERTIFICATETHUMBPRINT = "6CAEA8F6CEF8C5F8642F1F9AABE0237DB3D0C424" \ No newline at end of file From 20ca4e7b1fb2f8590678876fb203d5a0513d6ac2 Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Tue, 30 Apr 2024 17:39:14 +0530 Subject: [PATCH 02/10] updated integration test --- .../Entra/Integration/EntraMSGroup.Tests.ps1 | 2 +- .../EntraMSLifecyclePolicyGroup.Tests.ps1 | 52 ++++++++++++++----- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 b/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 index c5a8b4110..9274ea648 100644 --- a/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 @@ -30,7 +30,7 @@ Describe "The EntraMSGroup command executing unmocked" { } AfterAll { - Remove-EntraMSGroup -Id $newMSGroup.Id + Remove-EntraMSGroup -Id $newMSGroup.Id | Out-Null } } } \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 index cc879f0c3..154e6763b 100644 --- a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 @@ -9,32 +9,58 @@ Describe "The EntraMSLifecyclePolicyGroup command executing unmocked" { $tenantId = $env:TEST_TENANTID $cert = $env:CERTIFICATETHUMBPRINT + # Validate required environment variables + if (-not $appId -or -not $tenantId -or -not $cert) { + throw "Required environment variables are not set." + } + + # Connect to Entra service Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert # Create a group with Description parameter. - $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid + $thisTestInstanceId = New-Guid | Select-Object -ExpandProperty Guid $testName = 'Demo Help Group' + $thisTestInstanceId - $testNickname = "helpDeskAdminGroup" - $global:newMSGroup = New-EntraMSGroup -DisplayName $testName -MailEnabled $false -MailNickname $testNickname -SecurityEnabled $true - Write-host $newMSGroup + $testNickname = "testhelpDeskAdminGroup" + $global:newMSGroup = New-EntraMSGroup -DisplayName $testName -MailEnabled $false -MailNickname $testNickname -SecurityEnabled $true -GroupTypes "unified" + Write-Host "Group $($newMSGroup.Id)" + # Validate group creation + if (-not $newMSGroup) { + throw "Failed to create a new group." + } + Start-Sleep 5 + # Create a lifecycle policy $global:testGroupPolicy = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.un" - Write-host $testGroupPolicy - - $global:testLifePolicyGroup = Add-EntraMSLifecyclePolicyGroup -Id $testGroupPolicy.Id -GroupId $newMSGroup.Id - Write-host $testLifePolicyGroup + Write-Host "Policy $($testGroupPolicy.Id)" + # Validate policy creation + if (-not $testGroupPolicy) { + throw "Failed to create a new group lifecycle policy." + } + Start-Sleep 5 } It "should successfully retrieve details of a LifecyclePolicyGroup" { - $lifecyclePolicyGroup = Get-EntraMSLifecyclePolicyGroup -Id $testLifePolicyGroup.Id - - # Ensure that the retrieved group lifecycle policy matches the expected one - $lifecyclePolicyGroup.Id | Should -Be $testLifePolicyGroup.Id + # Associate the group with the lifecycle policy + $testLifePolicyGroup = Add-EntraMSLifecyclePolicyGroup -Id $testGroupPolicy.Id -GroupId $newMSGroup.Id + Write-Host "Lifecycle Policy Group $($testLifePolicyGroup.Id)" + $testLifePolicyGroup.ObjectId | Should -BeNullOrEmpty + + # Get lifecycle policy group using group id + $lifecyclePolicyGroup = Get-EntraMSLifecyclePolicyGroup -Id $newMSGroup.Id + $lifecyclePolicyGroup.ObjectId | Should -Be $testGroupPolicy.Id Write-Host $lifecyclePolicyGroup } AfterAll { - Remove-EntraMSLifecyclePolicyGroup -Id $testLifePolicyGroup.Id -GroupId $newMSGroup.Id | Out-Null + if ($newMSGroup) { + Remove-EntraMSGroup -Id $newMSGroup.Id | Out-Null + } + if ($testGroupPolicy) { + Remove-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id | Out-Null + } + if ($testLifePolicyGroup) { + Remove-EntraMSLifecyclePolicyGroup -Id $testLifePolicyGroup.Id -GroupId $newMSGroup.Id | Out-Null + } } } } From 271907ce7d7ee7595fc90f07d97495d5b740d931 Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Tue, 30 Apr 2024 18:29:37 +0530 Subject: [PATCH 03/10] updated 3 test and added 1 test --- .../Entra/Integration/EntraGroup.Tests.ps1 | 2 +- .../Integration/EntraMSApplication.Tests.ps1 | 2 +- ...raMSApplicationExtensionProperty.Tests.ps1 | 50 +++++++++++++++++++ .../EntraMSLifecyclePolicyGroup.Tests.ps1 | 13 +++-- 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 diff --git a/test/module/Entra/Integration/EntraGroup.Tests.ps1 b/test/module/Entra/Integration/EntraGroup.Tests.ps1 index eec4f8ef6..70cfae06f 100644 --- a/test/module/Entra/Integration/EntraGroup.Tests.ps1 +++ b/test/module/Entra/Integration/EntraGroup.Tests.ps1 @@ -29,7 +29,7 @@ Describe "The EntraGroup command executing unmocked" { } AfterAll { - Remove-EntraGroup -ObjectId $newGroup.Id + Remove-EntraGroup -ObjectId $newGroup.Id | Out-Null } } } \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 b/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 index 81b1446e2..1d86abec8 100644 --- a/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 @@ -32,7 +32,7 @@ Describe "The EntraMSApplication command executing unmocked" { } AfterAll { - Remove-EntraMSApplication -ObjectId $newMSApplication.ObjectId + Remove-EntraMSApplication -ObjectId $newMSApplication.ObjectId | Out-Null } } } \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 b/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 new file mode 100644 index 000000000..17e1d53b6 --- /dev/null +++ b/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 @@ -0,0 +1,50 @@ +Describe "The EntraMSApplicationExtensionProperty command executing unmocked" { + + Context "When getting ApplicationExtensionProperty" { + BeforeAll { + $testReportPath = Join-Path $PSScriptRoot "\env.ps1" + Import-Module -Name $testReportPath + + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + + # Validate required environment variables + if (-not $appId -or -not $tenantId -or -not $cert) { + throw "Required environment variables are not set." + } + + # Connect to Entra service + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + # Create an application + $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid + $testApplicationName = 'Test Demo Name' + $thisTestInstanceId + $global:newMSApplication = New-EntraMSApplication -DisplayName $testApplicationName + Write-Host "Id :$($newMSApplication.Id)" + Write-Host "AppId :$($newMSApplication.AppId)" + + # Create an extension property + $global:newMSApplicationExtensionProperty = New-EntraMSApplicationExtensionProperty -ObjectId $newMSApplication.Id -DataType "string" -Name "NewAttribute" -TargetObjects "Application" + Write-Host "ObjectId :$($newMSApplicationExtensionProperty.ObjectId)" + Write-Host "Name :$($newMSApplicationExtensionProperty.Name)" + } + + It "should successfully get application extension property" { + # Get application extension property using object id + $applicationExtensionProperty = Get-EntraMSApplicationExtensionProperty -ObjectId $newMSApplicationExtensionProperty.ObjectId + $applicationExtensionProperty.ObjectId | Should -Be $newMSApplicationExtensionProperty.ObjectId + $applicationExtensionProperty.Name | Should -Be $newMSApplicationExtensionProperty.Name + Write-Host $applicationExtensionProperty + } + + AfterAll { + if ($newMSGroup) { + Remove-EntraMSApplication -ObjectId $newMSApplication.ObjectId | Out-Null + } + if ($testGroupPolicy) { + # Remove-EntraMSApplicationExtensionProperty -ObjectId $newMSApplicationExtensionProperty.ObjectId -ExtensionPropertyId "344ed560-f8e7-410e-ab9f-c79df5c36" | Out-Null + } + } + } +} diff --git a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 index 154e6763b..fe2cbdf05 100644 --- a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 @@ -22,32 +22,35 @@ Describe "The EntraMSLifecyclePolicyGroup command executing unmocked" { $testName = 'Demo Help Group' + $thisTestInstanceId $testNickname = "testhelpDeskAdminGroup" $global:newMSGroup = New-EntraMSGroup -DisplayName $testName -MailEnabled $false -MailNickname $testNickname -SecurityEnabled $true -GroupTypes "unified" - Write-Host "Group $($newMSGroup.Id)" + Write-Host "Group Id:$($newMSGroup.Id)" # Validate group creation if (-not $newMSGroup) { throw "Failed to create a new group." } - Start-Sleep 5 + Start-Sleep -Seconds 10 # Create a lifecycle policy $global:testGroupPolicy = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.un" - Write-Host "Policy $($testGroupPolicy.Id)" + Write-Host "Policy Id:$($testGroupPolicy.Id)" # Validate policy creation if (-not $testGroupPolicy) { throw "Failed to create a new group lifecycle policy." } - Start-Sleep 5 + Start-Sleep -Seconds 10 } It "should successfully retrieve details of a LifecyclePolicyGroup" { # Associate the group with the lifecycle policy $testLifePolicyGroup = Add-EntraMSLifecyclePolicyGroup -Id $testGroupPolicy.Id -GroupId $newMSGroup.Id - Write-Host "Lifecycle Policy Group $($testLifePolicyGroup.Id)" + Write-Host "Lifecycle Policy Group Id:$($testLifePolicyGroup.Id)" $testLifePolicyGroup.ObjectId | Should -BeNullOrEmpty # Get lifecycle policy group using group id $lifecyclePolicyGroup = Get-EntraMSLifecyclePolicyGroup -Id $newMSGroup.Id $lifecyclePolicyGroup.ObjectId | Should -Be $testGroupPolicy.Id + $lifecyclePolicyGroup.GroupLifetimeInDays | Should -Be 99 + $lifecyclePolicyGroup.ManagedGroupTypes | Should -Contain "Selected" + $lifecyclePolicyGroup.AlternateNotificationEmails | Should -Contain "example@contoso.un" Write-Host $lifecyclePolicyGroup } From c49260ee08ac3a5db95404cc3b44a69ad4523697 Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Thu, 2 May 2024 18:20:22 +0530 Subject: [PATCH 04/10] integrated EntraMSGroup, EntraMSGroupLifecyclePolicy into EntraMSLifecyclePolicyGroup and EntraMSApplication into EntraMSApplicationExtensionProperty --- .../Integration/EntraMSApplication.Tests.ps1 | 38 --------- ...raMSApplicationExtensionProperty.Tests.ps1 | 36 +++++--- .../Entra/Integration/EntraMSGroup.Tests.ps1 | 36 -------- .../EntraMSGroupLifecyclePolicy.Tests.ps1 | 46 ---------- .../EntraMSLifecyclePolicyGroup.Tests.ps1 | 84 +++++++++++++------ 5 files changed, 84 insertions(+), 156 deletions(-) delete mode 100644 test/module/Entra/Integration/EntraMSApplication.Tests.ps1 delete mode 100644 test/module/Entra/Integration/EntraMSGroup.Tests.ps1 delete mode 100644 test/module/Entra/Integration/EntraMSGroupLifecyclePolicy.Tests.ps1 diff --git a/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 b/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 deleted file mode 100644 index 1d86abec8..000000000 --- a/test/module/Entra/Integration/EntraMSApplication.Tests.ps1 +++ /dev/null @@ -1,38 +0,0 @@ -Describe "The EntraMSApplication command executing unmocked" { - - Context "When getting application" { - BeforeAll { - $testReportPath = join-path $psscriptroot "\env.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-Object -expandproperty guid - $testApplicationName = 'Demo Name' + $thisTestInstanceId - - # Create an application - $global:newMSApplication = New-EntraMSApplication -DisplayName $testApplicationName - } - - It "should successfully get an application by display name" { - $application = Get-EntraMSApplication -Filter "DisplayName eq '$($newMSApplication.DisplayName)'" - $application.ObjectId | Should -Be $newMSApplication.Id - $application.AppId | Should -Be $newMSApplication.AppId - $application.DisplayName | Should -Be $newMSApplication.DisplayName - } - - It "should successfully update a application display name" { - Set-EntraMSApplication -ObjectId $newMSApplication.ObjectId -DisplayName "Update Application Name" - $result = Get-EntraMSApplication -Filter "AppId eq '$($newMSApplication.AppId)'" - $result.ObjectId | Should -Be $newMSApplication.Id - $result.AppId | Should -Be $newMSApplication.AppId - $result.DisplayName | Should -Be "Update Application Name" - } - - AfterAll { - Remove-EntraMSApplication -ObjectId $newMSApplication.ObjectId | Out-Null - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 b/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 index 17e1d53b6..46d2252e0 100644 --- a/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 @@ -21,29 +21,43 @@ Describe "The EntraMSApplicationExtensionProperty command executing unmocked" { $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid $testApplicationName = 'Test Demo Name' + $thisTestInstanceId $global:newMSApplication = New-EntraMSApplication -DisplayName $testApplicationName - Write-Host "Id :$($newMSApplication.Id)" - Write-Host "AppId :$($newMSApplication.AppId)" + } + + It "should successfully get an application by display name" { + $application = Get-EntraMSApplication -Filter "DisplayName eq '$($newMSApplication.DisplayName)'" + $application.ObjectId | Should -Be $newMSApplication.Id + $application.AppId | Should -Be $newMSApplication.AppId + $application.DisplayName | Should -Be $newMSApplication.DisplayName + } + + It "should successfully update a application display name" { + $updatedDisplayName = "Update Application Name" + Set-EntraMSApplication -ObjectId $newMSApplication.ObjectId -DisplayName $updatedDisplayName + $result = Get-EntraMSApplication -Filter "AppId eq '$($newMSApplication.AppId)'" + $result.ObjectId | Should -Be $newMSApplication.Id + $result.AppId | Should -Be $newMSApplication.AppId + $result.DisplayName | Should -Be "Update Application Name" + } + It "should successfully create application extension property" { # Create an extension property $global:newMSApplicationExtensionProperty = New-EntraMSApplicationExtensionProperty -ObjectId $newMSApplication.Id -DataType "string" -Name "NewAttribute" -TargetObjects "Application" - Write-Host "ObjectId :$($newMSApplicationExtensionProperty.ObjectId)" - Write-Host "Name :$($newMSApplicationExtensionProperty.Name)" } It "should successfully get application extension property" { # Get application extension property using object id - $applicationExtensionProperty = Get-EntraMSApplicationExtensionProperty -ObjectId $newMSApplicationExtensionProperty.ObjectId - $applicationExtensionProperty.ObjectId | Should -Be $newMSApplicationExtensionProperty.ObjectId + $applicationExtensionProperty = Get-EntraMSApplicationExtensionProperty -ObjectId $newMSApplication.Id + $applicationExtensionProperty.ObjectId | Should -Be $newMSApplicationExtensionProperty.Id $applicationExtensionProperty.Name | Should -Be $newMSApplicationExtensionProperty.Name - Write-Host $applicationExtensionProperty + } AfterAll { - if ($newMSGroup) { - Remove-EntraMSApplication -ObjectId $newMSApplication.ObjectId | Out-Null + if ($newMSApplicationExtensionProperty) { + Remove-EntraMSApplicationExtensionProperty -ObjectId $newMSApplication.Id -ExtensionPropertyId $newMSApplicationExtensionProperty.Id | Out-Null } - if ($testGroupPolicy) { - # Remove-EntraMSApplicationExtensionProperty -ObjectId $newMSApplicationExtensionProperty.ObjectId -ExtensionPropertyId "344ed560-f8e7-410e-ab9f-c79df5c36" | Out-Null + if ($newMSApplication) { + Remove-EntraMSApplication -ObjectId $newMSApplication.Id | Out-Null } } } diff --git a/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 b/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 deleted file mode 100644 index 9274ea648..000000000 --- a/test/module/Entra/Integration/EntraMSGroup.Tests.ps1 +++ /dev/null @@ -1,36 +0,0 @@ -Describe "The EntraMSGroup command executing unmocked" { - - Context "When getting user and group" { - BeforeAll { - $testReportPath = join-path $psscriptroot "\env.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-Object -expandproperty guid - $testName = 'Demo Help Group' + $thisTestInstanceId - $testNickname = "helpDeskAdminGroup" - - #Create a group with Description parameter. - $global:newMSGroup = New-EntraMSGroup -DisplayName $testName -MailEnabled $False -MailNickname $testNickname -SecurityEnabled $True - } - - It "should successfully get a specific group by using an Id" { - $group = Get-EntraMSGroup -Id $newMSGroup.Id - $group.ObjectId | Should -Be $newMSGroup.Id - $group.DisplayName | Should -Be $testName - } - - It "should successfully update a group display name" { - Set-EntraMSGroup -Id $newMSGroup.Id -DisplayName "Update Help Group Name" - $result = Get-EntraGroup -ObjectId $newMSGroup.Id - $result.Id | Should -Contain $newMSGroup.Id - } - - AfterAll { - Remove-EntraMSGroup -Id $newMSGroup.Id | Out-Null - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/Integration/EntraMSGroupLifecyclePolicy.Tests.ps1 deleted file mode 100644 index f59df6c6a..000000000 --- a/test/module/Entra/Integration/EntraMSGroupLifecyclePolicy.Tests.ps1 +++ /dev/null @@ -1,46 +0,0 @@ -Describe "The EntraMSGroupLifecyclePolicy command executing unmocked" { - - Context "When getting groupLifecyclePolicy" { - BeforeAll { - $testReportPath = join-path $psscriptroot "\env.ps1" - Import-Module -Name $testReportPath - $appId = $env:TEST_APPID - $tenantId = $env:TEST_TENANTID - $cert = $env:CERTIFICATETHUMBPRINT - Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert - - $global:testGroupPolicy = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.en" - } - - It "should successfully retrieve properties of an groupLifecyclePolicy" { - $groupLifecyclePolicy = Get-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id - - # Ensure that the retrieved group lifecycle policy matches the expected one - $groupLifecyclePolicy.Id | Should -Be $testGroupPolicy.Id - $groupLifecyclePolicy.GroupLifetimeInDays | Should -Be 99 - $groupLifecyclePolicy.ManagedGroupTypes | Should -Contain "Selected" - $groupLifecyclePolicy.AlternateNotificationEmails | Should -Contain "example@contoso.en" - } - - It "should successfully update group lifecycle policy" { - $updatedGroupLifecyclePolicy = Set-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.en" -ManagedGroupTypes "All" - - # Ensure that the retrieved group lifecycle policy matches the expected one - $updatedGroupLifecyclePolicy.Id | Should -Be $testGroupPolicy.Id - $updatedGroupLifecyclePolicy.GroupLifetimeInDays | Should -Be 200 - $updatedGroupLifecyclePolicy.ManagedGroupTypes | Should -Contain "All" - $updatedGroupLifecyclePolicy.AlternateNotificationEmails | Should -Contain "admingroup@contoso.en" - } - - # It "should throw an exception if a nonexistent ID parameter is specified" { - # $Id = (New-Guid).Guid - # Get-EntraMSGroupLifecyclePolicy -Id $Id -ErrorAction ignore - # $errorMessage = $Error[0].Exception.Message - # $errorMessage | Should -match "([\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12})" - # } - - AfterAll { - Remove-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id | Out-Null - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 index fe2cbdf05..d597d873c 100644 --- a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 @@ -19,50 +19,84 @@ Describe "The EntraMSLifecyclePolicyGroup command executing unmocked" { # Create a group with Description parameter. $thisTestInstanceId = New-Guid | Select-Object -ExpandProperty Guid - $testName = 'Demo Help Group' + $thisTestInstanceId + $global:displayName = 'Demo Help Group' + $thisTestInstanceId $testNickname = "testhelpDeskAdminGroup" - $global:newMSGroup = New-EntraMSGroup -DisplayName $testName -MailEnabled $false -MailNickname $testNickname -SecurityEnabled $true -GroupTypes "unified" - Write-Host "Group Id:$($newMSGroup.Id)" - # Validate group creation - if (-not $newMSGroup) { - throw "Failed to create a new group." - } + $global:newMSGroup = New-EntraMSGroup -DisplayName $displayName -MailEnabled $false -MailNickname $testNickname -SecurityEnabled $true -GroupTypes "unified" Start-Sleep -Seconds 10 + } + + It "should successfully get a specific group by using an group Id" { + $group = Get-EntraMSGroup -Id $newMSGroup.Id + $group.ObjectId | Should -Be $newMSGroup.Id + $group.DisplayName | Should -Be $displayName + } + + It "should successfully update a group display name" { + $updatedDisplayName = "Update Help Group Name" + Set-EntraMSGroup -Id $newMSGroup.Id -DisplayName $updatedDisplayName + $result = Get-EntraGroup -ObjectId $newMSGroup.Id + $result.Id | Should -Contain $newMSGroup.Id + } + It "should successfully Create a lifecycle policy" { # Create a lifecycle policy $global:testGroupPolicy = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.un" - Write-Host "Policy Id:$($testGroupPolicy.Id)" - # Validate policy creation - if (-not $testGroupPolicy) { - throw "Failed to create a new group lifecycle policy." - } + } + + It "should successfully retrieve properties of an groupLifecyclePolicy" { + $groupLifecyclePolicy = Get-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id + + # Ensure that the retrieved group lifecycle policy matches the expected one + $groupLifecyclePolicy.Id | Should -Be $testGroupPolicy.Id + $groupLifecyclePolicy.GroupLifetimeInDays | Should -Be 99 + $groupLifecyclePolicy.ManagedGroupTypes | Should -Contain "Selected" + $groupLifecyclePolicy.AlternateNotificationEmails | Should -Contain "example@contoso.un" + } + + It "should successfully update groupLifecyclePolicy" { + $alternateNotificationEmails = "admingroup@contoso.en" + $global:updatedGroupLifecyclePolicy = Set-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id -GroupLifetimeInDays 200 -AlternateNotificationEmails $alternateNotificationEmails -ManagedGroupTypes "Selected" Start-Sleep -Seconds 10 + + # Ensure that the retrieved group lifecycle policy matches the expected one + $updatedGroupLifecyclePolicy.Id | Should -Be $testGroupPolicy.Id + $updatedGroupLifecyclePolicy.GroupLifetimeInDays | Should -Be 200 + $updatedGroupLifecyclePolicy.ManagedGroupTypes | Should -Contain "Selected" + $updatedGroupLifecyclePolicy.AlternateNotificationEmails | Should -Contain $alternateNotificationEmails } - It "should successfully retrieve details of a LifecyclePolicyGroup" { + # It "should throw an exception if a nonexistent ID parameter is specified" { + # $Id = (New-Guid).Guid + # Get-EntraMSGroupLifecyclePolicy -Id $Id -ErrorAction ignore + # $errorMessage = $Error[0].Exception.Message + # $errorMessage | Should -match "([\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12})" + # } + + It "should successfully associate the group with the lifecycle policy" { # Associate the group with the lifecycle policy $testLifePolicyGroup = Add-EntraMSLifecyclePolicyGroup -Id $testGroupPolicy.Id -GroupId $newMSGroup.Id - Write-Host "Lifecycle Policy Group Id:$($testLifePolicyGroup.Id)" $testLifePolicyGroup.ObjectId | Should -BeNullOrEmpty - + Start-Sleep -Seconds 10 + } + + It "should successfully retrieve details of a LifecyclePolicyGroup" { # Get lifecycle policy group using group id - $lifecyclePolicyGroup = Get-EntraMSLifecyclePolicyGroup -Id $newMSGroup.Id + $global:lifecyclePolicyGroup = Get-EntraMSLifecyclePolicyGroup -Id $newMSGroup.Id $lifecyclePolicyGroup.ObjectId | Should -Be $testGroupPolicy.Id - $lifecyclePolicyGroup.GroupLifetimeInDays | Should -Be 99 + $lifecyclePolicyGroup.GroupLifetimeInDays | Should -Be 200 $lifecyclePolicyGroup.ManagedGroupTypes | Should -Contain "Selected" - $lifecyclePolicyGroup.AlternateNotificationEmails | Should -Contain "example@contoso.un" - Write-Host $lifecyclePolicyGroup + $lifecyclePolicyGroup.AlternateNotificationEmails | Should -Contain $updatedGroupLifecyclePolicy.AlternateNotificationEmails } AfterAll { - if ($newMSGroup) { - Remove-EntraMSGroup -Id $newMSGroup.Id | Out-Null + if ($lifecyclePolicyGroup) { + Remove-EntraMSLifecyclePolicyGroup -Id $lifecyclePolicyGroup.Id -GroupId $newMSGroup.Id | Out-Null } - if ($testGroupPolicy) { - Remove-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id | Out-Null + if ($updatedGroupLifecyclePolicy) { + Remove-EntraMSGroupLifecyclePolicy -Id $updatedGroupLifecyclePolicy.Id | Out-Null } - if ($testLifePolicyGroup) { - Remove-EntraMSLifecyclePolicyGroup -Id $testLifePolicyGroup.Id -GroupId $newMSGroup.Id | Out-Null + if ($newMSGroup) { + Remove-EntraMSGroup -Id $newMSGroup.Id | Out-Null } } } From 3a3abcc563082b70cf07c8a61939b8db73fe24a3 Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Thu, 2 May 2024 18:28:33 +0530 Subject: [PATCH 05/10] updated test --- test/module/Entra/Integration/EntraGroup.Tests.ps1 | 2 +- .../Integration/EntraMSApplicationExtensionProperty.Tests.ps1 | 2 +- .../Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 | 2 +- test/module/Entra/Integration/{env.ps1 => setenv.ps1} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename test/module/Entra/Integration/{env.ps1 => setenv.ps1} (100%) diff --git a/test/module/Entra/Integration/EntraGroup.Tests.ps1 b/test/module/Entra/Integration/EntraGroup.Tests.ps1 index 70cfae06f..b55d981f6 100644 --- a/test/module/Entra/Integration/EntraGroup.Tests.ps1 +++ b/test/module/Entra/Integration/EntraGroup.Tests.ps1 @@ -2,7 +2,7 @@ Describe "The EntraGroup command executing unmocked" { Context "When getting user and group" { BeforeAll { - $testReportPath = join-path $psscriptroot "\env.ps1" + $testReportPath = join-path $psscriptroot "\setenv.ps1" Import-Module -Name $testReportPath $appId = $env:TEST_APPID $tenantId = $env:TEST_TENANTID diff --git a/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 b/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 index 46d2252e0..e5b95c3ae 100644 --- a/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 @@ -2,7 +2,7 @@ Describe "The EntraMSApplicationExtensionProperty command executing unmocked" { Context "When getting ApplicationExtensionProperty" { BeforeAll { - $testReportPath = Join-Path $PSScriptRoot "\env.ps1" + $testReportPath = Join-Path $PSScriptRoot "\setenv.ps1" Import-Module -Name $testReportPath $appId = $env:TEST_APPID diff --git a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 index d597d873c..4ea191c4e 100644 --- a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 @@ -2,7 +2,7 @@ Describe "The EntraMSLifecyclePolicyGroup command executing unmocked" { Context "When getting LifecyclePolicyGroup" { BeforeAll { - $testReportPath = Join-Path $PSScriptRoot "\env.ps1" + $testReportPath = Join-Path $PSScriptRoot "\setenv.ps1" Import-Module -Name $testReportPath $appId = $env:TEST_APPID diff --git a/test/module/Entra/Integration/env.ps1 b/test/module/Entra/Integration/setenv.ps1 similarity index 100% rename from test/module/Entra/Integration/env.ps1 rename to test/module/Entra/Integration/setenv.ps1 From f098a8d2e5e53586b34652d6e3f38e01ee5ba673 Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Fri, 3 May 2024 18:52:02 +0530 Subject: [PATCH 06/10] Removed EntraGroup, Added EntraGroupOwner and EntraGroupAppRoleAssignment, Updated EntraMSLifecyclePolicyGroup test --- ... => EntraGroupAppRoleAssignment.Tests.ps1} | 17 ++-- .../Integration/EntraGroupOwner.Tests.ps1 | 86 +++++++++++++++++++ .../EntraMSLifecyclePolicyGroup.Tests.ps1 | 15 ---- 3 files changed, 97 insertions(+), 21 deletions(-) rename test/module/Entra/Integration/{EntraGroup.Tests.ps1 => EntraGroupAppRoleAssignment.Tests.ps1} (63%) create mode 100644 test/module/Entra/Integration/EntraGroupOwner.Tests.ps1 diff --git a/test/module/Entra/Integration/EntraGroup.Tests.ps1 b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 similarity index 63% rename from test/module/Entra/Integration/EntraGroup.Tests.ps1 rename to test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 index b55d981f6..344199ea3 100644 --- a/test/module/Entra/Integration/EntraGroup.Tests.ps1 +++ b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 @@ -10,26 +10,31 @@ Describe "The EntraGroup command executing unmocked" { Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid - $testName = 'Demo Name' + $thisTestInstanceId - + $global:displayName = 'DemoName' + $thisTestInstanceId + #create test group - $global:newGroup = New-EntraGroup -DisplayName $testName -MailEnabled $false -SecurityEnabled $true -MailNickName "NotSet" + $global:newGroup = New-EntraGroup -DisplayName $displayName -MailEnabled $false -SecurityEnabled $true -MailNickName $testName + Write-Host $newGroup } It "should successfully get a specific group by using an Id" { $group = Get-EntraGroup -ObjectId $newGroup.Id $group.Id | Should -Be $newGroup.Id - $group.DisplayName | Should -Be $testName + $group.DisplayName | Should -Be $displayName } It "should successfully update a group display name" { - Set-EntraGroup -ObjectId $newGroup.Id -DisplayName "Demo Name 2" + $global:updatedDisplayName = "Demo Name 2" + Set-EntraGroup -ObjectId $newGroup.Id -DisplayName $updatedDisplayName $result = Get-EntraGroup -ObjectId $newGroup.Id $result.Id | Should -Contain $newGroup.Id } + AfterAll { - Remove-EntraGroup -ObjectId $newGroup.Id | Out-Null + if ($newGroup) { + Remove-EntraGroup -ObjectId $newGroup.Id | Out-Null + } } } } \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraGroupOwner.Tests.ps1 b/test/module/Entra/Integration/EntraGroupOwner.Tests.ps1 new file mode 100644 index 000000000..19224a2ab --- /dev/null +++ b/test/module/Entra/Integration/EntraGroupOwner.Tests.ps1 @@ -0,0 +1,86 @@ +Describe "The 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-Object -expandproperty guid + $global:displayName = 'DemoName' + $thisTestInstanceId + + #create test group + $global:newGroup = New-EntraGroup -DisplayName $displayName -MailEnabled $false -SecurityEnabled $true -MailNickName $displayName + Write-Host $newGroup.Id + } + + It "should successfully get a specific group by using an Id" { + $group = Get-EntraGroup -ObjectId $newGroup.Id + $group.Id | Should -Be $newGroup.Id + $group.DisplayName | Should -Be $displayName + } + + It "should successfully update a group display name" { + $global:updatedDisplayName = "DemoNameUpdated" + Set-EntraGroup -ObjectId $newGroup.Id -DisplayName $updatedDisplayName + $result = Get-EntraGroup -ObjectId $newGroup.Id + $result.Id | Should -Contain $newGroup.Id + $result.DisplayName | Should -Contain $updatedDisplayName + } + + It "should successfully create user" { + #create test user + $PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile + $PasswordProfile.Password = "Pass@12345" + $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid + $Username = 'DemoName' + $thisTestInstanceId + $UserPrincipalName = "$Username@M365x99297270.OnMicrosoft.com" + $global:newUser = New-EntraUser -DisplayName $updatedDisplayName -PasswordProfile $PasswordProfile -UserPrincipalName $UserPrincipalName -AccountEnabled $true -MailNickName $updatedDisplayName + Write-Host $newUser + } + + It "should successfully get user" { + $user = Get-EntraUser -ObjectId $newUser.Id + $user.Id | Should -Be $newUser.Id + $user.DisplayName | Should -Be $updatedDisplayName + } + + It "should successfully get user" { + $user = Get-EntraUser -ObjectId $newUser.Id + $user.Id | Should -Be $newUser.Id + $user.DisplayName | Should -Be $updatedDisplayName + $updatedDisplayNameInCreatedUser = 'YetAnotherTestUser' + Set-EntraUser -ObjectId $newUser.Id -Displayname $updatedDisplayNameInCreatedUser + $global:updatedUser = Get-EntraUser -ObjectId $newUser.Id + $updatedUser.Id | Should -Be $newUser.Id + $updatedUser.DisplayName | Should -Be $updatedDisplayNameInCreatedUser + Write-Host $updatedUser.Id + } + + It "should successfully create and get group owner" { + #create group owner + $createdGroupOwner= Add-EntraGroupOwner -ObjectId $newGroup.Id -RefObjectId $updatedUser.Id + Write-Host $createdGroupOwner | FL + + $global:getCreatedGroupOwner = Get-EntraGroupOwner -ObjectId $newGroup.Id + $getCreatedGroupOwner.Id | Should -Be $updatedUser.Id + Write-Host $getCreatedGroupOwner + Write-Host $getCreatedGroupOwner.Id + } + + AfterAll { + if ($getCreatedGroupOwner) { + Remove-EntraGroupOwner -ObjectId $updatedUser.Id -OwnerId $getCreatedGroupOwner.Id | Out-Null + } + if ($updatedUser) { + Remove-EntraUser -ObjectId $updatedUser.Id | Out-Null + } + if ($newGroup) { + Remove-EntraGroup -ObjectId $newGroup.Id | Out-Null + } + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 index 4ea191c4e..c4a32486e 100644 --- a/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSLifecyclePolicyGroup.Tests.ps1 @@ -9,15 +9,12 @@ Describe "The EntraMSLifecyclePolicyGroup command executing unmocked" { $tenantId = $env:TEST_TENANTID $cert = $env:CERTIFICATETHUMBPRINT - # Validate required environment variables if (-not $appId -or -not $tenantId -or -not $cert) { throw "Required environment variables are not set." } - # Connect to Entra service Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert - # Create a group with Description parameter. $thisTestInstanceId = New-Guid | Select-Object -ExpandProperty Guid $global:displayName = 'Demo Help Group' + $thisTestInstanceId $testNickname = "testhelpDeskAdminGroup" @@ -39,14 +36,12 @@ Describe "The EntraMSLifecyclePolicyGroup command executing unmocked" { } It "should successfully Create a lifecycle policy" { - # Create a lifecycle policy $global:testGroupPolicy = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.un" } It "should successfully retrieve properties of an groupLifecyclePolicy" { $groupLifecyclePolicy = Get-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id - # Ensure that the retrieved group lifecycle policy matches the expected one $groupLifecyclePolicy.Id | Should -Be $testGroupPolicy.Id $groupLifecyclePolicy.GroupLifetimeInDays | Should -Be 99 $groupLifecyclePolicy.ManagedGroupTypes | Should -Contain "Selected" @@ -58,29 +53,19 @@ Describe "The EntraMSLifecyclePolicyGroup command executing unmocked" { $global:updatedGroupLifecyclePolicy = Set-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id -GroupLifetimeInDays 200 -AlternateNotificationEmails $alternateNotificationEmails -ManagedGroupTypes "Selected" Start-Sleep -Seconds 10 - # Ensure that the retrieved group lifecycle policy matches the expected one $updatedGroupLifecyclePolicy.Id | Should -Be $testGroupPolicy.Id $updatedGroupLifecyclePolicy.GroupLifetimeInDays | Should -Be 200 $updatedGroupLifecyclePolicy.ManagedGroupTypes | Should -Contain "Selected" $updatedGroupLifecyclePolicy.AlternateNotificationEmails | Should -Contain $alternateNotificationEmails } - # It "should throw an exception if a nonexistent ID parameter is specified" { - # $Id = (New-Guid).Guid - # Get-EntraMSGroupLifecyclePolicy -Id $Id -ErrorAction ignore - # $errorMessage = $Error[0].Exception.Message - # $errorMessage | Should -match "([\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12})" - # } - It "should successfully associate the group with the lifecycle policy" { - # Associate the group with the lifecycle policy $testLifePolicyGroup = Add-EntraMSLifecyclePolicyGroup -Id $testGroupPolicy.Id -GroupId $newMSGroup.Id $testLifePolicyGroup.ObjectId | Should -BeNullOrEmpty Start-Sleep -Seconds 10 } It "should successfully retrieve details of a LifecyclePolicyGroup" { - # Get lifecycle policy group using group id $global:lifecyclePolicyGroup = Get-EntraMSLifecyclePolicyGroup -Id $newMSGroup.Id $lifecyclePolicyGroup.ObjectId | Should -Be $testGroupPolicy.Id $lifecyclePolicyGroup.GroupLifetimeInDays | Should -Be 200 From 96759e24d9b076c557a27bdee8dd28e15e1d6a13 Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Mon, 6 May 2024 12:59:39 +0530 Subject: [PATCH 07/10] updated test --- .../EntraGroupAppRoleAssignment.Tests.ps1 | 3 +- .../Integration/EntraGroupOwner.Tests.ps1 | 38 ++++++++++++------- ...raMSApplicationExtensionProperty.Tests.ps1 | 7 +--- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 index 344199ea3..6fb44cce9 100644 --- a/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 @@ -12,8 +12,7 @@ Describe "The EntraGroup command executing unmocked" { $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid $global:displayName = 'DemoName' + $thisTestInstanceId - #create test group - $global:newGroup = New-EntraGroup -DisplayName $displayName -MailEnabled $false -SecurityEnabled $true -MailNickName $testName + $global:newGroup = New-EntraGroup -DisplayName $displayName -MailEnabled $false -SecurityEnabled $true -MailNickName $displayName Write-Host $newGroup } diff --git a/test/module/Entra/Integration/EntraGroupOwner.Tests.ps1 b/test/module/Entra/Integration/EntraGroupOwner.Tests.ps1 index 19224a2ab..eac1dee82 100644 --- a/test/module/Entra/Integration/EntraGroupOwner.Tests.ps1 +++ b/test/module/Entra/Integration/EntraGroupOwner.Tests.ps1 @@ -12,9 +12,7 @@ Describe "The EntraGroupOwner command executing unmocked" { $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid $global:displayName = 'DemoName' + $thisTestInstanceId - #create test group $global:newGroup = New-EntraGroup -DisplayName $displayName -MailEnabled $false -SecurityEnabled $true -MailNickName $displayName - Write-Host $newGroup.Id } It "should successfully get a specific group by using an Id" { @@ -32,23 +30,21 @@ Describe "The EntraGroupOwner command executing unmocked" { } It "should successfully create user" { - #create test user $PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile $PasswordProfile.Password = "Pass@12345" $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid $Username = 'DemoName' + $thisTestInstanceId $UserPrincipalName = "$Username@M365x99297270.OnMicrosoft.com" $global:newUser = New-EntraUser -DisplayName $updatedDisplayName -PasswordProfile $PasswordProfile -UserPrincipalName $UserPrincipalName -AccountEnabled $true -MailNickName $updatedDisplayName - Write-Host $newUser } - It "should successfully get user" { + It "should successfully get created user" { $user = Get-EntraUser -ObjectId $newUser.Id $user.Id | Should -Be $newUser.Id $user.DisplayName | Should -Be $updatedDisplayName } - It "should successfully get user" { + It "should successfully update created user" { $user = Get-EntraUser -ObjectId $newUser.Id $user.Id | Should -Be $newUser.Id $user.DisplayName | Should -Be $updatedDisplayName @@ -57,23 +53,34 @@ Describe "The EntraGroupOwner command executing unmocked" { $global:updatedUser = Get-EntraUser -ObjectId $newUser.Id $updatedUser.Id | Should -Be $newUser.Id $updatedUser.DisplayName | Should -Be $updatedDisplayNameInCreatedUser - Write-Host $updatedUser.Id } It "should successfully create and get group owner" { - #create group owner - $createdGroupOwner= Add-EntraGroupOwner -ObjectId $newGroup.Id -RefObjectId $updatedUser.Id - Write-Host $createdGroupOwner | FL - + Add-EntraGroupOwner -ObjectId $newGroup.Id -RefObjectId $updatedUser.Id $global:getCreatedGroupOwner = Get-EntraGroupOwner -ObjectId $newGroup.Id $getCreatedGroupOwner.Id | Should -Be $updatedUser.Id - Write-Host $getCreatedGroupOwner - Write-Host $getCreatedGroupOwner.Id + } + + It "should successfully create second user" { + $PasswordProfile1 = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile + $PasswordProfile1.Password = "Pass@12345" + $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid + $Username1 = 'DemoName2' + $thisTestInstanceId + $UserPrincipalName1 = "$Username1@M365x99297270.OnMicrosoft.com" + $global:newUser1 = New-EntraUser -DisplayName $updatedDisplayName -PasswordProfile $PasswordProfile1 -UserPrincipalName $UserPrincipalName1 -AccountEnabled $true -MailNickName $updatedDisplayName + } + + It "should successfully create and get group owner for second user" { + Add-EntraGroupOwner -ObjectId $newGroup.Id -RefObjectId $newUser1.Id + $getCreatedGroupOwner1 = Get-EntraGroupOwner -ObjectId $newGroup.Id + $retrievedIds = $getCreatedGroupOwner1.Id | Sort-Object -Unique + $retrievedIds.Count | Should -BeExactly 2 + $retrievedIds | should -Contain $newUser1.Id } AfterAll { if ($getCreatedGroupOwner) { - Remove-EntraGroupOwner -ObjectId $updatedUser.Id -OwnerId $getCreatedGroupOwner.Id | Out-Null + Remove-EntraGroupOwner -ObjectId $newGroup.Id -OwnerId $getCreatedGroupOwner.Id | Out-Null } if ($updatedUser) { Remove-EntraUser -ObjectId $updatedUser.Id | Out-Null @@ -81,6 +88,9 @@ Describe "The EntraGroupOwner command executing unmocked" { if ($newGroup) { Remove-EntraGroup -ObjectId $newGroup.Id | Out-Null } + if ($newUser1) { + Remove-EntraUser -ObjectId $newUser1.Id | Out-Null + } } } } \ No newline at end of file diff --git a/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 b/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 index e5b95c3ae..c8e749dd5 100644 --- a/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 +++ b/test/module/Entra/Integration/EntraMSApplicationExtensionProperty.Tests.ps1 @@ -9,15 +9,12 @@ Describe "The EntraMSApplicationExtensionProperty command executing unmocked" { $tenantId = $env:TEST_TENANTID $cert = $env:CERTIFICATETHUMBPRINT - # Validate required environment variables if (-not $appId -or -not $tenantId -or -not $cert) { throw "Required environment variables are not set." } - # Connect to Entra service Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert - - # Create an application + $thisTestInstanceId = New-Guid | Select-Object -expandproperty guid $testApplicationName = 'Test Demo Name' + $thisTestInstanceId $global:newMSApplication = New-EntraMSApplication -DisplayName $testApplicationName @@ -40,12 +37,10 @@ Describe "The EntraMSApplicationExtensionProperty command executing unmocked" { } It "should successfully create application extension property" { - # Create an extension property $global:newMSApplicationExtensionProperty = New-EntraMSApplicationExtensionProperty -ObjectId $newMSApplication.Id -DataType "string" -Name "NewAttribute" -TargetObjects "Application" } It "should successfully get application extension property" { - # Get application extension property using object id $applicationExtensionProperty = Get-EntraMSApplicationExtensionProperty -ObjectId $newMSApplication.Id $applicationExtensionProperty.ObjectId | Should -Be $newMSApplicationExtensionProperty.Id $applicationExtensionProperty.Name | Should -Be $newMSApplicationExtensionProperty.Name From f0b32fa86d10f831db59bb9bda167e8e918c623a Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Mon, 6 May 2024 19:12:58 +0530 Subject: [PATCH 08/10] updated test --- .../EntraGroupAppRoleAssignment.Tests.ps1 | 66 ++++++++++++++++++- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 index 6fb44cce9..edaba61e3 100644 --- a/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 @@ -1,6 +1,6 @@ -Describe "The EntraGroup command executing unmocked" { +Describe "The EntraGroupAppRoleAssignment command executing unmocked" { - Context "When getting user and group" { + Context "When getting GroupAppRoleAssignment" { BeforeAll { $testReportPath = join-path $psscriptroot "\setenv.ps1" Import-Module -Name $testReportPath @@ -13,7 +13,6 @@ Describe "The EntraGroup command executing unmocked" { $global:displayName = 'DemoName' + $thisTestInstanceId $global:newGroup = New-EntraGroup -DisplayName $displayName -MailEnabled $false -SecurityEnabled $true -MailNickName $displayName - Write-Host $newGroup } It "should successfully get a specific group by using an Id" { @@ -29,8 +28,69 @@ Describe "The EntraGroup command executing unmocked" { $result.Id | Should -Contain $newGroup.Id } + It "should successfully create application" { + $applicationDisplayName = "Demo new application" + $global:createdApplication = New-EntraApplication -DisplayName $applicationDisplayName + $createdApplication.DisplayName | Should -Be $applicationDisplayName + } + + It "should successfully get application" { + $global:getCreatedApplication = Get-EntraApplication -ObjectId $createdApplication.Id + $getCreatedApplication.DisplayName | Should -Be $createdApplication.DisplayName + $getCreatedApplication.Id | Should -Be $createdApplication.Id + $getCreatedApplication.AppId | Should -Be $createdApplication.AppId + } + + It "should successfully update application display name" { + $global:updateApplicationDisplayName = "Update demo application" + Set-EntraApplication -ObjectId $getCreatedApplication.Id -DisplayName $updateApplicationDisplayName + + $global:getUpdatedCreatedApplication = Get-EntraApplication -ObjectId $getCreatedApplication.Id + $getUpdatedCreatedApplication.DisplayName | Should -Be $updateApplicationDisplayName + $getUpdatedCreatedApplication.Id | Should -Be $getCreatedApplication.Id + $getUpdatedCreatedApplication.AppId | Should -Be $getCreatedApplication.AppId + } + + It "should successfully create and get service principal" { + $global:MyApp = Get-EntraApplication -Filter "DisplayName eq '$($getUpdatedCreatedApplication.DisplayName)'" + + New-EntraServicePrincipal -AccountEnabled $true -AppId $MyApp.AppId -AppRoleAssignmentRequired $true -DisplayName $MyApp.DisplayName -Tags {"WindowsAzureActiveDirectoryIntegratedApp"} + $global:createdServicePrincipal = Get-EntraServicePrincipal -Filter "DisplayName eq '$($MyApp.DisplayName)'" + $createdServicePrincipal.AppId | Should -Be $MyApp.AppId + $createdServicePrincipal.DisplayName | Should -Be $MyApp.DisplayName + } + + It "should successfully update the account of a service principal" { + Set-EntraServicePrincipal -ObjectId $createdServicePrincipal.Id -AccountEnabled $False + $disableServicePrincipal = Get-EntraServicePrincipal -Filter "DisplayName eq '$($MyApp.DisplayName)'" + $disableServicePrincipal.AppId | Should -Be $MyApp.AppId + $disableServicePrincipal.DisplayName | Should -Be $MyApp.DisplayName + + Set-EntraServicePrincipal -ObjectId $createdServicePrincipal.Id -AccountEnabled $True + $global:updatedServicePrincipal = Get-EntraServicePrincipal -Filter "DisplayName eq '$($MyApp.DisplayName)'" + $updatedServicePrincipal.AppId | Should -Be $MyApp.AppId + $updatedServicePrincipal.DisplayName | Should -Be $MyApp.DisplayName + } + + It "should successfully assign a group of users to an application" { + New-EntraGroupAppRoleAssignment -ObjectId $newGroup.ObjectId -PrincipalId $newGroup.ObjectId -ResourceId $updatedServicePrincipal.ObjectId -Id $updatedServicePrincipal.AppId + } + + It "should successfully retrieve application role assignments of a group" { + $global:getGroupAppRoleAssignment = Get-EntraGroupAppRoleAssignment -ObjectId $newGroup.Id + Write-Host $getGroupAppRoleAssignment + } AfterAll { + if ( $getGroupAppRoleAssignment) { + Remove-EntraGroupAppRoleAssignment -ObjectId $newGroup.Id -AppRoleAssignmentId $getGroupAppRoleAssignment.Id | Out-Null + } + if ( $updatedServicePrincipal) { + Remove-EntraServicePrincipal -ObjectId $updatedServicePrincipal.Id | Out-Null + } + if ( $getUpdatedCreatedApplication) { + Remove-EntraApplication -ObjectId $getUpdatedCreatedApplication.Id | Out-Null + } if ($newGroup) { Remove-EntraGroup -ObjectId $newGroup.Id | Out-Null } From 268c1200354c5736071dda78c8774a0623a73aab Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Tue, 7 May 2024 12:21:22 +0530 Subject: [PATCH 09/10] updated test --- .../EntraGroupAppRoleAssignment.Tests.ps1 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 index edaba61e3..05d0d1bfe 100644 --- a/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 @@ -29,8 +29,18 @@ Describe "The EntraGroupAppRoleAssignment command executing unmocked" { } It "should successfully create application" { - $applicationDisplayName = "Demo new application" - $global:createdApplication = New-EntraApplication -DisplayName $applicationDisplayName + # $types = @() + # $types += 'User' + # $approle = New-Object Microsoft.Open.AzureAD.Model.AppRole + # $approle.AllowedMemberTypes = $types + # $approle.Description = 'msiam_access' + # $approle.DisplayName = 'msiam_access' + # $approle.Id = '643985ce-3eaf-4a67-9550-ecca25cb6814' + # $approle.Value = 'Application' + # $approle.IsEnabled = $true + $applicationDisplayName = "Demo new application" + $global:createdApplication = New-EntraApplication -DisplayName $applicationDisplayName + # -AppRoles $approle $createdApplication.DisplayName | Should -Be $applicationDisplayName } @@ -73,7 +83,7 @@ Describe "The EntraGroupAppRoleAssignment command executing unmocked" { } It "should successfully assign a group of users to an application" { - New-EntraGroupAppRoleAssignment -ObjectId $newGroup.ObjectId -PrincipalId $newGroup.ObjectId -ResourceId $updatedServicePrincipal.ObjectId -Id $updatedServicePrincipal.AppId + New-EntraGroupAppRoleAssignment -ObjectId $newGroup.ObjectId -PrincipalId $newGroup.ObjectId -ResourceId $updatedServicePrincipal.ObjectId -Id $updatedServicePrincipal.Approles[0].id } It "should successfully retrieve application role assignments of a group" { From c6ba4640390867399d79e8a9c844ed6365066e01 Mon Sep 17 00:00:00 2001 From: Sanjeev Kumar Date: Tue, 7 May 2024 16:35:56 +0530 Subject: [PATCH 10/10] Updated EntraGroupAppRoleAssignment test --- .../EntraGroupAppRoleAssignment.Tests.ps1 | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 index 05d0d1bfe..22bfff3bc 100644 --- a/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1 @@ -29,18 +29,17 @@ Describe "The EntraGroupAppRoleAssignment command executing unmocked" { } It "should successfully create application" { - # $types = @() - # $types += 'User' - # $approle = New-Object Microsoft.Open.AzureAD.Model.AppRole - # $approle.AllowedMemberTypes = $types - # $approle.Description = 'msiam_access' - # $approle.DisplayName = 'msiam_access' - # $approle.Id = '643985ce-3eaf-4a67-9550-ecca25cb6814' - # $approle.Value = 'Application' - # $approle.IsEnabled = $true + $types = @() + $types += 'User' + $approle = New-Object Microsoft.Open.AzureAD.Model.AppRole + $approle.AllowedMemberTypes = $types + $approle.Description = 'msiam_access' + $approle.DisplayName = 'msiam_access' + $approle.Id = '643985ce-3eaf-4a67-9550-ecca25cb6814' + $approle.Value = 'Application' + $approle.IsEnabled = $true $applicationDisplayName = "Demo new application" - $global:createdApplication = New-EntraApplication -DisplayName $applicationDisplayName - # -AppRoles $approle + $global:createdApplication = New-EntraApplication -DisplayName $applicationDisplayName -AppRoles $approle $createdApplication.DisplayName | Should -Be $applicationDisplayName } @@ -88,7 +87,8 @@ Describe "The EntraGroupAppRoleAssignment command executing unmocked" { It "should successfully retrieve application role assignments of a group" { $global:getGroupAppRoleAssignment = Get-EntraGroupAppRoleAssignment -ObjectId $newGroup.Id - Write-Host $getGroupAppRoleAssignment + $getGroupAppRoleAssignment.ResourceDisplayName | Should -Be $createdServicePrincipal.DisplayName + $getGroupAppRoleAssignment.PrincipalDisplayName | Should -Be $updatedDisplayName } AfterAll {