diff --git a/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 b/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 new file mode 100644 index 0000000000..87c2f031b8 --- /dev/null +++ b/test/module/Entra/Integration/Add-EntraGroupMember.Tests.ps1 @@ -0,0 +1,44 @@ +Describe "The Add-EntraGroupMember command executing unmocked" { + + Context "When getting user and group" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $testName = 'SimpleTest' + $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 "SimpleTestUser@M365x99297270.OnMicrosoft.com" + + #create test group + $global:newGroup = New-EntraGroup -DisplayName $testName -MailEnabled $false -SecurityEnabled $true -MailNickName $testName + } + + It "should successfully add user to new created group" { + $user = Get-EntraUser -ObjectId $newUser.Id + $user.Id | Should -Be $newUser.Id + $user.DisplayName | Should -Be $testName + + $group = Get-EntraGroup -ObjectId $newGroup.Id + $group.Id | Should -Be $newGroup.Id + $group.DisplayName | Should -Be $testName + + Add-EntraGroupMember -ObjectId $group.Id -RefObjectId $user.Id + $result = Get-EntraGroupMember -ObjectId $group.Id + $result.Id | Should -Contain $user.Id + } + + AfterAll { + Remove-EntraGroupMember -ObjectId $newGroup.Id -MemberId $newUser.Id + Remove-EntraUser -ObjectId $newUser.Id + Remove-EntraGroup -ObjectId $newGroup.Id + } + } +} diff --git a/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 new file mode 100644 index 0000000000..6b5dd71a70 --- /dev/null +++ b/test/module/Entra/Integration/Add-EntraGroupOwner.Tests.ps1 @@ -0,0 +1,66 @@ +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 -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 proprties of user and group" { + $updatedDisplayName = "SimpleTestsUpdated" + Set-EntraGroup -ObjectId $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 + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 b/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 new file mode 100644 index 0000000000..160a2f20bd --- /dev/null +++ b/test/module/Entra/Integration/Add-EntraServicePrincipalOwner.Tests.ps1 @@ -0,0 +1,63 @@ +Describe "The Add-EntraServicePrincipalOwner command executing unmocked" { + + Context "When getting ServicePrincipal and User" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-MgGraph -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $testName1 = 'DemoTests' + $thisTestInstanceId + $testname2 = 'appTests' + $thisTestInstanceId + + #Create Teste Application + $global:newApplication = New-EntraApplication -DisplayName $testname2 + + #create ServicePrincipal test user + $global:newServicePrincipal = New-EntraServicePrincipal -AccountEnabled $true -AlternativeNames "Demo" -DisplayName $testname2 -AppId $newApplication.AppId + + #create test user + $PasswordProfile1 = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile + $PasswordProfile1.Password = "Pass@1234" + $global:newUser1 = New-EntraUser -AccountEnabled $true -DisplayName $testName1 -PasswordProfile $PasswordProfile1 -MailNickName $testName1 -UserPrincipalName $testName1"@M365x99297270.OnMicrosoft.com" + + } + + It "should update the properties of Application , ServicePrincipal and User" { + $updatedDisplayNameforappUser = 'appTetsUpdatedUser' + Set-EntraApplication -ObjectId $newApplication.Id -Displayname $updatedDisplayNameforappUser + + $Application = Get-EntraApplication -ObjectId $newApplication.Id + $Application.Id | Should -Be $newApplication.Id + $Application.DisplayName | Should -Be $updatedDisplayNameforappUser + + Set-EntraServicePrincipal -ObjectId $newServicePrincipal.Id -Displayname $updatedDisplayNameforappUser + + $ServicePrincipal = Get-EntraServicePrincipal -ObjectId $newServicePrincipal.Id + $ServicePrincipal.Id | Should -Be $newServicePrincipal.Id + $ServicePrincipal.DisplayName | Should -Be $updatedDisplayNameforappUser + + $updatedDisplayNameInCreatedUser = 'DemoTestsUpdatedUser' + Set-EntraUser -ObjectId $newUser1.Id -Displayname $updatedDisplayNameInCreatedUser + + $updatedUser = Get-EntraUser -ObjectId $newUser1.Id + $updatedUser.Id | Should -Be $newUser1.Id + $updatedUser.DisplayName | Should -Be $updatedDisplayNameInCreatedUser + } + + It "should successfully Adds an owner to a service principal." { + Add-EntraServicePrincipalOwner -ObjectId $newServicePrincipal.Id -RefObjectId $newUser1.Id + $result = Get-EntraServicePrincipalOwner -ObjectId $newServicePrincipal.Id + $result.Id | Should -Contain $newUser1.Id + } + + AfterAll { + Remove-EntraServicePrincipalOwner -ObjectId $newServicePrincipal.Id -OwnerId $newUser1.Id + Remove-EntraUser -ObjectId $newUser1.Id + Remove-EntraApplication -ObjectId $newApplication.Id + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Integration/Get-EntraApplication.Tests.ps1 b/test/module/Entra/Integration/Get-EntraApplication.Tests.ps1 new file mode 100644 index 0000000000..199acea382 --- /dev/null +++ b/test/module/Entra/Integration/Get-EntraApplication.Tests.ps1 @@ -0,0 +1,36 @@ +Describe "The Get-EntraApplication command executing unmocked" { + + Context "When getting applications" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $testAppName = 'SimpleTestAppRead' + $thisTestInstanceId + $testApp = New-EntraApplication -DisplayName $testAppName + } + + It "should successfully read the application with expected properties when the application ID parameter is used" { + $app = Get-EntraApplication -ObjectId $testApp.Id + $app.Id | Should -Be $testApp.Id + $app.DisplayName | Should -Be $testAppName + } + + It "should throw an exception if a nonexistent object ID parameter is specified" { + $Id = (New-Guid).Guid + Get-EntraApplication -ObjectId $Id -ErrorAction Stop + $Error[0] | Should -match "Resource '([^']+)' does not exist" + } + + AfterAll { + foreach ($app in (Get-EntraApplication -All $true | Where-Object { $_.DisplayName -eq $testAppName})) { + Remove-EntraApplication -ObjectId $app.Id | Out-Null + } + + } + } +} diff --git a/test/module/Entra/Integration/New-EntraApplication.Tests.ps1 b/test/module/Entra/Integration/New-EntraApplication.Tests.ps1 new file mode 100644 index 0000000000..ce3951bac2 --- /dev/null +++ b/test/module/Entra/Integration/New-EntraApplication.Tests.ps1 @@ -0,0 +1,28 @@ +Describe "The Get-EntraApplication command executing unmocked" { + + Context "When creating applications" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + } + + It "should succeed when creating a new application" { + $testAppName = 'SimpleTestApp' + $thisTestInstanceId + $newApp = New-EntraApplication -DisplayName $testAppName + $newApp.DisplayName | Should -Be $testAppName + { Get-EntraApplication -ObjectId $newApp.Id } | Should -Not -BeNullOrEmpty + } + + AfterAll { + foreach ($app in (Get-EntraApplication -All $true | Where-Object { $_.DisplayName -eq $testAppName})) { + Remove-EntraApplication -ObjectId $app.Id | Out-Null + } + } + } +} diff --git a/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 b/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 new file mode 100644 index 0000000000..54574437c5 --- /dev/null +++ b/test/module/Entra/Integration/Set-EntraApplication.Tests.ps1 @@ -0,0 +1,34 @@ +Describe "The Get-EntraApplication command executing unmocked" { + + Context "When getting applications" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-Entra -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $testAppName = 'SimpleTestAppRead' + $thisTestInstanceId + $testApp = New-EntraApplication -DisplayName $testAppName + } + + It "should successfully update the application with expected properties when the application ID parameter is used" { + $thisTestInstanceId = New-Guid | select -expandproperty guid + $newAppName = 'SimpleTestAppUpdate' + $thisTestInstanceId + Set-EntraApplication -ObjectId $testApp.Id -DisplayName $newAppName | Should -BeNullOrEmpty + + $app = Get-EntraApplication -ObjectId $testApp.Id + $app.Id | Should -Be $testApp.Id + $app.DisplayName | Should -Be $newAppName + } + + AfterAll { + foreach ($app in (Get-EntraApplication -All $true | Where-Object { $_.DisplayName -eq $newAppName})) { + Remove-EntraApplication -ObjectId $app.Id | Out-Null + } + + } + } +} diff --git a/test/module/Entra/Integration/setenv.ps1 b/test/module/Entra/Integration/setenv.ps1 new file mode 100644 index 0000000000..80c8a6e7ff --- /dev/null +++ b/test/module/Entra/Integration/setenv.ps1 @@ -0,0 +1,3 @@ +$env:TEST_APPID = "8886ad7b-1795-4542-9808-c85859d97f23" +$env:TEST_TENANTID = "d5aec55f-2d12-4442-8d2f-ccca95d4390e" +$env:CERTIFICATETHUMBPRINT = "4000D12C2AB68245A576C0BF167A3C15805F3D5C" \ No newline at end of file