From a889bafd68717b661b882ca67588eede8c5d0f9e Mon Sep 17 00:00:00 2001 From: Emmanuel Ng'ang'a <60355631+emmanuel-karanja@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:14:34 +0300 Subject: [PATCH 1/5] Commented out call to create root psm1 file --- src/EntraModuleBuilder.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/EntraModuleBuilder.ps1 b/src/EntraModuleBuilder.ps1 index 85648e69ae..e69d771b52 100644 --- a/src/EntraModuleBuilder.ps1 +++ b/src/EntraModuleBuilder.ps1 @@ -278,7 +278,7 @@ foreach (`$subModule in `$subModules) { $settingPath = Join-Path $rootPath -ChildPath "/config/ModuleMetadata.json" #We do not need to create a help file for the root module, since once the nested modules are loaded, their help will be available - $files = @("$($moduleName).psd1", "$($moduleName).psm1") + $files = @("$($moduleName).psd1") $content = Get-Content -Path $settingPath | ConvertFrom-Json $PSData = @{ Tags = $($content.tags) @@ -311,7 +311,6 @@ foreach (`$subModule in `$subModules) { Author = $($content.authors) CompanyName = $($content.owners) FileList = $files - RootModule = "$($moduleName).psm1" Description = 'Microsoft Graph Entra PowerShell.' DotNetFrameworkVersion = $([System.Version]::Parse('4.7.2')) PowerShellVersion = $([System.Version]::Parse('5.1')) @@ -489,7 +488,7 @@ foreach (`$subModule in `$subModules) { #Create the Root Module Manifest - $this.CreateRootModuleManifest($module) + # $this.CreateRootModuleManifest($module) } From 62d0cfac7c50ff4fcd03ef4025b2863878e131e4 Mon Sep 17 00:00:00 2001 From: Emmanuel Ng'ang'a <60355631+emmanuel-karanja@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:17:49 +0300 Subject: [PATCH 2/5] Clean up Entra tests --- .../Get-EntraAuditDirectoryLog.Tests.ps1 | 114 -------------- ....ps1 => Get-EntraDirSyncFeature.Tests.ps1} | 0 .../Get-EntraUserDirectReport.Tests.ps1 | 140 ----------------- ...Get-EntraDirectoryRoleAssignment.Tests.ps1 | 129 ---------------- ...Get-EntraDirectoryRoleDefinition.Tests.ps1 | 145 ------------------ 5 files changed, 528 deletions(-) delete mode 100644 testVNext/Entra/DirectoryManagement/Get-EntraAuditDirectoryLog.Tests.ps1 rename testVNext/Entra/DirectoryManagement/{Get-EntraDirSyncFeatures.Tests.ps1 => Get-EntraDirSyncFeature.Tests.ps1} (100%) delete mode 100644 testVNext/Entra/DirectoryManagement/Get-EntraUserDirectReport.Tests.ps1 delete mode 100644 testVNext/Entra/Governance/Get-EntraDirectoryRoleAssignment.Tests.ps1 delete mode 100644 testVNext/Entra/Governance/Get-EntraDirectoryRoleDefinition.Tests.ps1 diff --git a/testVNext/Entra/DirectoryManagement/Get-EntraAuditDirectoryLog.Tests.ps1 b/testVNext/Entra/DirectoryManagement/Get-EntraAuditDirectoryLog.Tests.ps1 deleted file mode 100644 index 35d07002f5..0000000000 --- a/testVNext/Entra/DirectoryManagement/Get-EntraAuditDirectoryLog.Tests.ps1 +++ /dev/null @@ -1,114 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ - -BeforeAll { - if ((Get-Module -Name Microsoft.Graph.Entra.DirectoryManagement) -eq $null) { - Import-Module Microsoft.Graph.Entra.DirectoryManagement - } - Import-Module (Join-Path $PSScriptRoot "..\..\build\Common-Functions.ps1") -Force - - $scriptblock = { - # Write-Host "Mocking Get-EntraAuditDirectoryLog with parameters: $($args | ConvertTo-Json -Depth 3)" - return @( - [PSCustomObject]@{ - category = 'DirectoryManagement' - resultReason = 'Successfully deleted [0] records for [[LicenseKey:][TenantId:bbbbbbbb-1111-2222-3333-ccccccccccc2][UserName:][UserObjectId:bbbbbbbb-1111-2222-3333-ccccccccccc1][HomeTenantId:bbbbbbbb-1111-2222-3333-cccccccccccc][AzureSovereign:WorldWide]]' - id = 'bbbbbbbb-1111-2222-3333-cccccccccccc' - operationType = 'Delete' - loggedByService = 'Azure MFA12' - additionalDetails = @{ key = 'RequestId'; value = '00000000-0000-0000-0000-000000000000' } - activityDisplayName = 'DeleteDataFromBackend' - targetResources = @( - @{ - userPrincipalName = '' - groupType = '' - id = 'bbbbbbbb-1111-2222-3333-cccccccccaaa' - type = 'User' - displayName = '' - modifiedProperties = @() - } - ) - correlationId = 'bbbbbbbb-1111-2222-3333-cccccccccrrr' - result = 'success' - initiatedBy = @{ app = ''; user = '' } - activityDateTime = '06/19/2024 9:52:22 am' - } - ) - } - - Mock -CommandName Invoke-GraphRequest -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.DirectoryManagement -} - -Describe "Get-EntraAuditDirectoryLog" { - Context "Test for Get-EntraAuditDirectoryLog" { - It "Should return specific Audit Directory Logs" { - $result = Get-EntraAuditDirectoryLog -Id "bbbbbbbb-1111-2222-3333-cccccccccccc" - $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be 'bbbbbbbb-1111-2222-3333-cccccccccccc' - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should fail when Id is empty" { - { Get-EntraAuditDirectoryLog -Id } | Should -Throw "Missing an argument for parameter 'Id'*" - } - It "Should fail when filter is empty" { - { Get-EntraAuditDirectoryLog -Filter } | Should -Throw "Missing an argument for parameter 'Filter'*" - } - It "Should fail when Top is empty" { - { Get-EntraAuditDirectoryLog -Top } | Should -Throw "Missing an argument for parameter 'Top'*" - } - It "Should fail when Top is invalid" { - { Get-EntraAuditDirectoryLog -Top XY } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" - } - It "Should return all Audit Directory Logs" { - $result = Get-EntraAuditDirectoryLog -All - $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should fail when All has an argument" { - { Get-EntraAuditDirectoryLog -All $true } | Should -Throw "A positional parameter cannot be found that accepts argument 'True'.*" - } - - It "Should return specific Audit Directory Logs by filter" { - $result = Get-EntraAuditDirectoryLog -Filter "correlationId eq 'bbbbbbbb-1111-2222-3333-cccccccccrrr'" - $result | Should -Not -BeNullOrEmpty - $result.id | should -Be 'bbbbbbbb-1111-2222-3333-cccccccccccc' - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should return top Audit Directory Logs" { - $result = @(Get-EntraAuditDirectoryLog -Top 1) - $result | Should -Not -BeNullOrEmpty - $result | Should -HaveCount 1 - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should contain ID in parameters when passed Id to it" { - $result = Get-EntraAuditDirectoryLog -Id "bbbbbbbb-1111-2222-3333-cccccccccccc" - $result.Id | Should -Be "bbbbbbbb-1111-2222-3333-cccccccccccc" - } - - It "Should contain 'User-Agent' header" { - Mock -CommandName Invoke-GraphRequest -MockWith {$args} -ModuleName Microsoft.Graph.Entra.DirectoryManagement - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraAuditDirectoryLog" - $result = Get-EntraAuditDirectoryLog -Id "bbbbbbbb-1111-2222-3333-cccccccccccc" - $result | Should -Not -BeNullOrEmpty - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 -ParameterFilter { - $Headers.'User-Agent' | Should -Be $userAgentHeaderValue - $true - } - } - - It "Should execute successfully without throwing an error " { - # Disable confirmation prompts - $originalDebugPreference = $DebugPreference - $DebugPreference = 'Continue' - - try { - # Act & Assert: Ensure the function doesn't throw an exception - { Get-EntraAuditDirectoryLog -Id "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} diff --git a/testVNext/Entra/DirectoryManagement/Get-EntraDirSyncFeatures.Tests.ps1 b/testVNext/Entra/DirectoryManagement/Get-EntraDirSyncFeature.Tests.ps1 similarity index 100% rename from testVNext/Entra/DirectoryManagement/Get-EntraDirSyncFeatures.Tests.ps1 rename to testVNext/Entra/DirectoryManagement/Get-EntraDirSyncFeature.Tests.ps1 diff --git a/testVNext/Entra/DirectoryManagement/Get-EntraUserDirectReport.Tests.ps1 b/testVNext/Entra/DirectoryManagement/Get-EntraUserDirectReport.Tests.ps1 deleted file mode 100644 index 0643919d87..0000000000 --- a/testVNext/Entra/DirectoryManagement/Get-EntraUserDirectReport.Tests.ps1 +++ /dev/null @@ -1,140 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ -BeforeAll { - if ((Get-Module -Name Microsoft.Graph.Entra) -eq $null) { - Import-Module Microsoft.Graph.Entra - } - Import-Module (Join-Path $PSScriptRoot "..\..\build\Common-Functions.ps1") -Force - - $scriptblock = { - return @{ - value = @( - @{ - "Id" = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - "DisplayName" = "Mock-User" - "OnPremisesImmutableId" = $null - "DeletedDateTime" = $null - "OnPremisesSyncEnabled" = $null - "OnPremisesLastSyncDateTime" = $null - "OnPremisesProvisioningErrors" = @{} - "MobilePhone" = "425-555-0100" - "BusinessPhones" = @("425-555-0100") - "ExternalUserState" = $null - "ExternalUserStateChangeDateTime" = $null - "Parameters" = $args - } - ) - } - } - - - Mock -CommandName Invoke-GraphRequest -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra -} - - - -Describe "Get-EntraUserDirectReport" { - Context "Test for Get-EntraUserDirectReport" { - It "Should return specific user direct report" { - $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb' - - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should return specific user direct report with alias" { - $result = Get-EntraUserDirectReport -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb' - - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when UserId is empty" { - { Get-EntraUserDirectReport -UserId } | Should -Throw "Missing an argument for parameter 'UserId'*" - } - It "Should fail when UserId is invalid" { - { Get-EntraUserDirectReport -UserId "" } | Should -Throw "Cannot bind argument to parameter 'UserId' because it is an empty string.*" - } - It "Should return all user direct reports" { - $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All - $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb' - - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when All is invalid" { - { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All xyz } | Should -Throw "A positional parameter cannot be found that accepts argument 'xyz'.*" - } - It "Should return top 1 user direct report" { - $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top 1 - $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb' - - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when top is empty" { - { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" - } - It "Should fail when top is invalid" { - { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" - } - It "Property parameter should work" { - $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property DisplayName - $result | Should -Not -BeNullOrEmpty - $result.DisplayName | Should -Be "Mock-User" - - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when Property is empty" { - { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" - } - It "Result should contain Properties" { - $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result.ObjectId | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result.DeletionTimestamp | Should -Be $null - $result.DirSyncEnabled | Should -Be $null - $result.ImmutableId | Should -Be $null - $result.LastDirSyncTime | Should -Be $null - $result.Mobile | Should -Be "425-555-0100" - $result.ProvisioningErrors | Should -BeNullOrEmpty - $result.TelephoneNumber | Should -Be "425-555-0100" - $result.UserState | Should -Be $null - $result.UserStateChangedOn | Should -Be $null - - } - It "Should contain UserId in parameters when passed UserId to it" { - - $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $params = Get-Parameters -data $result.Parameters - $para= $params | ConvertTo-json | ConvertFrom-Json - $para.URI | Should -Match "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraUserDirectReport" - $result = Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result | Should -Not -BeNullOrEmpty - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraUserDirectReport" - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { - $Headers.'User-Agent' | Should -Be $userAgentHeaderValue - $true - } - } - It "Should execute successfully without throwing an error " { - # Disable confirmation prompts - $originalDebugPreference = $DebugPreference - $DebugPreference = 'Continue' - - try { - # Act & Assert: Ensure the function doesn't throw an exception - { Get-EntraUserDirectReport -UserId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - - } - -} - diff --git a/testVNext/Entra/Governance/Get-EntraDirectoryRoleAssignment.Tests.ps1 b/testVNext/Entra/Governance/Get-EntraDirectoryRoleAssignment.Tests.ps1 deleted file mode 100644 index 932cef0a0d..0000000000 --- a/testVNext/Entra/Governance/Get-EntraDirectoryRoleAssignment.Tests.ps1 +++ /dev/null @@ -1,129 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ -BeforeAll { - if((Get-Module -Name Microsoft.Graph.Entra.Governance) -eq $null){ - Import-Module Microsoft.Graph.Entra.Governance - } - Import-Module (Join-Path $PSScriptRoot "..\..\build\Common-Functions.ps1") -Force - - $scriptblock = { - return @( - [PSCustomObject]@{ - "AppScope" = "Microsoft.Graph.PowerShell.Models.MicrosoftGraphAppScope" - "AppScopeId" = $null - "Id" = "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - "DirectoryScope" = "Microsoft.Graph.PowerShell.Models.MicrosoftGraphDirectoryObject" - "DirectoryScopeId" = "/0000aaaa-11bb-cccc-dd22-eeeeee333333" - "Condition" = $null - "Principal" = "Microsoft.Graph.PowerShell.Models.MicrosoftGraphDirectoryObject" - "PrincipalId" = "aaaaaaaa-bbbb-cccc-1111-222222222222" - "RoleDefinition" = "Microsoft.Graph.PowerShell.Models.MicrosoftGraphUnifiedRoleDefinition" - "RoleDefinitionId" = "1b1b1b1b-2222-cccc-3333-4d4d4d4d4d4d" - "AdditionalProperties" = @{"@odata.context" = "https://graph.microsoft.com/v1.0/$metadata#roleManagement/directory/roleAssignments/$entity"} - "Parameters" = $args - } - ) - } - - Mock -CommandName Get-MgRoleManagementDirectoryRoleAssignment -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.Governance -} - -Describe "Get-EntraDirectoryRoleAssignment" { - Context "Test for Get-EntraDirectoryRoleAssignment" { - It "Should return specific role assignment" { - $result = Get-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should execute successfully with Alias" { - $result = Get-EntraDirectoryRoleAssignment -Id "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when Get-EntraDirectoryRoleAssignment is empty" { - { Get-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId } | Should -Throw "Missing an argument for parameter 'UnifiedRoleAssignmentId'*" - } - It "Should fail when Get-EntraDirectoryRoleAssignment is invalid" { - { Get-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "" } | Should -Throw "Cannot bind argument to parameter 'UnifiedRoleAssignmentId' because it is an empty string." - } - It "Should return all role assignments" { - $result = Get-EntraDirectoryRoleAssignment -All - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when All is invalid" { - { Get-EntraDirectoryRoleAssignment -All XY } | Should -Throw "A positional parameter cannot be found that accepts argument 'xy'.*" - } - It "Should return top role assignment" { - $result = Get-EntraDirectoryRoleAssignment -Top 1 - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when Top is empty" { - { Get-EntraDirectoryRoleAssignment -Top } | Should -Throw "Missing an argument for parameter 'Top'*" - } - It "Should fail when Top is invalid" { - { Get-EntraDirectoryRoleAssignment -Top XY } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" - } - It "Should return specific application by filter" { - $result = Get-EntraDirectoryRoleAssignment -Filter "PrincipalId eq 'aaaaaaaa-bbbb-cccc-1111-222222222222'" - $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be 'Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2' - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when filter is empty" { - { Get-EntraDirectoryRoleAssignment -Filter } | Should -Throw "Missing an argument for parameter 'Filter'*" - } - - It "Result should Contain ObjectId" { - $result = Get-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - $result.ObjectId | should -Be "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - } - It "Should contain UnifiedRoleAssignmentId in parameters when passed Id to it" { - $result = Get-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - $params = Get-Parameters -data $result.Parameters - $params.UnifiedRoleAssignmentId | Should -Be "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - } - It "Property parameter should work" { - $result = Get-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" -Property PrincipalId - $result | Should -Not -BeNullOrEmpty - $result.PrincipalId | Should -Be 'aaaaaaaa-bbbb-cccc-1111-222222222222' - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when Property is empty" { - { Get-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDirectoryRoleAssignment" - - Get-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDirectoryRoleAssignment" - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.Governance -Times 1 -ParameterFilter { - $Headers.'User-Agent' | Should -Be $userAgentHeaderValue - $true - } - } - It "Should execute successfully without throwing an error" { - # Disable confirmation prompts - $originalDebugPreference = $DebugPreference - $DebugPreference = 'Continue' - - try { - # Act & Assert: Ensure the function doesn't throw an exception - { Get-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} diff --git a/testVNext/Entra/Governance/Get-EntraDirectoryRoleDefinition.Tests.ps1 b/testVNext/Entra/Governance/Get-EntraDirectoryRoleDefinition.Tests.ps1 deleted file mode 100644 index 068403f431..0000000000 --- a/testVNext/Entra/Governance/Get-EntraDirectoryRoleDefinition.Tests.ps1 +++ /dev/null @@ -1,145 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ -BeforeAll { - if((Get-Module -Name Microsoft.Graph.Entra.Governance) -eq $null){ - Import-Module Microsoft.Graph.Entra.Governance - } - Import-Module (Join-Path $PSScriptRoot "..\..\build\Common-Functions.ps1") -Force - - $scriptblock = { - return @( - [PSCustomObject]@{ - "RolePermissions" = @{AllowedResourceActions="System.Object[]"; Condition=""; ExcludedResourceActions=""; AdditionalProperties=""} - "Description" = "Mock-App" - "DisplayName" = "Mock-App" - "Id" = "0000aaaa-11bb-cccc-dd22-eeeeee333333" - "InheritsPermissionsFrom" = {} - "IsBuiltIn" = $False - "IsEnabled" = $False - "ResourceScopes" = {/} - "TemplateId" = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - "Version" = "2" - "RoleDefinitionId" = "00001111-aaaa-2222-bbbb-3333cccc4444" - "AdditionalProperties" = @{"@odata.context" = "https://graph.microsoft.com/v1.0/$metadata#roleManagement/directory/roleDefinitions/$entity" - "inheritsPermissionsFrom@odata.context" = "https://graph.microsoft.com/v1.0/$metadata#roleManagement/directory/roleDefinitions('54d418b2-4cc0-47ee-9b39-e8f84ed8e073')/inheritsPermissionsFrom" - } - "Parameters" = $args - } - ) - } - - Mock -CommandName Get-MgRoleManagementDirectoryRoleDefinition -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.Governance -} - -Describe "Get-EntraDirectoryRoleDefinition" { - Context "Test for Get-EntraDirectoryRoleDefinition" { - It "Should return specificrole Defination" { - $result = Get-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "0000aaaa-11bb-cccc-dd22-eeeeee333333" - $result | Should -Not -BeNullOrEmpty - $result.DisplayName | Should -Be "Mock-App" - $result.Id | Should -Be "0000aaaa-11bb-cccc-dd22-eeeeee333333" - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should return specificrole Defination With Alias" { - $result = Get-EntraDirectoryRoleDefinition -Id "0000aaaa-11bb-cccc-dd22-eeeeee333333" - $result | Should -Not -BeNullOrEmpty - $result.DisplayName | Should -Be "Mock-App" - $result.Id | Should -Be "0000aaaa-11bb-cccc-dd22-eeeeee333333" - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when UnifiedRoleDefinitionId is empty" { - { Get-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId } | Should -Throw "Missing an argument for parameter 'UnifiedRoleDefinitionId'*" - } - It "Should fail when UnifiedRoleDefinitionId is invalid" { - { Get-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "" } | Should -Throw "Cannot bind argument to parameter 'UnifiedRoleDefinitionId' because it is an empty string." - } - It "Should return all role assignments" { - $result = Get-EntraDirectoryRoleDefinition -All - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when All is invalid" { - { Get-EntraDirectoryRoleDefinition -All XY } | Should -Throw "A positional parameter cannot be found that accepts argument 'xy'.*" - } - It "Should return top role assignment" { - $result = Get-EntraDirectoryRoleDefinition -Top 1 - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when Top is empty" { - { Get-EntraDirectoryRoleDefinition -Top } | Should -Throw "Missing an argument for parameter 'Top'*" - } - It "Should fail when Top is invalid" { - { Get-EntraDirectoryRoleDefinition -Top XY } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" - } - It "Should return specific application by SearchString" { - $result = Get-EntraDirectoryRoleDefinition -SearchString 'Mock-App' - $result | Should -Not -BeNullOrEmpty - $result.DisplayName | should -Be 'Mock-App' - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when String is empty" { - { Get-EntraDirectoryRoleDefinition -SearchString } | Should -Throw "Missing an argument for parameter 'SearchString'*" - } - It "Should return specific application by filter" { - $result = Get-EntraDirectoryRoleDefinition -Filter "DisplayName eq 'Mock-App'" - $result | Should -Not -BeNullOrEmpty - $result.DisplayName | should -Be 'Mock-App' - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when filter is empty" { - { Get-EntraDirectoryRoleDefinition -Filter } | Should -Throw "Missing an argument for parameter 'Filter'*" - } - It "Result should Contain ObjectId" { - $result = Get-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "0000aaaa-11bb-cccc-dd22-eeeeee333333" - $result.ObjectId | should -Be "0000aaaa-11bb-cccc-dd22-eeeeee333333" - } - It "Should contain Filter in parameters when passed SearchString to it" { - $result = Get-EntraDirectoryRoleDefinition -SearchString 'Mock-App' - $params = Get-Parameters -data $result.Parameters - $params.Filter | Should -Match "Mock-App" - } - It "Property parameter should work" { - $result = Get-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "0000aaaa-11bb-cccc-dd22-eeeeee333333" -Property DisplayName - $result | Should -Not -BeNullOrEmpty - $result.DisplayName | Should -Be 'Mock-App' - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.Governance -Times 1 - } - It "Should fail when Property is empty" { - { Get-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "0000aaaa-11bb-cccc-dd22-eeeeee333333" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDirectoryRoleDefinition" - - Get-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "0000aaaa-11bb-cccc-dd22-eeeeee333333" - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDirectoryRoleDefinition" - - Should -Invoke -CommandName Get-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.Governance -Times 1 -ParameterFilter { - $Headers.'User-Agent' | Should -Be $userAgentHeaderValue - $true - } - } - It "Should execute successfully without throwing an error" { - # Disable confirmation prompts - $originalDebugPreference = $DebugPreference - $DebugPreference = 'Continue' - - try { - # Act & Assert: Ensure the function doesn't throw an exception - { Get-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "0000aaaa-11bb-cccc-dd22-eeeeee333333" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} From 4119c535a7a4cf841971294f5239974385e7fb91 Mon Sep 17 00:00:00 2001 From: Emmanuel Ng'ang'a <60355631+emmanuel-karanja@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:27:21 +0300 Subject: [PATCH 3/5] Clean up Entra tests --- ...move-EntraDeletedDirectoryObject.Tests.ps1 | 64 ------------------ ...ove-EntraDirectoryRoleAssignment.Tests.ps1 | 66 ------------------- ...ove-EntraDirectoryRoleDefinition.Tests.ps1 | 66 ------------------- ...tureRolloutPolicyDirectoryObject.Tests.ps1 | 59 ----------------- 4 files changed, 255 deletions(-) delete mode 100644 testVNext/Entra/DirectoryManagement/Remove-EntraDeletedDirectoryObject.Tests.ps1 delete mode 100644 testVNext/Entra/DirectoryManagement/Remove-EntraDirectoryRoleAssignment.Tests.ps1 delete mode 100644 testVNext/Entra/DirectoryManagement/Remove-EntraDirectoryRoleDefinition.Tests.ps1 delete mode 100644 testVNext/Entra/DirectoryManagement/Remove-EntraFeatureRolloutPolicyDirectoryObject.Tests.ps1 diff --git a/testVNext/Entra/DirectoryManagement/Remove-EntraDeletedDirectoryObject.Tests.ps1 b/testVNext/Entra/DirectoryManagement/Remove-EntraDeletedDirectoryObject.Tests.ps1 deleted file mode 100644 index ee39953e51..0000000000 --- a/testVNext/Entra/DirectoryManagement/Remove-EntraDeletedDirectoryObject.Tests.ps1 +++ /dev/null @@ -1,64 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ -BeforeAll { - if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ - Import-Module Microsoft.Graph.Entra - } - Import-Module (Join-Path $PSScriptRoot "..\..\build\Common-Functions.ps1") -Force - - Mock -CommandName Invoke-GraphRequest -MockWith {} -ModuleName Microsoft.Graph.Entra -} - -Describe "Remove-EntraDeletedDirectoryObject" { - Context "Test for Remove-EntraDeletedDirectoryObject" { - It "Should delete a previously deleted directory object" { - $result = Remove-EntraDeletedDirectoryObject -DirectoryObjectId "11112222-bbbb-3333-cccc-4444dddd5555" - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 - } - - It "Should execute successfully with Alias" { - $result = Remove-EntraDeletedDirectoryObject -Id "11112222-bbbb-3333-cccc-4444dddd5555" - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 - } - - It "Should fail when DirectoryObjectId is empty" { - { Remove-EntraDeletedDirectoryObject -DirectoryObjectId } | Should -Throw "Missing an argument for parameter 'DirectoryObjectId'*" - } - - It "Should fail when DirectoryObjectId is invalid" { - { Remove-EntraDeletedDirectoryObject -DirectoryObjectId "" } | Should -Throw "Cannot bind argument to parameter 'DirectoryObjectId' because it is an empty string." - } - - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraDeletedDirectoryObject" - - Remove-EntraDeletedDirectoryObject -DirectoryObjectId "11112222-bbbb-3333-cccc-4444dddd5555" - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraDeletedDirectoryObject" - - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { - $Headers.'User-Agent' | Should -Be $userAgentHeaderValue - $true - } - } - It "Should execute successfully without throwing an error" { - # Disable confirmation prompts - $originalDebugPreference = $DebugPreference - $DebugPreference = 'Continue' - - try { - # Act & Assert: Ensure the function doesn't throw an exception - { Remove-EntraDeletedDirectoryObject -DirectoryObjectId "11112222-bbbb-3333-cccc-4444dddd5555" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} - diff --git a/testVNext/Entra/DirectoryManagement/Remove-EntraDirectoryRoleAssignment.Tests.ps1 b/testVNext/Entra/DirectoryManagement/Remove-EntraDirectoryRoleAssignment.Tests.ps1 deleted file mode 100644 index 085fd324e8..0000000000 --- a/testVNext/Entra/DirectoryManagement/Remove-EntraDirectoryRoleAssignment.Tests.ps1 +++ /dev/null @@ -1,66 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ -BeforeAll { - if((Get-Module -Name Microsoft.Graph.Entra.DirectoryManagement) -eq $null){ - Import-Module Microsoft.Graph.Entra.DirectoryManagement - } - Import-Module (Join-Path $PSScriptRoot "..\..\build\Common-Functions.ps1") -Force - - Mock -CommandName Remove-MgRoleManagementDirectoryRoleAssignment -MockWith {} -ModuleName Microsoft.Graph.Entra.DirectoryManagement -} - -Describe "Remove-EntraDirectoryRoleAssignment" { - Context "Test for Remove-EntraDirectoryRoleAssignment" { - It "Should return empty object" { - $result = Remove-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Remove-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should execute successfully with Alias" { - $result = Remove-EntraDirectoryRoleAssignment -Id "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Remove-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should fail when UnifiedRoleAssignmentId is empty" { - { Remove-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId } | Should -Throw "Missing an argument for parameter 'UnifiedRoleAssignmentId'*" - } - It "Should fail when UnifiedRoleAssignmentId is invalid" { - { Remove-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "" } | Should -Throw "Cannot bind argument to parameter 'UnifiedRoleAssignmentId' because it is an empty string." - } - It "Should contain UnifiedRoleAssignmentId in parameters when passed Id to it" { - Mock -CommandName Remove-MgRoleManagementDirectoryRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra.DirectoryManagement - - $result = Remove-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - $params = Get-Parameters -data $result - $params.UnifiedRoleAssignmentId | Should -Be "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraDirectoryRoleAssignment" - - Remove-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraDirectoryRoleAssignment" - - Should -Invoke -CommandName Remove-MgRoleManagementDirectoryRoleAssignment -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 -ParameterFilter { - $Headers.'User-Agent' | Should -Be $userAgentHeaderValue - $true - } - } - It "Should execute successfully without throwing an error" { - # Disable confirmation prompts - $originalDebugPreference = $DebugPreference - $DebugPreference = 'Continue' - - try { - # Act & Assert: Ensure the function doesn't throw an exception - { Remove-EntraDirectoryRoleAssignment -UnifiedRoleAssignmentId "Aa1Bb2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_~Jj0Kk1Ll2" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} diff --git a/testVNext/Entra/DirectoryManagement/Remove-EntraDirectoryRoleDefinition.Tests.ps1 b/testVNext/Entra/DirectoryManagement/Remove-EntraDirectoryRoleDefinition.Tests.ps1 deleted file mode 100644 index 696a70a0cc..0000000000 --- a/testVNext/Entra/DirectoryManagement/Remove-EntraDirectoryRoleDefinition.Tests.ps1 +++ /dev/null @@ -1,66 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ -BeforeAll { - if((Get-Module -Name Microsoft.Graph.Entra.DirectoryManagement) -eq $null){ - Import-Module Microsoft.Graph.Entra.DirectoryManagement - } - Import-Module (Join-Path $PSScriptRoot "..\..\build\Common-Functions.ps1") -Force - - Mock -CommandName Remove-MgRoleManagementDirectoryRoleDefinition -MockWith {} -ModuleName Microsoft.Graph.Entra.DirectoryManagement -} - -Describe "Remove-EntraDirectoryRoleDefinition" { - Context "Test for Remove-EntraDirectoryRoleDefinition" { - It "Should return empty object" { - $result = Remove-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Remove-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should execute successfully with Alias" { - $result = Remove-EntraDirectoryRoleDefinition -Id "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Remove-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should fail when UnifiedRoleDefinitionId is empty" { - { Remove-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId } | Should -Throw "Missing an argument for parameter 'UnifiedRoleDefinitionId'*" - } - It "Should fail when UnifiedRoleDefinitionId is invalid" { - { Remove-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "" } | Should -Throw "Cannot bind argument to parameter 'UnifiedRoleDefinitionId' because it is an empty string*" - } - It "Should contain UnifiedRoleDefinitionId in parameters when passed Id to it" { - Mock -CommandName Remove-MgRoleManagementDirectoryRoleDefinition -MockWith {$args} -ModuleName Microsoft.Graph.Entra.DirectoryManagement - - $result = Remove-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" - $params = Get-Parameters -data $result - $params.UnifiedRoleDefinitionId | Should -Be "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraDirectoryRoleDefinition" - - Remove-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraDirectoryRoleDefinition" - - Should -Invoke -CommandName Remove-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 -ParameterFilter { - $Headers.'User-Agent' | Should -Be $userAgentHeaderValue - $true - } - } - It "Should execute successfully without throwing an error" { - # Disable confirmation prompts - $originalDebugPreference = $DebugPreference - $DebugPreference = 'Continue' - - try { - # Act & Assert: Ensure the function doesn't throw an exception - { Remove-EntraDirectoryRoleDefinition -UnifiedRoleDefinitionId "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} diff --git a/testVNext/Entra/DirectoryManagement/Remove-EntraFeatureRolloutPolicyDirectoryObject.Tests.ps1 b/testVNext/Entra/DirectoryManagement/Remove-EntraFeatureRolloutPolicyDirectoryObject.Tests.ps1 deleted file mode 100644 index abdd91c9db..0000000000 --- a/testVNext/Entra/DirectoryManagement/Remove-EntraFeatureRolloutPolicyDirectoryObject.Tests.ps1 +++ /dev/null @@ -1,59 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ - -BeforeAll { - if((Get-Module -Name Microsoft.Graph.Entra.DirectoryManagement) -eq $null){ - Import-Module Microsoft.Graph.Entra.DirectoryManagement - } - Import-Module (Join-Path $PSScriptRoot "..\..\build\Common-Functions.ps1") -Force - - Mock -CommandName Invoke-GraphRequest -MockWith {} -ModuleName Microsoft.Graph.Entra.DirectoryManagement -} - -Describe "Remove-EntraFeatureRolloutPolicyDirectoryObject" { - Context "Test for Remove-EntraFeatureRolloutPolicyDirectoryObject" { - It "Should return empty object" { - $result = Remove-EntraFeatureRolloutPolicyDirectoryObject -Id bbbbbbbb-1111-2222-3333-cccccccccccc -ObjectId bbbbbbbb-1111-2222-3333-aaaaaaaaaaaa - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should fail when Id is invalid" { - { Remove-EntraFeatureRolloutPolicyDirectoryObject -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." - } - It "Should fail when Id is empty" { - { Remove-EntraFeatureRolloutPolicyDirectoryObject -Id } | Should -Throw "Missing an argument for parameter 'Id'*" - } - It "Should fail when ObjectId is invalid" { - { Remove-EntraFeatureRolloutPolicyDirectoryObject -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." - } - It "Should fail when ObjectId is empty" { - { Remove-EntraFeatureRolloutPolicyDirectoryObject -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraFeatureRolloutPolicyDirectoryObject" - $result = Remove-EntraFeatureRolloutPolicyDirectoryObject -Id bbbbbbbb-1111-2222-3333-cccccccccccc -ObjectId bbbbbbbb-1111-2222-3333-aaaaaaaaaaaa - $result | Should -BeNullOrEmpty - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraFeatureRolloutPolicyDirectoryObject" - Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 -ParameterFilter { - $Headers.'User-Agent' | Should -Be $userAgentHeaderValue - $true - } - } - It "Should execute successfully without throwing an error " { - # Disable confirmation prompts - $originalDebugPreference = $DebugPreference - $DebugPreference = 'Continue' - - try { - # Act & Assert: Ensure the function doesn't throw an exception - { Remove-EntraFeatureRolloutPolicyDirectoryObject -Id bbbbbbbb-1111-2222-3333-cccccccccccc -ObjectId bbbbbbbb-1111-2222-3333-aaaaaaaaaaaa -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} - From 1f8c601844f0a2e2e310a9eb1b3e19cb71ccbbb9 Mon Sep 17 00:00:00 2001 From: Emmanuel Ng'ang'a <60355631+emmanuel-karanja@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:37:56 +0300 Subject: [PATCH 4/5] Clean up Entra tests --- ...New-EntraDirectoryRoleDefinition.Tests.ps1 | 130 ------------------ 1 file changed, 130 deletions(-) delete mode 100644 testVNext/Entra/DirectoryManagement/New-EntraDirectoryRoleDefinition.Tests.ps1 diff --git a/testVNext/Entra/DirectoryManagement/New-EntraDirectoryRoleDefinition.Tests.ps1 b/testVNext/Entra/DirectoryManagement/New-EntraDirectoryRoleDefinition.Tests.ps1 deleted file mode 100644 index dccea60aca..0000000000 --- a/testVNext/Entra/DirectoryManagement/New-EntraDirectoryRoleDefinition.Tests.ps1 +++ /dev/null @@ -1,130 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ -BeforeAll { - if((Get-Module -Name Microsoft.Graph.Entra.DirectoryManagement) -eq $null){ - Import-Module Microsoft.Graph.Entra.DirectoryManagement - } - Import-Module (Join-Path $PSScriptRoot "..\..\build\Common-Functions.ps1") -Force - - $scriptblock = { - return @( - [PSCustomObject]@{ - "RolePermissions" = {"Microsoft.Graph.PowerShell.Models.MicrosoftGraphUnifiedRolePermission"} - "Description" = "Mock-App" - "DisplayName" = "Mock-App" - "Id" = "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" - "InheritsPermissionsFrom" = {} - "IsBuiltIn" = $False - "IsEnabled" = $False - "ResourceScopes" = {/} - "TemplateId" = "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" - "Version" = "2" - "RoleDefinitionId" = "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" - "AdditionalProperties" = @{"@odata.context" = "https://graph.microsoft.com/v1.0/$metadata#roleManagement/directory/roleDefinitions/$entity" - } - "Parameters" = $args - } - ) - } - - Mock -CommandName New-MgRoleManagementDirectoryRoleDefinition -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.DirectoryManagement -} - -Describe "New-EntraDirectoryRoleDefinition" { - Context "Test for New-EntraDirectoryRoleDefinition" { - It "Should return specific Ms role Defination" { - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - $result = New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName 'Mock-App' -ResourceScopes "/" -Description "Mock-App" -TemplateId "4dd5aa9c-cf4d-4895-a993-740d342802b1" -Version 2 - $result | Should -Not -BeNullOrEmpty - $result.DisplayName | Should -Be "Mock-App" - $result.Id | Should -Be "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" - $result.IsEnabled | Should -Be $False - $result.TemplateId | Should -Be "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" - $result.Version | Should -Be 2 - - - Should -Invoke -CommandName New-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 - } - It "Should fail when RolePermissions is empty" { - {New-EntraDirectoryRoleDefinition -RolePermissions -IsEnabled $false -DisplayName 'Mock-App' -ResourceScopes "/" -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2} | Should -Throw "Missing an argument for parameter 'RolePermissions'*" - } - It "Should fail when IsEnabled is empty" { - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - {New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled -DisplayName 'Mock-App' -ResourceScopes "/" -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2} | Should -Throw "Missing an argument for parameter 'IsEnabled'*" - } - It "Should fail when IsEnabled is invalid" { - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - {New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled xy -DisplayName 'Mock-App' -ResourceScopes "/" -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2} | Should -Throw "Cannot process argument transformation on parameter 'IsEnabled'*" - } - It "Should fail when DisplayName is empty" { - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - {New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName -ResourceScopes "/" -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2} | Should -Throw "Missing an argument for parameter 'DisplayName'*" - } - It "Should fail when DisplayName is invalid" { - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - {New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName "" -ResourceScopes "/" -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2} | Should -Throw "Cannot bind argument to parameter 'DisplayName' because it is an empty string." - } - It "Should fail when ResourceScopes is empty" { - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - {New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName 'Mock-App' -ResourceScopes -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2} | Should -Throw "Missing an argument for parameter 'ResourceScopes'*" - } - It "Should fail when Description is empty" { - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - {New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName 'Mock-App' -ResourceScopes "/" -Description -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2} | Should -Throw "Missing an argument for parameter 'Description'*" - } - It "Should fail when TemplateId is empty" { - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - {New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName 'Mock-App' -ResourceScopes "/" -Description "Mock-App" -TemplateId -Version 2} | Should -Throw "Missing an argument for parameter 'TemplateId'*" - } - It "Should fail when Version is empty" { - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - {New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName 'Mock-App' -ResourceScopes "/" -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff"-Version } | Should -Throw "Missing an argument for parameter 'Version'*" - } - It "Result should Contain ObjectId" { - $result = $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - $result = New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName 'Mock-App' -ResourceScopes "/" -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2 - $result.ObjectId | should -Be "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraDirectoryRoleDefinition" - - $result = $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - $result = New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName 'Mock-App' -ResourceScopes "/" -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2 - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraDirectoryRoleDefinition" - - Should -Invoke -CommandName New-MgRoleManagementDirectoryRoleDefinition -ModuleName Microsoft.Graph.Entra.DirectoryManagement -Times 1 -ParameterFilter { - $Headers.'User-Agent' | Should -Be $userAgentHeaderValue - $true - } - } - It "Should execute successfully without throwing an error" { - # Disable confirmation prompts - $originalDebugPreference = $DebugPreference - $DebugPreference = 'Continue' - $RolePermissions = New-object Microsoft.Open.MSGraph.Model.RolePermission - $RolePermissions.AllowedResourceActions = @("microsoft.directory/applications/basic/read") - - try { - # Act & Assert: Ensure the function doesn't throw an exception - { New-EntraDirectoryRoleDefinition -RolePermissions $RolePermissions -IsEnabled $false -DisplayName 'Mock-App' -ResourceScopes "/" -Description "Mock-App" -TemplateId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Version 2 -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} - From f2275a282c0ada7546812898cf479f0d219fc01c Mon Sep 17 00:00:00 2001 From: Emmanuel Ng'ang'a <60355631+emmanuel-karanja@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:25:20 +0300 Subject: [PATCH 5/5] Split clean up --- .../Groups/Get-EntraAuthorizationPolicy.ps1 | 50 ++++++++++++++++++ .../Restore-EntraDeletedDirectoryObject.ps1 | 52 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 moduleVNext/Entra/Microsoft.Graph.Entra/Groups/Get-EntraAuthorizationPolicy.ps1 create mode 100644 moduleVNext/Entra/Microsoft.Graph.Entra/SignIns/Restore-EntraDeletedDirectoryObject.ps1 diff --git a/moduleVNext/Entra/Microsoft.Graph.Entra/Groups/Get-EntraAuthorizationPolicy.ps1 b/moduleVNext/Entra/Microsoft.Graph.Entra/Groups/Get-EntraAuthorizationPolicy.ps1 new file mode 100644 index 0000000000..61325dc14f --- /dev/null +++ b/moduleVNext/Entra/Microsoft.Graph.Entra/Groups/Get-EntraAuthorizationPolicy.ps1 @@ -0,0 +1,50 @@ +function Get-EntraAuthorizationPolicy { + [CmdletBinding(DefaultParameterSetName = '')] + param ( + [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [System.String] $Id, + [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)] + [System.String[]] $Property + ) + + PROCESS { + $params = @{} + $customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand + $params["Uri"] = "https://graph.microsoft.com/v1.0/policies/authorizationPolicy?" + $params["Method"] = "GET" + + if($null -ne $PSBoundParameters["Id"]) + { + $Id = $Id.Substring(0, 1).ToLower() + $Id.Substring(1) + $Filter = "Id eq '$Id'" + $f = '$' + 'Filter' + $params["Uri"] += "&$f=$Filter" + } + if($null -ne $PSBoundParameters["Property"]) + { + $selectProperties = $PSBoundParameters["Property"] + $selectProperties = $selectProperties -Join ',' + $properties = "`$select=$($selectProperties)" + $params["Uri"] += "&$properties" + } + + Write-Debug("============================ TRANSFORMATIONS ============================") + $params.Keys | ForEach-Object {"$_ : $($params[$_])" } | Write-Debug + Write-Debug("=========================================================================`n") + + $response = Invoke-GraphRequest @params -Headers $customHeaders | ConvertTo-Json | ConvertFrom-Json + if($response){ + $policyList = @() + foreach ($data in $response) { + $policyType = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphAuthorizationPolicy + $data.PSObject.Properties | ForEach-Object { + $propertyName = $_.Name + $propertyValue = $_.Value + $policyType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force + } + $policyList += $policyType + } + $policyList + } + } +}# ------------------------------------------------------------------------------ diff --git a/moduleVNext/Entra/Microsoft.Graph.Entra/SignIns/Restore-EntraDeletedDirectoryObject.ps1 b/moduleVNext/Entra/Microsoft.Graph.Entra/SignIns/Restore-EntraDeletedDirectoryObject.ps1 new file mode 100644 index 0000000000..3d515e7353 --- /dev/null +++ b/moduleVNext/Entra/Microsoft.Graph.Entra/SignIns/Restore-EntraDeletedDirectoryObject.ps1 @@ -0,0 +1,52 @@ +function Restore-EntraDeletedDirectoryObject { + [CmdletBinding(DefaultParameterSetName = '')] + param ( + [Alias('ObjectId')] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [System.String] $Id, + [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [switch] $AutoReconcileProxyConflict + ) + + PROCESS { + $params = @{} + $customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand + $params["Uri"] = 'https://graph.microsoft.com/v1.0/directory/deletedItems/' + $params["Method"] = "POST" + if($null -ne $PSBoundParameters["Id"]) + { + $params["Uri"] += $Id+"/microsoft.graph.restore" + } + if($PSBoundParameters.ContainsKey("AutoReconcileProxyConflict")) + { + $params["Body"] = @{ + autoReconcileProxyConflict = $true + } + } + + Write-Debug("============================ TRANSFORMATIONS ============================") + $params.Keys | ForEach-Object {"$_ : $($params[$_])" } | Write-Debug + Write-Debug("=========================================================================`n") + + $response = Invoke-GraphRequest @params -Headers $customHeaders + $data = $response | ConvertTo-Json -Depth 10 | ConvertFrom-Json + $data | ForEach-Object { + if($null -ne $_) { + Add-Member -InputObject $_ -MemberType AliasProperty -Name ObjectId -Value Id + + } + } + $userList = @() + foreach ($res in $data) { + $userType = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphDirectoryObject + $res.PSObject.Properties | ForEach-Object { + $propertyName = $_.Name.Substring(0,1).ToUpper() + $_.Name.Substring(1) + $propertyValue = $_.Value + $userType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force + } + $userList += $userType + } + $userList + } +}# ------------------------------------------------------------------------------ +