Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Describe "The EntraBetaObjectSetting commands executing unmocked" {

Context "When Changing group settings" {
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
$testGroupName = 'SimpleTestAppRead' + $testGroupName
$global:testGroup = New-EntraBetaGroup -DisplayName $testGroupName -MailEnabled $false -SecurityEnabled $true -MailNickName $testGroupName -Description $testGroupName
}

It "Should successfully block guest access" {
$template = Get-EntraBetaDirectorySettingTemplate | ? {$_.displayname -eq "group.unified.guest"}
$settingsCopy = $template.CreateDirectorySetting()
$settingsCopy["AllowToAddGuests"]=$False

$groupID= (Get-EntraBetaGroup -ObjectId $testGroup.Id).ObjectId
$global:newObjectSetting = New-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $groupID -DirectorySetting $settingsCopy

$ObjectSettings = Get-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $testGroup.Id
$ObjectSettings.values.value | Should -be 'False'
}

It "Should successfully allow guest access" {
$template = Get-EntraBetaDirectorySettingTemplate | ? {$_.displayname -eq "group.unified.guest"}
$settingsCopy = $template.CreateDirectorySetting()
$settingsCopy["AllowToAddGuests"]=$True

$groupID= (Get-EntraBetaGroup -ObjectId $testGroup.Id).ObjectId
Set-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $groupID -DirectorySetting $settingsCopy -Id $newObjectSetting.Id

$ObjectSettings = Get-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $testGroup.Id
$ObjectSettings.values.value | Should -be 'True'
}

AfterAll {
$groupId = (Get-EntraBetaGroup -ObjectId $testGroup.Id).ObjectId
Remove-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $groupId -Id $newObjectSetting.Id
$ObjectSettings = Get-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $testGroup.Id
$ObjectSettings | Should -BeNullorEmpty

Remove-EntraBetaGroup -ObjectId $groupId
}
}
}
3 changes: 3 additions & 0 deletions test/module/EntraBeta/Integration/setenv.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 = "305D4F33E153980E2451F6E068426FC2BCAF683E"