Skip to content
Closed
35 changes: 35 additions & 0 deletions test/module/Entra/Integration/EntraGroup.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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 | Out-Null
}
}
}
38 changes: 38 additions & 0 deletions test/module/Entra/Integration/EntraMSApplication.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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 | Out-Null
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
36 changes: 36 additions & 0 deletions test/module/Entra/Integration/EntraMSGroup.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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 | Out-Null
}
}
}
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
}

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 "[email protected]"
}

It "should successfully update group lifecycle policy" {
$updatedGroupLifecyclePolicy = Set-EntraMSGroupLifecyclePolicy -Id $testGroupPolicy.Id -GroupLifetimeInDays 200 -AlternateNotificationEmails "[email protected]" -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 "[email protected]"
}

# 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
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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

# 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
$testName = '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."
}
Start-Sleep -Seconds 10

# Create a lifecycle policy
$global:testGroupPolicy = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "[email protected]"
Write-Host "Policy Id:$($testGroupPolicy.Id)"
# Validate policy creation
if (-not $testGroupPolicy) {
throw "Failed to create a new group lifecycle policy."
}
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 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 "[email protected]"
Write-Host $lifecyclePolicyGroup
}

AfterAll {
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
}
}
}
}
3 changes: 3 additions & 0 deletions test/module/Entra/Integration/env.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$env:TEST_APPID = "8886ad7b-1795-4542-9808-c85859d97f23"
$env:TEST_TENANTID = "d5aec55f-2d12-4442-8d2f-ccca95d4390e"
$env:CERTIFICATETHUMBPRINT = "6CAEA8F6CEF8C5F8642F1F9AABE0237DB3D0C424"