Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration Testing : Entra/EntraBeta #1028

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1cf2384
added Integration test cases
v-akarke Aug 23, 2024
570f88b
added Integration Testing
v-akarke Aug 27, 2024
a63161d
added Integration test cases
v-akarke Aug 30, 2024
4f78932
main pull
v-akarke Aug 30, 2024
c3f3e8f
added EntraBetaObjectSetting
v-akarke Sep 3, 2024
578bc32
Merge branch 'main' into Integration
v-akarke Sep 3, 2024
f54012e
conflict
snehalkotwal Sep 25, 2024
9f539cf
updated license
snehalkotwal Sep 25, 2024
94cc3a9
Update test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1
v-akarke Sep 26, 2024
f380427
main pull
v-akarke Sep 27, 2024
0c1f2f1
added Integration test cases
v-akarke Aug 23, 2024
e3af752
added Integration Testing
v-akarke Aug 27, 2024
263e935
added Integration test cases
v-akarke Aug 30, 2024
4aeec5d
added EntraBetaObjectSetting
v-akarke Sep 3, 2024
eb59c4e
updated license
snehalkotwal Sep 25, 2024
4d1a1d1
Update test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1
v-akarke Sep 26, 2024
b7b8945
main pull
v-akarke Sep 30, 2024
0f2cddd
updated test cases
v-akarke Sep 30, 2024
77aa53e
updated structure
v-akarke Sep 30, 2024
fe7b76c
main pull
v-akarke Sep 30, 2024
5360120
updated beta test cases
v-akarke Sep 30, 2024
58b2463
Merge branch 'main' into Integration
v-akarke Oct 1, 2024
547eae0
updated test cases
v-akarke Oct 1, 2024
b8d8f40
main pull
v-akarke Oct 1, 2024
ad4ec10
main pull
v-akarke Oct 1, 2024
05c6594
main pull
v-akarke Oct 1, 2024
bfad5ea
resolved PR comments
v-akarke Oct 1, 2024
9008b9c
Merge branch 'main' into Integration
v-akarke Oct 1, 2024
8bdeb5e
updated test cases
v-akarke Oct 1, 2024
af7ca29
updated test cases
v-akarke Oct 1, 2024
983e84d
Merge branch 'main' into Integration
v-varshamane Oct 1, 2024
f46fa9b
updated clientId
v-varshamane Oct 2, 2024
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
69 changes: 69 additions & 0 deletions test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
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-MgGraph -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert

$thisTestInstanceId = New-Guid | Select-Object -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 $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
}

It "should update the properties of user and group" {
$updatedDisplayName = "SimpleTestsUpdated"
Set-EntraGroup -Id $newGroup.Id -DisplayName $updatedDisplayName

$result = Get-EntraGroup -ObjectId $newGroup.Id
$result.Id | Should -Contain $newGroup.Id
$result.DisplayName | Should -Contain $updatedDisplayName

$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 $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
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
Describe "The EntraApplicationExtensionProperty command executing unmocked" {

Context "When getting ApplicationExtensionProperty" {
BeforeAll {
$testReportPath = Join-Path $PSScriptRoot "\setenv.ps1"
Import-Module -Name $testReportPath

$appId = $env:TEST_APPID
$tenantId = $env:TEST_TENANTID
$cert = $env:CERTIFICATETHUMBPRINT

if (-not $appId -or -not $tenantId -or -not $cert) {
throw "Required environment variables are not set."
}

Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert

$thisTestInstanceId = New-Guid | Select-Object -expandproperty guid
$testApplicationName = 'Test Demo Name' + $thisTestInstanceId
$global:newMSApplication = New-EntraApplication -DisplayName $testApplicationName
}

It "should successfully get an application by display name" {
$application = Get-EntraApplication -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-EntraApplication -ObjectId $newMSApplication.ObjectId -DisplayName $updatedDisplayName
$result = Get-EntraApplication -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" {
$global:newMSApplicationExtensionProperty = New-EntraApplicationExtensionProperty -ObjectId $newMSApplication.Id -DataType "string" -Name "NewAttribute" -TargetObjects "Application"
}

It "should successfully get application extension property" {
$applicationExtensionProperty = Get-EntraApplicationExtensionProperty -ObjectId $newMSApplication.Id
$applicationExtensionProperty.ObjectId | Should -Be $newMSApplicationExtensionProperty.Id
$applicationExtensionProperty.Name | Should -Be $newMSApplicationExtensionProperty.Name

}

AfterAll {
if ($newMSApplicationExtensionProperty) {
Remove-EntraApplicationExtensionProperty -ObjectId $newMSApplication.Id -ExtensionPropertyId $newMSApplicationExtensionProperty.Id | Out-Null
}
if ($newMSApplication) {
Remove-EntraApplication -ObjectId $newMSApplication.Id | Out-Null
}
}
}
}
112 changes: 112 additions & 0 deletions test/module/Entra/Integration/EntraGroupAppRoleAssignment.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
Describe "The EntraGroupAppRoleAssignment command executing unmocked" {

Context "When getting GroupAppRoleAssignment" {
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

$global:newGroup = New-EntraGroup -DisplayName $displayName -MailEnabled $false -SecurityEnabled $true -MailNickName $displayName
}

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 = "Demo Name 2"
Set-EntraGroup -Id $newGroup.Id -DisplayName $updatedDisplayName
$result = Get-EntraGroup -ObjectId $newGroup.Id
$result.Id | Should -Contain $newGroup.Id
}

It "should successfully create application" {
$types = @()
$types += 'User'
$approle = New-Object Microsoft.Open.MSGraph.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
}

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.Approles[0].id
}

