From 22313090edd17c0ffeebdc207d5235cd74593582 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Wed, 8 May 2024 17:51:01 +0530 Subject: [PATCH 01/10] Added mock test for Get-EntraServiceAppRoleAssigne,Get-EntraServiceAppRoleAssignedTo Remove-EntraServiceAppRoleAssignment --- ...et-EntraServiceAppRoleAssignedTo.Tests.ps1 | 87 +++++++++++++++++++ ...et-EntraServiceAppRoleAssignment.Tests.ps1 | 87 +++++++++++++++++++ ...ve-EntraServiceAppRoleAssignment.Tests.ps1 | 46 ++++++++++ 3 files changed, 220 insertions(+) create mode 100644 test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 create mode 100644 test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 create mode 100644 test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 new file mode 100644 index 000000000..c1887e2ba --- /dev/null +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 @@ -0,0 +1,87 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + # Write-Host "Mocking Get-EntraServiceAppRoleAssignedTo with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "AppRoleId" = "bdd80a03-d9bc-451d-b7c4-ce7c63fe3c8f" + "Id" = "I8uPTcetR02TKCQg6xB170ZWgaqJluBEqPHHxTxJ9Hs" + "PrincipalDisplayName" = "Entra-App-Testing" + "PrincipalType" = "ServicePrincipal" + "ResourceDisplayName" = "Microsoft Graph" + "PrincipalId" = "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + "ResourceId" = "7af1d6f7-755a-4803-a078-a4f5a431ad51" + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraServiceAppRoleAssignedTo" { + Context "Test for Get-EntraServiceAppRoleAssignedTo" { + It "Should return app role assignments" { + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result | Should -Not -BeNullOrEmpty + $result.PrincipalId | should -Be '4d8fcb23-adc7-4d47-9328-2420eb1075ef' + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" + } + It "Should fail when ObjectId is invalid" { + {Get-EntraServiceAppRoleAssignedTo -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + } + It "Should return all app role assignments" { + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All $true + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should fail when All is invalid" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All xyz} | Should -Throw "Cannot process argument transformation on parameter 'All'.*" + } + It "Should return top app role assignments " { + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -top 1 + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Top is empty" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + } + It "Should fail when Top is invalid" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + } + It "Result should Contain ObjectId" { + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result.ObjectId | should -Be "I8uPTcetR02TKCQg6xB170ZWgaqJluBEqPHHxTxJ9Hs" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $params = Get-Parameters -data $result + $params.ServicePrincipalId | Should -Be "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + } + + It "Should contain 'User-Agent' header" { + Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignedTo" + + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 new file mode 100644 index 000000000..b68b847b0 --- /dev/null +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 @@ -0,0 +1,87 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + # Write-Host "Mocking Get-EntraServiceAppRoleAssignment with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "AppRoleId" = "00000000-0000-0000-0000-000000000000" + "Id" = "qjltmaz9l02qPcgftHNirITXiOnmHR5GmW_oEXl_ZL8" + "PrincipalDisplayName" = "MOD Administrator" + "PrincipalType" = "User" + "ResourceDisplayName" = "ProvisioningPowerBi" + "PrincipalId" = "996d39aa-fdac-4d97-aa3d-c81fb47362ac" + "ResourceId" = "021510b7-e753-40aa-b668-29753295ca34" + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraServiceAppRoleAssigned" { + Context "Test for Get-EntraServiceAppRoleAssigned" { + It "Should return service principal application role assignment." { + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result | Should -Not -BeNullOrEmpty + $result.ResourceId | should -Be '021510b7-e753-40aa-b668-29753295ca34' + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraServiceAppRoleAssignment -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" + } + It "Should fail when ObjectId is invalid" { + { Get-EntraServiceAppRoleAssignment -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + } + It "Should return all service principal application role assignment." { + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All $true + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should fail when All is invalid" { + { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All xyz} | Should -Throw "Cannot process argument transformation on parameter 'All'.*" + } + It "Should return top service principal application role assignment." { + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -top 1 + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Top is empty" { + { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + } + It "Should fail when Top is invalid" { + { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + } + It "Result should Contain ObjectId" { + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result.ObjectId | should -Be "qjltmaz9l02qPcgftHNirITXiOnmHR5GmW_oEXl_ZL8" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $params = Get-Parameters -data $result + $params.ServicePrincipalId | Should -Be "021510b7-e753-40aa-b668-29753295ca34" + } + + It "Should contain 'User-Agent' header" { + Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignment" + + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 new file mode 100644 index 000000000..7cdfc0dc0 --- /dev/null +++ b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 @@ -0,0 +1,46 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {} -ModuleName Microsoft.Graph.Entra +} +Describe "Remove-EntraServiceAppRoleAssignment" { + Context "Test for Remove-EntraServiceAppRoleAssignment" { + It "Should return empty object" { + $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Remove-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + + It "Should fail when ObjectId is empty" { + { Remove-EntraServiceAppRoleAssignment -ObjectId -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww"}| Should -Throw "Missing an argument for parameter 'ObjectId'.*" + } + It "Should fail when ObjectId is invalid" { + { Remove-EntraServiceAppRoleAssignment -ObjectId "" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + } + It "Should fail when AppRoleAssignmentId is empty" { + { Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId }| Should -Throw "Missing an argument for parameter 'AppRoleAssignmentId'.*" + } + It "Should fail when AppRoleAssignmentId is invalid" { + { Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "" } | Should -Throw "Cannot bind argument to parameter 'AppRoleAssignmentId' because it is an empty string.*" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $params = Get-Parameters -data $result + $params.ServicePrincipalId | Should -Be "cc7fcc82-ac1b-4785-af47-2ca3b7052886" + + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServiceAppRoleAssignment" + $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file From 91b7542ea8754c0b5b2733df8cefba3ec1987513 Mon Sep 17 00:00:00 2001 From: v-uansari Date: Wed, 7 Aug 2024 16:33:31 +0530 Subject: [PATCH 02/10] test fix --- .../Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 | 10 ++-------- .../Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 | 9 ++------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 index c1887e2ba..35cbea1f7 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 @@ -39,17 +39,11 @@ Describe "Get-EntraServiceAppRoleAssignedTo" { {Get-EntraServiceAppRoleAssignedTo -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should return all app role assignments" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All $true + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when All is empty" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All } | Should -Throw "Missing an argument for parameter 'All'*" - } - It "Should fail when All is invalid" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All xyz} | Should -Throw "Cannot process argument transformation on parameter 'All'.*" - } + } It "Should return top app role assignments " { $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -top 1 $result | Should -Not -BeNullOrEmpty diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 index b68b847b0..a4c66f8e4 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 @@ -39,17 +39,12 @@ Describe "Get-EntraServiceAppRoleAssigned" { { Get-EntraServiceAppRoleAssignment -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should return all service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All $true + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 } - It "Should fail when All is empty" { - { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All } | Should -Throw "Missing an argument for parameter 'All'*" - } - It "Should fail when All is invalid" { - { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All xyz} | Should -Throw "Cannot process argument transformation on parameter 'All'.*" - } + It "Should return top service principal application role assignment." { $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -top 1 $result | Should -Not -BeNullOrEmpty From 73d3977bbd0b4f01f416407253dc88c2558de00f Mon Sep 17 00:00:00 2001 From: v-uansari Date: Thu, 8 Aug 2024 12:33:46 +0530 Subject: [PATCH 03/10] added licance --- test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 | 3 +++ test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 | 3 +++ .../Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 | 3 +++ 3 files changed, 9 insertions(+) diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 index 35cbea1f7..04981aa1a 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 @@ -1,3 +1,6 @@ +# ------------------------------------------------------------------------------ +# 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 diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 index a4c66f8e4..97cc5f65d 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 @@ -1,3 +1,6 @@ +# ------------------------------------------------------------------------------ +# 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 diff --git a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 index 7cdfc0dc0..d2e861f2a 100644 --- a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 @@ -1,3 +1,6 @@ +# ------------------------------------------------------------------------------ +# 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 From e61b6c53c4a94480a850e55bcb69ef6d1b7df71d Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Wed, 8 May 2024 17:51:01 +0530 Subject: [PATCH 04/10] Added mock test for Get-EntraServiceAppRoleAssigne,Get-EntraServiceAppRoleAssignedTo Remove-EntraServiceAppRoleAssignment --- ...et-EntraServiceAppRoleAssignedTo.Tests.ps1 | 87 +++++++++++++++++++ ...et-EntraServiceAppRoleAssignment.Tests.ps1 | 87 +++++++++++++++++++ ...ve-EntraServiceAppRoleAssignment.Tests.ps1 | 46 ++++++++++ 3 files changed, 220 insertions(+) create mode 100644 test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 create mode 100644 test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 create mode 100644 test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 new file mode 100644 index 000000000..c1887e2ba --- /dev/null +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 @@ -0,0 +1,87 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + # Write-Host "Mocking Get-EntraServiceAppRoleAssignedTo with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "AppRoleId" = "bdd80a03-d9bc-451d-b7c4-ce7c63fe3c8f" + "Id" = "I8uPTcetR02TKCQg6xB170ZWgaqJluBEqPHHxTxJ9Hs" + "PrincipalDisplayName" = "Entra-App-Testing" + "PrincipalType" = "ServicePrincipal" + "ResourceDisplayName" = "Microsoft Graph" + "PrincipalId" = "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + "ResourceId" = "7af1d6f7-755a-4803-a078-a4f5a431ad51" + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraServiceAppRoleAssignedTo" { + Context "Test for Get-EntraServiceAppRoleAssignedTo" { + It "Should return app role assignments" { + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result | Should -Not -BeNullOrEmpty + $result.PrincipalId | should -Be '4d8fcb23-adc7-4d47-9328-2420eb1075ef' + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" + } + It "Should fail when ObjectId is invalid" { + {Get-EntraServiceAppRoleAssignedTo -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + } + It "Should return all app role assignments" { + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All $true + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should fail when All is invalid" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All xyz} | Should -Throw "Cannot process argument transformation on parameter 'All'.*" + } + It "Should return top app role assignments " { + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -top 1 + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Top is empty" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + } + It "Should fail when Top is invalid" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + } + It "Result should Contain ObjectId" { + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result.ObjectId | should -Be "I8uPTcetR02TKCQg6xB170ZWgaqJluBEqPHHxTxJ9Hs" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $params = Get-Parameters -data $result + $params.ServicePrincipalId | Should -Be "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + } + + It "Should contain 'User-Agent' header" { + Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignedTo" + + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 new file mode 100644 index 000000000..b68b847b0 --- /dev/null +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 @@ -0,0 +1,87 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + # Write-Host "Mocking Get-EntraServiceAppRoleAssignment with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "AppRoleId" = "00000000-0000-0000-0000-000000000000" + "Id" = "qjltmaz9l02qPcgftHNirITXiOnmHR5GmW_oEXl_ZL8" + "PrincipalDisplayName" = "MOD Administrator" + "PrincipalType" = "User" + "ResourceDisplayName" = "ProvisioningPowerBi" + "PrincipalId" = "996d39aa-fdac-4d97-aa3d-c81fb47362ac" + "ResourceId" = "021510b7-e753-40aa-b668-29753295ca34" + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraServiceAppRoleAssigned" { + Context "Test for Get-EntraServiceAppRoleAssigned" { + It "Should return service principal application role assignment." { + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result | Should -Not -BeNullOrEmpty + $result.ResourceId | should -Be '021510b7-e753-40aa-b668-29753295ca34' + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraServiceAppRoleAssignment -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" + } + It "Should fail when ObjectId is invalid" { + { Get-EntraServiceAppRoleAssignment -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + } + It "Should return all service principal application role assignment." { + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All $true + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should fail when All is invalid" { + { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All xyz} | Should -Throw "Cannot process argument transformation on parameter 'All'.*" + } + It "Should return top service principal application role assignment." { + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -top 1 + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Top is empty" { + { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + } + It "Should fail when Top is invalid" { + { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + } + It "Result should Contain ObjectId" { + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result.ObjectId | should -Be "qjltmaz9l02qPcgftHNirITXiOnmHR5GmW_oEXl_ZL8" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $params = Get-Parameters -data $result + $params.ServicePrincipalId | Should -Be "021510b7-e753-40aa-b668-29753295ca34" + } + + It "Should contain 'User-Agent' header" { + Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignment" + + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 new file mode 100644 index 000000000..7cdfc0dc0 --- /dev/null +++ b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 @@ -0,0 +1,46 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {} -ModuleName Microsoft.Graph.Entra +} +Describe "Remove-EntraServiceAppRoleAssignment" { + Context "Test for Remove-EntraServiceAppRoleAssignment" { + It "Should return empty object" { + $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Remove-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + + It "Should fail when ObjectId is empty" { + { Remove-EntraServiceAppRoleAssignment -ObjectId -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww"}| Should -Throw "Missing an argument for parameter 'ObjectId'.*" + } + It "Should fail when ObjectId is invalid" { + { Remove-EntraServiceAppRoleAssignment -ObjectId "" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + } + It "Should fail when AppRoleAssignmentId is empty" { + { Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId }| Should -Throw "Missing an argument for parameter 'AppRoleAssignmentId'.*" + } + It "Should fail when AppRoleAssignmentId is invalid" { + { Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "" } | Should -Throw "Cannot bind argument to parameter 'AppRoleAssignmentId' because it is an empty string.*" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $params = Get-Parameters -data $result + $params.ServicePrincipalId | Should -Be "cc7fcc82-ac1b-4785-af47-2ca3b7052886" + + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServiceAppRoleAssignment" + $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file From 606f8369ae9fc04a0a706ad30024922520a9e659 Mon Sep 17 00:00:00 2001 From: v-uansari Date: Wed, 7 Aug 2024 16:33:31 +0530 Subject: [PATCH 05/10] test fix --- .../Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 | 10 ++-------- .../Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 | 9 ++------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 index c1887e2ba..35cbea1f7 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 @@ -39,17 +39,11 @@ Describe "Get-EntraServiceAppRoleAssignedTo" { {Get-EntraServiceAppRoleAssignedTo -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should return all app role assignments" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All $true + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when All is empty" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All } | Should -Throw "Missing an argument for parameter 'All'*" - } - It "Should fail when All is invalid" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All xyz} | Should -Throw "Cannot process argument transformation on parameter 'All'.*" - } + } It "Should return top app role assignments " { $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -top 1 $result | Should -Not -BeNullOrEmpty diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 index b68b847b0..a4c66f8e4 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 @@ -39,17 +39,12 @@ Describe "Get-EntraServiceAppRoleAssigned" { { Get-EntraServiceAppRoleAssignment -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should return all service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All $true + $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 } - It "Should fail when All is empty" { - { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All } | Should -Throw "Missing an argument for parameter 'All'*" - } - It "Should fail when All is invalid" { - { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All xyz} | Should -Throw "Cannot process argument transformation on parameter 'All'.*" - } + It "Should return top service principal application role assignment." { $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -top 1 $result | Should -Not -BeNullOrEmpty From 3e2fe6ca8a37317a7869c0edf32d79e5466d91bf Mon Sep 17 00:00:00 2001 From: v-uansari Date: Thu, 8 Aug 2024 12:33:46 +0530 Subject: [PATCH 06/10] added licance --- test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 | 3 +++ test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 | 3 +++ .../Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 | 3 +++ 3 files changed, 9 insertions(+) diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 index 35cbea1f7..04981aa1a 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 @@ -1,3 +1,6 @@ +# ------------------------------------------------------------------------------ +# 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 diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 index a4c66f8e4..97cc5f65d 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 @@ -1,3 +1,6 @@ +# ------------------------------------------------------------------------------ +# 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 diff --git a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 index 7cdfc0dc0..d2e861f2a 100644 --- a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 @@ -1,3 +1,6 @@ +# ------------------------------------------------------------------------------ +# 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 From 8e8da74ee5a6d2a2e04f934372c383404b88fba4 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Fri, 30 Aug 2024 13:16:54 +0530 Subject: [PATCH 07/10] updated test cases --- ...et-EntraServiceAppRoleAssignedTo.Tests.ps1 | 65 ++++++++++++++----- ...et-EntraServiceAppRoleAssignment.Tests.ps1 | 59 ++++++++++++----- ...ve-EntraServiceAppRoleAssignment.Tests.ps1 | 32 ++++++--- 3 files changed, 115 insertions(+), 41 deletions(-) diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 index 04981aa1a..75b47e86d 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 @@ -11,13 +11,13 @@ BeforeAll { # Write-Host "Mocking Get-EntraServiceAppRoleAssignedTo with parameters: $($args | ConvertTo-Json -Depth 3)" return @( [PSCustomObject]@{ - "AppRoleId" = "bdd80a03-d9bc-451d-b7c4-ce7c63fe3c8f" - "Id" = "I8uPTcetR02TKCQg6xB170ZWgaqJluBEqPHHxTxJ9Hs" + "AppRoleId" = "00000000-0000-0000-0000-000000000000" + "Id" = "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" "PrincipalDisplayName" = "Entra-App-Testing" "PrincipalType" = "ServicePrincipal" "ResourceDisplayName" = "Microsoft Graph" - "PrincipalId" = "4d8fcb23-adc7-4d47-9328-2420eb1075ef" - "ResourceId" = "7af1d6f7-755a-4803-a078-a4f5a431ad51" + "PrincipalId" = "aaaaaaaa-bbbb-cccc-1111-222222222222" + "ResourceId" = "bbbbbbbb-cccc-dddd-2222-333333333333" "Parameters" = $args } ) @@ -29,9 +29,9 @@ BeforeAll { Describe "Get-EntraServiceAppRoleAssignedTo" { Context "Test for Get-EntraServiceAppRoleAssignedTo" { It "Should return app role assignments" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" $result | Should -Not -BeNullOrEmpty - $result.PrincipalId | should -Be '4d8fcb23-adc7-4d47-9328-2420eb1075ef' + $result.PrincipalId | should -Be 'aaaaaaaa-bbbb-cccc-1111-222222222222' Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 } @@ -42,43 +42,74 @@ Describe "Get-EntraServiceAppRoleAssignedTo" { {Get-EntraServiceAppRoleAssignedTo -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should return all app role assignments" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 - } + } + + It "Should fail when All is invalid" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All XY } | Should -Throw "A positional parameter cannot be found that accepts argument 'xy'.*" + } + It "Should return top app role assignments " { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -top 1 + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -top 1 $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when Top is empty" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } It "Should fail when Top is invalid" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + { Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" } It "Result should Contain ObjectId" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" - $result.ObjectId | should -Be "I8uPTcetR02TKCQg6xB170ZWgaqJluBEqPHHxTxJ9Hs" + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" + $result.ObjectId | should -Be "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" } It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" $params = Get-Parameters -data $result - $params.ServicePrincipalId | Should -Be "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $params.ServicePrincipalId | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" } + It "Property parameter should work" { + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property PrincipalDisplayName + $result | Should -Not -BeNullOrEmpty + $result.PrincipalDisplayName | Should -Be 'Entra-App-Testing' + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + + It "Should fail when Property is empty" { + { Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + } + It "Should contain 'User-Agent' header" { Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignedTo" - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" $params = Get-Parameters -data $result $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } + } + + 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-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 index 97cc5f65d..b7be6ced9 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 @@ -12,12 +12,12 @@ BeforeAll { return @( [PSCustomObject]@{ "AppRoleId" = "00000000-0000-0000-0000-000000000000" - "Id" = "qjltmaz9l02qPcgftHNirITXiOnmHR5GmW_oEXl_ZL8" + "Id" = "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" "PrincipalDisplayName" = "MOD Administrator" "PrincipalType" = "User" "ResourceDisplayName" = "ProvisioningPowerBi" - "PrincipalId" = "996d39aa-fdac-4d97-aa3d-c81fb47362ac" - "ResourceId" = "021510b7-e753-40aa-b668-29753295ca34" + "PrincipalId" = "aaaaaaaa-bbbb-cccc-1111-222222222222" + "ResourceId" = "bbbbbbbb-cccc-dddd-2222-333333333333" "Parameters" = $args } ) @@ -29,9 +29,9 @@ BeforeAll { Describe "Get-EntraServiceAppRoleAssigned" { Context "Test for Get-EntraServiceAppRoleAssigned" { It "Should return service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" $result | Should -Not -BeNullOrEmpty - $result.ResourceId | should -Be '021510b7-e753-40aa-b668-29753295ca34' + $result.ResourceId | should -Be 'bbbbbbbb-cccc-dddd-2222-333333333333' Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 } @@ -42,34 +42,50 @@ Describe "Get-EntraServiceAppRoleAssigned" { { Get-EntraServiceAppRoleAssignment -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should return all service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All + $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 } - + + It "Should fail when All is invalid" { + { Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All XY } | Should -Throw "A positional parameter cannot be found that accepts argument 'xy'.*" + } + It "Should return top service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -top 1 + $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -top 1 $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when Top is empty" { - { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } It "Should fail when Top is invalid" { - { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + { Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" } It "Result should Contain ObjectId" { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" - $result.ObjectId | should -Be "qjltmaz9l02qPcgftHNirITXiOnmHR5GmW_oEXl_ZL8" + $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" + $result.ObjectId | should -Be "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" } It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" $params = Get-Parameters -data $result - $params.ServicePrincipalId | Should -Be "021510b7-e753-40aa-b668-29753295ca34" + $params.ServicePrincipalId | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" + } + + It "Property parameter should work" { + $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property PrincipalDisplayName + $result | Should -Not -BeNullOrEmpty + $result.PrincipalDisplayName | Should -Be 'MOD Administrator' + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 + } + + It "Should fail when Property is empty" { + { Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should contain 'User-Agent' header" { @@ -77,9 +93,22 @@ Describe "Get-EntraServiceAppRoleAssigned" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignment" - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" $params = Get-Parameters -data $result $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + 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-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } } } } \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 index d2e861f2a..d4e9d4cc6 100644 --- a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 @@ -12,38 +12,52 @@ BeforeAll { Describe "Remove-EntraServiceAppRoleAssignment" { Context "Test for Remove-EntraServiceAppRoleAssignment" { It "Should return empty object" { - $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $result = Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" $result | Should -BeNullOrEmpty Should -Invoke -CommandName Remove-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when ObjectId is empty" { - { Remove-EntraServiceAppRoleAssignment -ObjectId -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww"}| Should -Throw "Missing an argument for parameter 'ObjectId'.*" + { Remove-EntraServiceAppRoleAssignment -ObjectId -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u"}| Should -Throw "Missing an argument for parameter 'ObjectId'.*" } It "Should fail when ObjectId is invalid" { - { Remove-EntraServiceAppRoleAssignment -ObjectId "" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + { Remove-EntraServiceAppRoleAssignment -ObjectId "" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should fail when AppRoleAssignmentId is empty" { - { Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId }| Should -Throw "Missing an argument for parameter 'AppRoleAssignmentId'.*" + { Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId }| Should -Throw "Missing an argument for parameter 'AppRoleAssignmentId'.*" } It "Should fail when AppRoleAssignmentId is invalid" { - { Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "" } | Should -Throw "Cannot bind argument to parameter 'AppRoleAssignmentId' because it is an empty string.*" + { Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "" } | Should -Throw "Cannot bind argument to parameter 'AppRoleAssignmentId' because it is an empty string.*" } It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $result = Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" $params = Get-Parameters -data $result - $params.ServicePrincipalId | Should -Be "cc7fcc82-ac1b-4785-af47-2ca3b7052886" + $params.ServicePrincipalId | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" } It "Should contain 'User-Agent' header" { Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServiceAppRoleAssignment" - $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $result = Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" $params = Get-Parameters -data $result $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } + } + + 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-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file From 1e457570663c52bbe17a34461e59d9717647d475 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Wed, 4 Sep 2024 14:04:07 +0530 Subject: [PATCH 08/10] updated --- .../Get-EntraServiceAppRoleAssignedTo.Tests.ps1 | 14 +++++++++----- .../Get-EntraServiceAppRoleAssignment.Tests.ps1 | 15 ++++++++++----- ...Remove-EntraServiceAppRoleAssignment.Tests.ps1 | 15 ++++++++++----- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 index 75b47e86d..342c7619a 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 @@ -89,14 +89,18 @@ Describe "Get-EntraServiceAppRoleAssignedTo" { } It "Should contain 'User-Agent' header" { - Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignedTo" $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } + $result | Should -Not -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignedTo" + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -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 diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 index b7be6ced9..b733531ef 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 @@ -89,14 +89,19 @@ Describe "Get-EntraServiceAppRoleAssigned" { } It "Should contain 'User-Agent' header" { - Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignment" $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } + $result | Should -Not -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignment" + + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -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 diff --git a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 index d4e9d4cc6..4ced95d96 100644 --- a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 @@ -37,13 +37,18 @@ Describe "Remove-EntraServiceAppRoleAssignment" { $params.ServicePrincipalId | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" } + It "Should contain 'User-Agent' header" { - Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServiceAppRoleAssignment" - $result = Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + + Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServiceAppRoleAssignment" + + Should -Invoke -CommandName Remove-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } } It "Should execute successfully without throwing an error" { From c2ea4092ac559093f96aa473cbe2f73e53416d6d Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Thu, 19 Sep 2024 18:29:32 +0530 Subject: [PATCH 09/10] renamed files and cmdlets in UT --- ...rvicePrincipalAppRoleAssignedTo.Tests.ps1} | 28 +++++++++---------- ...rvicePrincipalAppRoleAssignment.Tests.ps1} | 24 ++++++++-------- ...rvicePrincipalAppRoleAssignment.Tests.ps1} | 20 ++++++------- 3 files changed, 36 insertions(+), 36 deletions(-) rename test/module/Entra/{Get-EntraServiceAppRoleAssignedTo.Tests.ps1 => Get-EntraServicePrincipalAppRoleAssignedTo.Tests.ps1} (65%) rename test/module/Entra/{Get-EntraServiceAppRoleAssignment.Tests.ps1 => Get-EntraServicePrincipalAppRoleAssignment.Tests.ps1} (68%) rename test/module/Entra/{Remove-EntraServiceAppRoleAssignment.Tests.ps1 => Remove-EntraServicePrincipalAppRoleAssignment.Tests.ps1} (53%) diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignedTo.Tests.ps1 similarity index 65% rename from test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 rename to test/module/Entra/Get-EntraServicePrincipalAppRoleAssignedTo.Tests.ps1 index 04981aa1a..be1b10fe7 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 +++ b/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignedTo.Tests.ps1 @@ -8,7 +8,7 @@ BeforeAll { Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force $scriptblock = { - # Write-Host "Mocking Get-EntraServiceAppRoleAssignedTo with parameters: $($args | ConvertTo-Json -Depth 3)" + # Write-Host "Mocking Get-EntraServicePrincipalAppRoleAssignedTo with parameters: $($args | ConvertTo-Json -Depth 3)" return @( [PSCustomObject]@{ "AppRoleId" = "bdd80a03-d9bc-451d-b7c4-ce7c63fe3c8f" @@ -26,47 +26,47 @@ BeforeAll { Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "Get-EntraServiceAppRoleAssignedTo" { - Context "Test for Get-EntraServiceAppRoleAssignedTo" { +Describe "Get-EntraServicePrincipalAppRoleAssignedTo" { + Context "Test for Get-EntraServicePrincipalAppRoleAssignedTo" { It "Should return app role assignments" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result = Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" $result | Should -Not -BeNullOrEmpty $result.PrincipalId | should -Be '4d8fcb23-adc7-4d47-9328-2420eb1075ef' Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when ObjectId is empty" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" + { Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" } It "Should fail when ObjectId is invalid" { - {Get-EntraServiceAppRoleAssignedTo -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + {Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should return all app role assignments" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All + $result = Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -All $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should return top app role assignments " { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -top 1 + $result = Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -top 1 $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when Top is empty" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } It "Should fail when Top is invalid" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + { Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" } It "Result should Contain ObjectId" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result = Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" $result.ObjectId | should -Be "I8uPTcetR02TKCQg6xB170ZWgaqJluBEqPHHxTxJ9Hs" } It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result = Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" $params = Get-Parameters -data $result $params.ServicePrincipalId | Should -Be "4d8fcb23-adc7-4d47-9328-2420eb1075ef" } @@ -74,9 +74,9 @@ Describe "Get-EntraServiceAppRoleAssignedTo" { It "Should contain 'User-Agent' header" { Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignedTo" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalAppRoleAssignedTo" - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" + $result = Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" $params = Get-Parameters -data $result $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignment.Tests.ps1 similarity index 68% rename from test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 rename to test/module/Entra/Get-EntraServicePrincipalAppRoleAssignment.Tests.ps1 index 97cc5f65d..c98ddabfb 100644 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignment.Tests.ps1 @@ -8,7 +8,7 @@ BeforeAll { Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force $scriptblock = { - # Write-Host "Mocking Get-EntraServiceAppRoleAssignment with parameters: $($args | ConvertTo-Json -Depth 3)" + # Write-Host "Mocking Get-EntraServicePrincipalAppRoleAssignment with parameters: $($args | ConvertTo-Json -Depth 3)" return @( [PSCustomObject]@{ "AppRoleId" = "00000000-0000-0000-0000-000000000000" @@ -29,45 +29,45 @@ BeforeAll { Describe "Get-EntraServiceAppRoleAssigned" { Context "Test for Get-EntraServiceAppRoleAssigned" { It "Should return service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result = Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" $result | Should -Not -BeNullOrEmpty $result.ResourceId | should -Be '021510b7-e753-40aa-b668-29753295ca34' Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when ObjectId is empty" { - { Get-EntraServiceAppRoleAssignment -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" + { Get-EntraServicePrincipalAppRoleAssignment -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" } It "Should fail when ObjectId is invalid" { - { Get-EntraServiceAppRoleAssignment -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + { Get-EntraServicePrincipalAppRoleAssignment -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should return all service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All + $result = Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -All $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should return top service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -top 1 + $result = Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -top 1 $result | Should -Not -BeNullOrEmpty Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when Top is empty" { - { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" + { Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" } It "Should fail when Top is invalid" { - { Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" + { Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" } It "Result should Contain ObjectId" { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result = Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" $result.ObjectId | should -Be "qjltmaz9l02qPcgftHNirITXiOnmHR5GmW_oEXl_ZL8" } It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result = Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" $params = Get-Parameters -data $result $params.ServicePrincipalId | Should -Be "021510b7-e753-40aa-b668-29753295ca34" } @@ -75,9 +75,9 @@ Describe "Get-EntraServiceAppRoleAssigned" { It "Should contain 'User-Agent' header" { Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignment" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalAppRoleAssignment" - $result = Get-EntraServiceAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" + $result = Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" $params = Get-Parameters -data $result $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } diff --git a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Remove-EntraServicePrincipalAppRoleAssignment.Tests.ps1 similarity index 53% rename from test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 rename to test/module/Entra/Remove-EntraServicePrincipalAppRoleAssignment.Tests.ps1 index d2e861f2a..640044344 100644 --- a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Remove-EntraServicePrincipalAppRoleAssignment.Tests.ps1 @@ -9,30 +9,30 @@ BeforeAll { Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {} -ModuleName Microsoft.Graph.Entra } -Describe "Remove-EntraServiceAppRoleAssignment" { - Context "Test for Remove-EntraServiceAppRoleAssignment" { +Describe "Remove-EntraServicePrincipalAppRoleAssignment" { + Context "Test for Remove-EntraServicePrincipalAppRoleAssignment" { It "Should return empty object" { - $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $result = Remove-EntraServicePrincipalAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" $result | Should -BeNullOrEmpty Should -Invoke -CommandName Remove-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when ObjectId is empty" { - { Remove-EntraServiceAppRoleAssignment -ObjectId -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww"}| Should -Throw "Missing an argument for parameter 'ObjectId'.*" + { Remove-EntraServicePrincipalAppRoleAssignment -ObjectId -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww"}| Should -Throw "Missing an argument for parameter 'ObjectId'.*" } It "Should fail when ObjectId is invalid" { - { Remove-EntraServiceAppRoleAssignment -ObjectId "" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" + { Remove-EntraServicePrincipalAppRoleAssignment -ObjectId "" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" } It "Should fail when AppRoleAssignmentId is empty" { - { Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId }| Should -Throw "Missing an argument for parameter 'AppRoleAssignmentId'.*" + { Remove-EntraServicePrincipalAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId }| Should -Throw "Missing an argument for parameter 'AppRoleAssignmentId'.*" } It "Should fail when AppRoleAssignmentId is invalid" { - { Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "" } | Should -Throw "Cannot bind argument to parameter 'AppRoleAssignmentId' because it is an empty string.*" + { Remove-EntraServicePrincipalAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "" } | Should -Throw "Cannot bind argument to parameter 'AppRoleAssignmentId' because it is an empty string.*" } It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $result = Remove-EntraServicePrincipalAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" $params = Get-Parameters -data $result $params.ServicePrincipalId | Should -Be "cc7fcc82-ac1b-4785-af47-2ca3b7052886" @@ -40,8 +40,8 @@ Describe "Remove-EntraServiceAppRoleAssignment" { It "Should contain 'User-Agent' header" { Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServiceAppRoleAssignment" - $result = Remove-EntraServiceAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServicePrincipalAppRoleAssignment" + $result = Remove-EntraServicePrincipalAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" $params = Get-Parameters -data $result $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } From 9df5fafb0f53c56495d7f7259fc2050263d0a6ce Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Mon, 23 Sep 2024 15:24:58 +0530 Subject: [PATCH 10/10] deleted duplicate renamed files --- ...et-EntraServiceAppRoleAssignedTo.Tests.ps1 | 119 ------------------ ...et-EntraServiceAppRoleAssignment.Tests.ps1 | 119 ------------------ ...ve-EntraServiceAppRoleAssignment.Tests.ps1 | 68 ---------- 3 files changed, 306 deletions(-) delete mode 100644 test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 delete mode 100644 test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 delete mode 100644 test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 deleted file mode 100644 index 342c7619a..000000000 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignedTo.Tests.ps1 +++ /dev/null @@ -1,119 +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 "..\Common-Functions.ps1") -Force - - $scriptblock = { - # Write-Host "Mocking Get-EntraServiceAppRoleAssignedTo with parameters: $($args | ConvertTo-Json -Depth 3)" - return @( - [PSCustomObject]@{ - "AppRoleId" = "00000000-0000-0000-0000-000000000000" - "Id" = "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" - "PrincipalDisplayName" = "Entra-App-Testing" - "PrincipalType" = "ServicePrincipal" - "ResourceDisplayName" = "Microsoft Graph" - "PrincipalId" = "aaaaaaaa-bbbb-cccc-1111-222222222222" - "ResourceId" = "bbbbbbbb-cccc-dddd-2222-333333333333" - "Parameters" = $args - } - ) - } - - Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra -} - -Describe "Get-EntraServiceAppRoleAssignedTo" { - Context "Test for Get-EntraServiceAppRoleAssignedTo" { - It "Should return app role assignments" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result | Should -Not -BeNullOrEmpty - $result.PrincipalId | should -Be 'aaaaaaaa-bbbb-cccc-1111-222222222222' - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when ObjectId is empty" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" - } - It "Should fail when ObjectId is invalid" { - {Get-EntraServiceAppRoleAssignedTo -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" - } - It "Should return all app role assignments" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 - } - - It "Should fail when All is invalid" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All XY } | Should -Throw "A positional parameter cannot be found that accepts argument 'xy'.*" - } - - It "Should return top app role assignments " { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -top 1 - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when Top is empty" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" - } - It "Should fail when Top is invalid" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" - } - It "Result should Contain ObjectId" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result.ObjectId | should -Be "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" - } - It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { - Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $params = Get-Parameters -data $result - $params.ServicePrincipalId | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - } - - It "Property parameter should work" { - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property PrincipalDisplayName - $result | Should -Not -BeNullOrEmpty - $result.PrincipalDisplayName | Should -Be 'Entra-App-Testing' - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 - } - - It "Should fail when Property is empty" { - { Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" - } - - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignedTo" - - $result = Get-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result | Should -Not -BeNullOrEmpty - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignedTo" - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -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-EntraServiceAppRoleAssignedTo -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 deleted file mode 100644 index b733531ef..000000000 --- a/test/module/Entra/Get-EntraServiceAppRoleAssignment.Tests.ps1 +++ /dev/null @@ -1,119 +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 "..\Common-Functions.ps1") -Force - - $scriptblock = { - # Write-Host "Mocking Get-EntraServiceAppRoleAssignment with parameters: $($args | ConvertTo-Json -Depth 3)" - return @( - [PSCustomObject]@{ - "AppRoleId" = "00000000-0000-0000-0000-000000000000" - "Id" = "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" - "PrincipalDisplayName" = "MOD Administrator" - "PrincipalType" = "User" - "ResourceDisplayName" = "ProvisioningPowerBi" - "PrincipalId" = "aaaaaaaa-bbbb-cccc-1111-222222222222" - "ResourceId" = "bbbbbbbb-cccc-dddd-2222-333333333333" - "Parameters" = $args - } - ) - } - - Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra -} - -Describe "Get-EntraServiceAppRoleAssigned" { - Context "Test for Get-EntraServiceAppRoleAssigned" { - It "Should return service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result | Should -Not -BeNullOrEmpty - $result.ResourceId | should -Be 'bbbbbbbb-cccc-dddd-2222-333333333333' - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when ObjectId is empty" { - { Get-EntraServiceAppRoleAssignment -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" - } - It "Should fail when ObjectId is invalid" { - { Get-EntraServiceAppRoleAssignment -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" - } - It "Should return all service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 - } - - It "Should fail when All is invalid" { - { Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -All XY } | Should -Throw "A positional parameter cannot be found that accepts argument 'xy'.*" - } - - It "Should return top service principal application role assignment." { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -top 1 - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when Top is empty" { - { Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top } | Should -Throw "Missing an argument for parameter 'Top'*" - } - It "Should fail when Top is invalid" { - { Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Top xyz } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" - } - It "Result should Contain ObjectId" { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result.ObjectId | should -Be "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" - } - It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { - Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra - - $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $params = Get-Parameters -data $result - $params.ServicePrincipalId | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - } - - It "Property parameter should work" { - $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property PrincipalDisplayName - $result | Should -Not -BeNullOrEmpty - $result.PrincipalDisplayName | Should -Be 'MOD Administrator' - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 - } - - It "Should fail when Property is empty" { - { Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" - } - - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignment" - - $result = Get-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - $result | Should -Not -BeNullOrEmpty - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServiceAppRoleAssignment" - - Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -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-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 deleted file mode 100644 index 4ced95d96..000000000 --- a/test/module/Entra/Remove-EntraServiceAppRoleAssignment.Tests.ps1 +++ /dev/null @@ -1,68 +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 "..\Common-Functions.ps1") -Force - - Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {} -ModuleName Microsoft.Graph.Entra -} -Describe "Remove-EntraServiceAppRoleAssignment" { - Context "Test for Remove-EntraServiceAppRoleAssignment" { - It "Should return empty object" { - $result = Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" - $result | Should -BeNullOrEmpty - Should -Invoke -CommandName Remove-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 - } - - It "Should fail when ObjectId is empty" { - { Remove-EntraServiceAppRoleAssignment -ObjectId -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u"}| Should -Throw "Missing an argument for parameter 'ObjectId'.*" - } - It "Should fail when ObjectId is invalid" { - { Remove-EntraServiceAppRoleAssignment -ObjectId "" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string.*" - } - It "Should fail when AppRoleAssignmentId is empty" { - { Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId }| Should -Throw "Missing an argument for parameter 'AppRoleAssignmentId'.*" - } - It "Should fail when AppRoleAssignmentId is invalid" { - { Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "" } | Should -Throw "Cannot bind argument to parameter 'AppRoleAssignmentId' because it is an empty string.*" - } - It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { - Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - - $result = Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" - $params = Get-Parameters -data $result - $params.ServicePrincipalId | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" - - } - - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServiceAppRoleAssignment" - - Remove-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServiceAppRoleAssignment" - - Should -Invoke -CommandName Remove-MgServicePrincipalAppRoleAssignment -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-EntraServiceAppRoleAssignment -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -AppRoleAssignmentId "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u" -Debug } | Should -Not -Throw - } finally { - # Restore original confirmation preference - $DebugPreference = $originalDebugPreference - } - } - } -} \ No newline at end of file