It "should successfully retrieve application role assignments of a group" {
$global:getGroupAppRoleAssignment = Get-EntraGroupAppRoleAssignment -ObjectId $newGroup.Id
$getGroupAppRoleAssignment.ResourceDisplayName | Should -Be $createdServicePrincipal.DisplayName
$getGroupAppRoleAssignment.PrincipalDisplayName | Should -Be $updatedDisplayName
}

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
}
}
}
}
94 changes: 94 additions & 0 deletions test/module/Entra/Integration/EntraLifecyclePolicyGroup.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
Describe "The EntraLifecyclePolicyGroup command executing unmocked" {

Context "When getting LifecyclePolicyGroup" {
BeforeAll {
$testReportPath = Join-Path $PSScriptRoot "\setenv.ps1"
Import-Module -Name $testReportPath

$appId = $env:TEST_APPID
$tenantId = $env:TEST_TENANTID
$cert = $env:CERTIFICATETHUMBPRINT

if (-not $appId -or -not $tenantId -or -not $cert) {
throw "Required environment variables are not set."
}

Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert

$thisTestInstanceId = New-Guid | Select-Object -ExpandProperty Guid
$global:displayName = 'Demo Help Group' + $thisTestInstanceId
$testNickname = "test" + $thisTestInstanceId
$global:newMSGroup = New-EntraGroup -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-EntraGroup -ObjectId $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-EntraGroup -Id $newMSGroup.Id -DisplayName $updatedDisplayName
$result = Get-EntraGroup -ObjectId $newMSGroup.Id
$result.Id | Should -Contain $newMSGroup.Id
}

It "should successfully Create a lifecycle policy" {
try {
$existingPolicy = Get-EntraGroupLifecyclePolicy
Remove-EntraGroupLifecyclePolicy -Id $existingPolicy.Id
}
catch {}
$global:testGroupPolicy = New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "[email protected]"
}

It "should successfully retrieve properties of an groupLifecyclePolicy" {
$groupLifecyclePolicy = Get-EntraGroupLifecyclePolicy -Id $testGroupPolicy.Id

$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 groupLifecyclePolicy" {
$alternateNotificationEmails = "[email protected]"
$global:updatedGroupLifecyclePolicy = Set-EntraGroupLifecyclePolicy -Id $testGroupPolicy.Id -GroupLifetimeInDays 200 -AlternateNotificationEmails $alternateNotificationEmails -ManagedGroupTypes "Selected"

$updatedGroupLifecyclePolicy.Id | Should -Be $testGroupPolicy.Id
$updatedGroupLifecyclePolicy.GroupLifetimeInDays | Should -Be 200
$updatedGroupLifecyclePolicy.ManagedGroupTypes | Should -Contain "Selected"
$updatedGroupLifecyclePolicy.AlternateNotificationEmails | Should -Contain $alternateNotificationEmails
}

It "should successfully associate the group with the lifecycle policy" {
$testLifePolicyGroup = Add-EntraLifecyclePolicyGroup -Id $testGroupPolicy.Id -GroupId $newMSGroup.Id
$testLifePolicyGroup.ObjectId | Should -BeNullOrEmpty
}

It "should successfully retrieve details of a LifecyclePolicyGroup" {
$global:lifecyclePolicyGroup = Get-EntraLifecyclePolicyGroup -Id $newMSGroup.Id
$lifecyclePolicyGroup.ObjectId | Should -Be $testGroupPolicy.Id
$lifecyclePolicyGroup.GroupLifetimeInDays | Should -Be 200
$lifecyclePolicyGroup.ManagedGroupTypes | Should -Contain "Selected"
$lifecyclePolicyGroup.AlternateNotificationEmails | Should -Contain $updatedGroupLifecyclePolicy.AlternateNotificationEmails
}

AfterAll {
if ($lifecyclePolicyGroup) {
Remove-EntraLifecyclePolicyGroup -Id $lifecyclePolicyGroup.Id -GroupId $newMSGroup.Id | Out-Null
}
if ($updatedGroupLifecyclePolicy) {
Remove-EntraGroupLifecyclePolicy -Id $updatedGroupLifecyclePolicy.Id | Out-Null
}
if ($newMSGroup) {
Remove-EntraGroup -ObjectId $newMSGroup.Id | Out-Null
}
}
}
}
Loading