From 9e40dbe54b1802398c7105856292666ec30d6a44 Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Tue, 7 May 2024 17:26:38 +0530 Subject: [PATCH 01/11] Added unit test cases for New-MgPolicyPermissionGrantPolicy,New-EntraMSNamedLocationPolicy,Get-EntraMSPermissionGrantPolicy --- ...Get-EntraMSPermissionGrantPolicy.Tests.ps1 | 56 +++++++++++++ .../New-EntraMSNamedLocationPolicy.Tests.ps1 | 83 +++++++++++++++++++ ...New-EntraMSPermissionGrantPolicy.Tests.ps1 | 50 +++++++++++ 3 files changed, 189 insertions(+) create mode 100644 test/module/Entra/Get-EntraMSPermissionGrantPolicy.Tests.ps1 create mode 100644 test/module/Entra/New-EntraMSNamedLocationPolicy.Tests.ps1 create mode 100644 test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 diff --git a/test/module/Entra/Get-EntraMSPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/Get-EntraMSPermissionGrantPolicy.Tests.ps1 new file mode 100644 index 000000000..a7ed5549a --- /dev/null +++ b/test/module/Entra/Get-EntraMSPermissionGrantPolicy.Tests.ps1 @@ -0,0 +1,56 @@ +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 = { + return @( + [PSCustomObject]@{ + "Id" = "microsoft-all-application-permissions" + "DeletedDateTime" = "2/8/2024 6:39:16 AM" + "Description" = "Includes all application permissions (app roles), for all APIs, for any client application." + "DisplayName" = "All application permissions, for any client app" + "Excludes" = @{} + "Includes" = @("bddda1ec-0174-44d5-84e2-47fb0ac01595") + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgPolicyPermissionGrantPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraMSPermissionGrantPolicy" { + Context "Test for Get-EntraMSPermissionGrantPolicy" { + It "Should return specific PermissionGrantPolicy" { + $result = Get-EntraMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be "microsoft-all-application-permissions" + + Should -Invoke -CommandName Get-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is empty" { + { Get-EntraMSPermissionGrantPolicy -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." + } + It "Should fail when Id is empty" { + { Get-EntraMSPermissionGrantPolicy -Id } | Should -Throw "Missing an argument for parameter 'Id'. Specify a parameter of type 'System.String' and try again." + } + It "Result should Contain ObjectId" { + $result = Get-EntraMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result.ObjectId | should -Be "microsoft-all-application-permissions" + } + It "Should contain PermissionGrantPolicyId in parameters when passed ObjectId to it" { + $result = Get-EntraMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $params = Get-Parameters -data $result.Parameters + $params.PermissionGrantPolicyId | Should -Be "microsoft-all-application-permissions" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSPermissionGrantPolicy" + + $result = Get-EntraMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/New-EntraMSNamedLocationPolicy.Tests.ps1 b/test/module/Entra/New-EntraMSNamedLocationPolicy.Tests.ps1 new file mode 100644 index 000000000..d15bd8774 --- /dev/null +++ b/test/module/Entra/New-EntraMSNamedLocationPolicy.Tests.ps1 @@ -0,0 +1,83 @@ +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 = { + return @( + [PSCustomObject]@{ + "Id" = "04fee326-10cf-4211-8edd-d2bd3f4a9a9c" + "CreatedDateTime" = "5/7/2024 10:52:23 AM" + "DisplayName" = "NamedLocation" + "ModifiedDateTime" = "5/7/2024 10:52:23 AM" + "AdditionalProperties" = @{ + "isTrusted" = "False" + "ipRanges" = @( + @{"@odata.type" = "#microsoft.graph.iPv4CidrRange"; cidrAddress = 6.5.4.1 / 30 } + @{"@odata.type" = "#microsoft.graph.iPv4CidrRange"; cidrAddress = 6.5.4.2 / 30 } + ) + "countriesAndRegions" = @('US', 'ID', 'CA') + "includeUnknownCountriesAndRegions" = "True" + "countryLookupMethod" = "clientIpAddress" + } + "Parameters" = $args + } + ) + } + + Mock -CommandName New-MgIdentityConditionalAccessNamedLocation -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "New-EntraMSNamedLocationPolicy " { + Context "Test for New-EntraMSNamedLocationPolicy" { + It "Should return created NamedLocationPolicy" { + $ipRanges1 = New-Object -TypeName Microsoft.Open.MSGraph.Model.IpRange + $ipRanges1.cidrAddress = "6.5.4.1/30" + $ipRanges2 = New-Object -TypeName Microsoft.Open.MSGraph.Model.IpRange + $ipRanges2.cidrAddress = "6.5.4.2/30" + $result = New-EntraMSNamedLocationPolicy -OdataType "#microsoft.graph.ipNamedLocation" -DisplayName "NamedLocation" -IpRanges @($ipRanges1, $ipRanges2) -IsTrusted $false + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be "04fee326-10cf-4211-8edd-d2bd3f4a9a9c" + + Should -Invoke -CommandName New-MgIdentityConditionalAccessNamedLocation -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when OdataType is empty" { + { New-EntraMSNamedLocationPolicy -OdataType } | Should -Throw "Missing an argument for parameter 'OdataType'. Specify a parameter of type 'System.String' and try again." + } + It "Should fail when DisplayName is empty" { + { New-EntraMSNamedLocationPolicy -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'. Specify a parameter of type 'System.String' and try again." + } + It "Should fail when IpRanges is empty" { + { New-EntraMSNamedLocationPolicy -IpRanges } | Should -Throw "Missing an argument for parameter 'IpRanges'.*" + } + It "Should fail when IsTrusted is empty" { + { New-EntraMSNamedLocationPolicy -IsTrusted } | Should -Throw "Missing an argument for parameter 'IsTrusted'.*" + } + It "Should fail when CountriesAndRegions is empty" { + { New-EntraMSNamedLocationPolicy -CountriesAndRegions } | Should -Throw "Missing an argument for parameter 'CountriesAndRegions'.*" + } + It "Should fail when IncludeUnknownCountriesAndRegions is empty" { + { New-EntraMSNamedLocationPolicy -IncludeUnknownCountriesAndRegions } | Should -Throw "Missing an argument for parameter 'IncludeUnknownCountriesAndRegions'.*" + } + It "Result should Contain ObjectId" { + $result = New-EntraMSNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true + $result.ObjectId | should -Be "04fee326-10cf-4211-8edd-d2bd3f4a9a9c" + } + It "Should contain params inside BodyParameter" { + $result = New-EntraMSNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true + $params = Get-Parameters -data $result.Parameters + $BodyParameters = $params.BodyParameter.AdditionalProperties + $BodyParameters.includeUnknownCountriesAndRegions | Should -Be "True" + $BodyParameters.'@odata.type' | Should -Be "#microsoft.graph.countryNamedLocation" + $BodyParameters.countriesAndRegions | Should -Be @('US', 'ID', 'CA') + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSNamedLocationPolicy" + + $result = New-EntraMSNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 new file mode 100644 index 000000000..a83122271 --- /dev/null +++ b/test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 @@ -0,0 +1,50 @@ +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 = { + return @( + [PSCustomObject]@{ + "Id" = "my_new_permission_grant_policy_id" + "DeletedDateTime" = "2/8/2024 6:39:16 AM" + "Description" = "My new permission grant policy" + "DisplayName" = "My new permission grant policy" + "Excludes" = @{} + "Includes" = @("bddda1ec-0174-44d5-84e2-47fb0ac01595") + "Parameters" = $args + } + ) + } + + Mock -CommandName New-MgPolicyPermissionGrantPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "New-MgPolicyPermissionGrantPolicy" { + Context "Test for New-MgPolicyPermissionGrantPolicy" { + It "Should return created PermissionGrantPolicy" { + $result = New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be "my_new_permission_grant_policy_id" + + Should -Invoke -CommandName New-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is empty" { + { New-EntraMSPermissionGrantPolicy -Id -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + It "Should fail when DisplayName is empty" { + { New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName -Description "My new permission grant policy" } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" + } + It "Should fail when Description is empty" { + { New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description } | Should -Throw "Missing an argument for parameter 'Description'.*" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSPermissionGrantPolicy" + + $result = New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file From 8a721bd4ee2600c040605a3623852e49fe6a7d08 Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Fri, 10 May 2024 17:27:34 +0530 Subject: [PATCH 02/11] Added test cases for Set-EntraMSPermissionGrantPolicy,Add-EntraMSLifecyclePolicyGroup,New-EntraMSGroupLifecyclePolicy,Set-EntraMSGroupLifecyclePolicy,Get-EntraMSAuthorizationPolicy,Set-EntraMSAuthorizationPolicy --- .../Add-EntraMSLifecyclePolicyGroup.Tests.ps1 | 49 ++++++++++++++ .../Get-EntraMSAuthorizationPolicy.Tests.ps1 | 58 ++++++++++++++++ .../New-EntraMSGroupLifecyclePolicy.Tests.ps1 | 64 ++++++++++++++++++ ...New-EntraMSPermissionGrantPolicy.Tests.ps1 | 12 +++- .../Set-EntraMSAuthorizationPolicy.Tests.ps1 | 67 +++++++++++++++++++ .../Set-EntraMSGroupLifecyclePolicy.Tests.ps1 | 64 ++++++++++++++++++ ...Set-EntraMSPermissionGrantPolicy.Tests.ps1 | 39 +++++++++++ 7 files changed, 351 insertions(+), 2 deletions(-) create mode 100644 test/module/Entra/Add-EntraMSLifecyclePolicyGroup.Tests.ps1 create mode 100644 test/module/Entra/Get-EntraMSAuthorizationPolicy.Tests.ps1 create mode 100644 test/module/Entra/New-EntraMSGroupLifecyclePolicy.Tests.ps1 create mode 100644 test/module/Entra/Set-EntraMSAuthorizationPolicy.Tests.ps1 create mode 100644 test/module/Entra/Set-EntraMSGroupLifecyclePolicy.Tests.ps1 create mode 100644 test/module/Entra/Set-EntraMSPermissionGrantPolicy.Tests.ps1 diff --git a/test/module/Entra/Add-EntraMSLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Add-EntraMSLifecyclePolicyGroup.Tests.ps1 new file mode 100644 index 000000000..b7f644fff --- /dev/null +++ b/test/module/Entra/Add-EntraMSLifecyclePolicyGroup.Tests.ps1 @@ -0,0 +1,49 @@ +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 = { + return @( + [PSCustomObject]@{ + "Value" = "True" + "AdditionalProperties" = "{[@odata.context, https://graph.microsoft.com/v1.0/$metadata#Edm.Boolean]}" + "Parameters" = $args + } + ) + } + + Mock -CommandName Add-MgGroupToLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Add-EntraMSLifecyclePolicyGroup " { + Context "Test for Add-EntraMSLifecyclePolicyGroup" { + It "Should return created LifecyclePolicyGroup" { + $result = Add-EntraMSLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b + $result | Should -Not -BeNullOrEmpty" + $result.Value | should -Be "True" + + Should -Invoke -CommandName Add-MgGroupToLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is invalid" { + { Add-EntraMSLifecyclePolicyGroup -Id "" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + } + It "Should fail when Id is empty" { + { Add-EntraMSLifecyclePolicyGroup -Id -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + It "Should fail when GroupId is invalid" { + { Add-EntraMSLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "" } | Should -Throw "Cannot bind argument to parameter 'GroupId' because it is an empty string.*" + } + It "Should fail when GroupId is empty" { + { Add-EntraMSLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId } | Should -Throw "Missing an argument for parameter 'GroupId'.*" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraMSLifecyclePolicyGroup" + + $result = Add-EntraMSLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Get-EntraMSAuthorizationPolicy.Tests.ps1 b/test/module/Entra/Get-EntraMSAuthorizationPolicy.Tests.ps1 new file mode 100644 index 000000000..b99652a69 --- /dev/null +++ b/test/module/Entra/Get-EntraMSAuthorizationPolicy.Tests.ps1 @@ -0,0 +1,58 @@ +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 = { + return @( + [PSCustomObject]@{ + "DefaultUserRolePermissions" = @{AllowedToCreateApps = "False"; AllowedToCreateSecurityGroups = "False"; AllowedToCreateTenants = "True"; + AllowedToReadBitlockerKeysForOwnedDevice = "True"; AllowedToReadOtherUsers = "False"; PermissionGrantPoliciesAssigned = ""; + AdditionalProperties = "" + } + "DeletedDateTime" = $null + "GuestUserRoleId" = "111cc9b5-fce9-485e-9566-c68debafac5f" + "DisplayName" = "AuthorizationPolicy" + "Description" = "AuthorizationPolicy" + "AllowEmailVerifiedUsersToJoinOrganization" = $True + "AllowedToSignUpEmailBasedSubscriptions" = $True + "AllowInvitesFrom" = "everyone" + "AllowUserConsentForRiskyApps" = "" + "AllowedToUseSspr" = $True + "BlockMsolPowerShell" = $True + "Id" = "authorizationPolicy" + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgPolicyAuthorizationPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraMSAuthorizationPolicy" { + Context "Test for Get-EntraMSAuthorizationPolicy" { + It "Should return AuthorizationPolicy" { + $result = Get-EntraMSAuthorizationPolicy + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be 'authorizationPolicy' + $result.DisplayName | should -Be 'AuthorizationPolicy' + $result.Description | should -Be 'AuthorizationPolicy' + $result.AllowInvitesFrom | should -Be 'everyone' + $result.GuestUserRoleId | should -Be '111cc9b5-fce9-485e-9566-c68debafac5f' + $result.AllowEmailVerifiedUsersToJoinOrganization | should -Be $True + $result.AllowedToSignUpEmailBasedSubscriptions | should -Be $True + $result.AllowedToUseSspr | should -Be $True + $result.BlockMsolPowerShell | should -Be $True + + Should -Invoke -CommandName Get-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSAuthorizationPolicy" + + $result = Get-EntraMSAuthorizationPolicy + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/New-EntraMSGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/New-EntraMSGroupLifecyclePolicy.Tests.ps1 new file mode 100644 index 000000000..2846d9706 --- /dev/null +++ b/test/module/Entra/New-EntraMSGroupLifecyclePolicy.Tests.ps1 @@ -0,0 +1,64 @@ +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 = { + return @( + [PSCustomObject]@{ + "Id" = "a47d4510-08c8-4437-99e9-71ca88e7af0f" + "AlternateNotificationEmails" = "example@contoso.com" + "GroupLifetimeInDays" = "99" + "ManagedGroupTypes" = "Selected" + "Parameters" = $args + } + ) + } + + Mock -CommandName New-MgGroupLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "New-EntraMSGroupLifecyclePolicy " { + Context "Test for New-EntraMSGroupLifecyclePolicy" { + It "Should return created GroupLifecyclePolicy" { + $result = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + $result.GroupLifetimeInDays | should -Be "99" + $result.ManagedGroupTypes | should -Be "Selected" + $result.AlternateNotificationEmails | should -Be "example@contoso.com" + + Should -Invoke -CommandName New-MgGroupLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when GroupLifetimeInDays is invalid" { + { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot process argument transformation on parameter 'GroupLifetimeInDays'.*" + } + It "Should fail when GroupLifetimeInDays is empty" { + { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'GroupLifetimeInDays'.*" + } + It "Should fail when ManagedGroupTypes is invalid" { + { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot bind argument to parameter 'ManagedGroupTypes' because it is an empty string.*" + } + It "Should fail when ManagedGroupTypes is empty" { + { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'ManagedGroupTypes'.*" + } + It "Should fail when AlternateNotificationEmails is invalid" { + { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "" } | Should -Throw "Cannot bind argument to parameter 'AlternateNotificationEmails' because it is an empty string.*" + } + It "Should fail when AlternateNotificationEmails is empty" { + { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails } | Should -Throw "Missing an argument for parameter 'AlternateNotificationEmails'.*" + } + It "Result should Contain ObjectId" { + $result = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" + $result.ObjectId | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSGroupLifecyclePolicy" + + $result = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 index a83122271..08d480e12 100644 --- a/test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 @@ -21,12 +21,16 @@ BeforeAll { Mock -CommandName New-MgPolicyPermissionGrantPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "New-MgPolicyPermissionGrantPolicy" { - Context "Test for New-MgPolicyPermissionGrantPolicy" { +Describe "New-EntraMSPermissionGrantPolicy" { + Context "Test for New-EntraMSPermissionGrantPolicy" { It "Should return created PermissionGrantPolicy" { $result = New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" $result | Should -Not -BeNullOrEmpty $result.Id | should -Be "my_new_permission_grant_policy_id" + $result.DisplayName | should -Be "My new permission grant policy" + $result.Description | should -Be "My new permission grant policy" + $result.Includes | should -Be @("bddda1ec-0174-44d5-84e2-47fb0ac01595") + $result.DeletedDateTime | should -Be "2/8/2024 6:39:16 AM" Should -Invoke -CommandName New-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 } @@ -39,6 +43,10 @@ Describe "New-MgPolicyPermissionGrantPolicy" { It "Should fail when Description is empty" { { New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description } | Should -Throw "Missing an argument for parameter 'Description'.*" } + It "Result should Contain ObjectId" { + $result = New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" + $result.ObjectId | should -Be "my_new_permission_grant_policy_id" + } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSPermissionGrantPolicy" diff --git a/test/module/Entra/Set-EntraMSAuthorizationPolicy.Tests.ps1 b/test/module/Entra/Set-EntraMSAuthorizationPolicy.Tests.ps1 new file mode 100644 index 000000000..877a2f29a --- /dev/null +++ b/test/module/Entra/Set-EntraMSAuthorizationPolicy.Tests.ps1 @@ -0,0 +1,67 @@ +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 Update-MgPolicyAuthorizationPolicy -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Set-EntraMSAuthorizationPolicy" { + Context "Test for Set-EntraMSAuthorizationPolicy" { + It "Should update AuthorizationPolicy" { + $DefaultUserRolePermissions = New-Object -TypeName Microsoft.Open.MSGraph.Model.DefaultUserRolePermissions + $DefaultUserRolePermissions.AllowedToCreateApps = $true + $DefaultUserRolePermissions.AllowedToCreateSecurityGroups = $true + $DefaultUserRolePermissions.AllowedToReadOtherUsers = $true + $result = Set-EntraMSAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions $false -AllowedToUseSSPR $false -AllowEmailVerifiedUsersToJoinOrganization $true -BlockMsolPowerShell $true -DefaultUserRolePermissions $DefaultUserRolePermissions -Description "test" -DisplayName "Authorization Policies" + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName Update-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when AllowedToSignUpEmailBasedSubscriptions is invalid" { + { Set-EntraMSAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowedToSignUpEmailBasedSubscriptions'.*" + } + It "Should fail when AllowedToSignUpEmailBasedSubscriptions is empty" { + { Set-EntraMSAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions } | Should -Throw "Missing an argument for parameter 'AllowedToSignUpEmailBasedSubscriptions'.*" + } + It "Should fail when AllowedToUseSSPR is invalid" { + { Set-EntraMSAuthorizationPolicy -AllowedToUseSSPR 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowedToUseSSPR'*" + } + It "Should fail when AllowedToUseSSPR is empty" { + { Set-EntraMSAuthorizationPolicy -AllowedToUseSSPR } | Should -Throw "Missing an argument for parameter 'AllowedToUseSSPR'.*" + } + It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is invalid" { + { Set-EntraMSAuthorizationPolicy -AllowEmailVerifiedUsersToJoinOrganization 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowEmailVerifiedUsersToJoinOrganization'*" + } + It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is empty" { + { Set-EntraMSAuthorizationPolicy -AllowEmailVerifiedUsersToJoinOrganization } | Should -Throw "Missing an argument for parameter 'AllowEmailVerifiedUsersToJoinOrganization'.*" + } + It "Should fail when BlockMsolPowerShell is invalid" { + { Set-EntraMSAuthorizationPolicy -BlockMsolPowerShell 'a' } | Should -Throw "Cannot process argument transformation on parameter 'BlockMsolPowerShell'*" + } + It "Should fail when BlockMsolPowerShell is empty" { + { Set-EntraMSAuthorizationPolicy -BlockMsolPowerShell } | Should -Throw "Missing an argument for parameter 'BlockMsolPowerShell'.*" + } + It "Should fail when DefaultUserRolePermissions is invalid" { + { Set-EntraMSAuthorizationPolicy -DefaultUserRolePermissions 'a' } | Should -Throw "Cannot process argument transformation on parameter 'DefaultUserRolePermissions'*" + } + It "Should fail when DefaultUserRolePermissions is empty" { + { Set-EntraMSAuthorizationPolicy -DefaultUserRolePermissions } | Should -Throw "Missing an argument for parameter 'DefaultUserRolePermissions'.*" + } + It "Should fail when Description is empty" { + { Set-EntraMSAuthorizationPolicy -Description } | Should -Throw "Missing an argument for parameter 'Description'.*" + } + It "Should fail when DisplayName is empty" { + { Set-EntraMSAuthorizationPolicy -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Update-MgPolicyAuthorizationPolicy -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraMSAuthorizationPolicy" + + $result = Set-EntraMSAuthorizationPolicy + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Set-EntraMSGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/Set-EntraMSGroupLifecyclePolicy.Tests.ps1 new file mode 100644 index 000000000..d369ba6e9 --- /dev/null +++ b/test/module/Entra/Set-EntraMSGroupLifecyclePolicy.Tests.ps1 @@ -0,0 +1,64 @@ +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 = { + return @( + [PSCustomObject]@{ + "Id" = "a47d4510-08c8-4437-99e9-71ca88e7af0f" + "AlternateNotificationEmails" = "admingroup@contoso.com" + "GroupLifetimeInDays" = "100" + "ManagedGroupTypes" = "All" + "Parameters" = $args + } + ) + } + + Mock -CommandName Update-MgGroupLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Set-EntraMSGroupLifecyclePolicy " { + Context "Test for Set-EntraMSGroupLifecyclePolicy" { + It "Should return updated GroupLifecyclePolicy" { + $result = Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + $result.GroupLifetimeInDays | should -Be "100" + $result.ManagedGroupTypes | should -Be "All" + $result.AlternateNotificationEmails | should -Be "admingroup@contoso.com" + + Should -Invoke -CommandName Update-MgGroupLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is invalid" { + { Set-EntraMSGroupLifecyclePolicy -Id "" -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + } + It "Should fail when Id is empty" { + { Set-EntraMSGroupLifecyclePolicy -Id -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + It "Should fail when GroupLifetimeInDays is invalid" { + { Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot process argument transformation on parameter 'GroupLifetimeInDays'.*" + } + It "Should fail when GroupLifetimeInDays is empty" { + { Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'GroupLifetimeInDays'.*" + } + It "Should fail when ManagedGroupTypes is empty" { + { Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 99 -ManagedGroupTypes -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'ManagedGroupTypes'.*" + } + It "Should fail when AlternateNotificationEmails is empty" { + { Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails } | Should -Throw "Missing an argument for parameter 'AlternateNotificationEmails'.*" + } + It "Result should Contain ObjectId" { + $result = Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $result.ObjectId | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraMSGroupLifecyclePolicy" + + $result = Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Set-EntraMSPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/Set-EntraMSPermissionGrantPolicy.Tests.ps1 new file mode 100644 index 000000000..353d04fe3 --- /dev/null +++ b/test/module/Entra/Set-EntraMSPermissionGrantPolicy.Tests.ps1 @@ -0,0 +1,39 @@ +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 Update-MgPolicyPermissionGrantPolicy -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Set-EntraMSPermissionGrantPolicy" { + Context "Test for Set-EntraMSPermissionGrantPolicy" { + It "Should return updated PermissionGrantPolicy" { + $result = Set-EntraMSPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName "Test" + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName Update-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is empty" { + { Set-EntraMSPermissionGrantPolicy -Id -Description "test" -DisplayName "Test" } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + It "Should fail when Id is invalid" { + { Set-EntraMSPermissionGrantPolicy -Id "" -Description "test" -DisplayName "Test" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + } + It "Should fail when Description is empty" { + { Set-EntraMSPermissionGrantPolicy -Id "permission_grant_policy" -Description -DisplayName "Test" } | Should -Throw "Missing an argument for parameter 'Description'.*" + } + It "Should fail when DisplayName is empty" { + { Set-EntraMSPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Update-MgPolicyPermissionGrantPolicy -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraMSPermissionGrantPolicy" + + $result = Set-EntraMSPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName "Test" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file From 870c431f18748585f85ac3168cfc52f91688a028 Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Mon, 20 May 2024 18:07:24 +0530 Subject: [PATCH 03/11] added test case for Get-EntraMSServicePrincipalDelegatedPermissionClassification --- ...elegatedPermissionClassification.Tests.ps1 | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/module/Entra/Get-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 diff --git a/test/module/Entra/Get-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 b/test/module/Entra/Get-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 new file mode 100644 index 000000000..880f69217 --- /dev/null +++ b/test/module/Entra/Get-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 @@ -0,0 +1,65 @@ +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 = { + return @( + [PSCustomObject]@{ + "Id" = "T2qU_E28O0GgkLLIYRPsTwE" + "Classification" = "low" + "PermissionId" = "fc946a4f-bc4d-413b-a090-b2c86113ec4f" + "PermissionName" = "LicenseManager.AccessAsUser" + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraMSServicePrincipalDelegatedPermissionClassification" { + Context "Test for Get-EntraMSServicePrincipalDelegatedPermissionClassification" { + It "Should return specific ServicePrincipalDelegatedPermissionClassification" { + $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 + $result | Should -Not -BeNullOrEmpty + Write-Host ($result | convertto-json) + $result.Id | should -Be "T2qU_E28O0GgkLLIYRPsTwE" + + Should -Invoke -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ServicePrincipalId is invalid" { + { Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "" } | Should -Throw "Cannot bind argument to parameter 'ServicePrincipalId' because it is an empty string.*" + } + It "Should fail when ServicePrincipalId is empty" { + { Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId } | Should -Throw "Missing an argument for parameter 'ServicePrincipalId'.*" + } + It "Should return specific ServicePrincipalDelegatedPermissionClassification when Id passed to it" { + $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id T2qU_E28O0GgkLLIYRPsTwE + $params = Get-Parameters -data $result.Parameters + $params.DelegatedPermissionClassificationId | should -Be "T2qU_E28O0GgkLLIYRPsTwE" + } + It "Should fail when Id is invalid" { + { Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + } + It "Should fail when Id is empty" { + { Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + It "Should return specific ServicePrincipalDelegatedPermissionClassification when applied filter to it" { + $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Filter "PermissionName eq 'LicenseManager.AccessAsUser'" + $result.PermissionName | should -Be "LicenseManager.AccessAsUser" + $result.ObjectId | should -Be "T2qU_E28O0GgkLLIYRPsTwE" + } + It "Should fail when Filter is empty" { + { Get-AzureADMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Filter } | Should -Throw "Missing an argument for parameter 'Filter'.*" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSServicePrincipalDelegatedPermissionClassification" + + $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file From 88d728d26a3394958a20606ca2f38e1b8ec8cd5c Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Tue, 28 May 2024 17:26:41 +0530 Subject: [PATCH 04/11] added test case for Get-EntraBetaMSPermissionGrantPolicy --- test/module/Common-Functions.ps1 | 7 ++- ...EntraBetaMSPermissionGrantPolicy.Tests.ps1 | 56 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/module/EntraBeta/Get-EntraBetaMSPermissionGrantPolicy.Tests.ps1 diff --git a/test/module/Common-Functions.ps1 b/test/module/Common-Functions.ps1 index a899a6355..134309dae 100644 --- a/test/module/Common-Functions.ps1 +++ b/test/module/Common-Functions.ps1 @@ -1,5 +1,10 @@ $psVersion = $global:PSVersionTable.PSVersion -$entraVersion = (Get-module Microsoft.Graph.Entra | select version).Version.ToString() +if($null -ne (Get-Module -Name Microsoft.Graph.Entra.Beta)){ + $entraVersion = (Get-module Microsoft.Graph.Entra.Beta | select version).Version.ToString() +} +if($null -ne (Get-Module -Name Microsoft.Graph.Entra)){ + $entraVersion = (Get-module Microsoft.Graph.Entra | select version).Version.ToString() +} function Get-Parameters{ param( diff --git a/test/module/EntraBeta/Get-EntraBetaMSPermissionGrantPolicy.Tests.ps1 b/test/module/EntraBeta/Get-EntraBetaMSPermissionGrantPolicy.Tests.ps1 new file mode 100644 index 000000000..1cac61bc1 --- /dev/null +++ b/test/module/EntraBeta/Get-EntraBetaMSPermissionGrantPolicy.Tests.ps1 @@ -0,0 +1,56 @@ +BeforeAll { + if ((Get-Module -Name Microsoft.Graph.Entra.Beta) -eq $null) { + Import-Module Microsoft.Graph.Entra.Beta + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + return @( + [PSCustomObject]@{ + "Id" = "microsoft-all-application-permissions" + "DeletedDateTime" = "2/8/2024 6:39:16 AM" + "Description" = "Includes all application permissions (app roles), for all APIs, for any client application." + "DisplayName" = "All application permissions, for any client app" + "Excludes" = @{} + "Includes" = @("bddda1ec-0174-44d5-84e2-47fb0ac01595") + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgBetaPolicyPermissionGrantPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "Get-EntraBetaMSPermissionGrantPolicy" { + Context "Test for Get-EntraBetaMSPermissionGrantPolicy" { + It "Should return specific PermissionGrantPolicy" { + $result = Get-EntraBetaMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be "microsoft-all-application-permissions" + + Should -Invoke -CommandName Get-MgBetaPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when Id is empty" { + { Get-EntraBetaMSPermissionGrantPolicy -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." + } + It "Should fail when Id is empty" { + { Get-EntraBetaMSPermissionGrantPolicy -Id } | Should -Throw "Missing an argument for parameter 'Id'. Specify a parameter of type 'System.String' and try again." + } + It "Result should Contain ObjectId" { + $result = Get-EntraBetaMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result.ObjectId | should -Be "microsoft-all-application-permissions" + } + It "Should contain PermissionGrantPolicyId in parameters when passed ObjectId to it" { + $result = Get-EntraBetaMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $params = Get-Parameters -data $result.Parameters + $params.PermissionGrantPolicyId | Should -Be "microsoft-all-application-permissions" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaMSPermissionGrantPolicy" + + $result = Get-EntraBetaMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file From d5639b8ab1431d7c6d1b102516677f52a4ac8f7d Mon Sep 17 00:00:00 2001 From: v-uansari Date: Thu, 8 Aug 2024 13:42:33 +0530 Subject: [PATCH 05/11] added licance and removed MS --- .../Add-EntraLifecyclePolicyGroup.Tests.ps1 | 52 ++++++++++++++ .../Add-EntraMSLifecyclePolicyGroup.Tests.ps1 | 49 ------------- ...=> Get-EntraAuthorizationPolicy.Tests.ps1} | 13 ++-- ... Get-EntraPermissionGrantPolicy.Tests.ps1} | 21 +++--- ...legatedPermissionClassification.Tests.ps1} | 25 ++++--- .../New-EntraGroupLifecyclePolicy.Tests.ps1 | 67 ++++++++++++++++++ .../New-EntraMSGroupLifecyclePolicy.Tests.ps1 | 64 ----------------- ...=> New-EntraNamedLocationPolicy.Tests.ps1} | 29 ++++---- ... New-EntraPermissionGrantPolicy.Tests.ps1} | 21 +++--- .../Set-EntraAuthorizationPolicy.Tests.ps1 | 70 +++++++++++++++++++ .../Set-EntraGroupLifecyclePolicy.Tests.ps1 | 67 ++++++++++++++++++ .../Set-EntraMSAuthorizationPolicy.Tests.ps1 | 67 ------------------ .../Set-EntraMSGroupLifecyclePolicy.Tests.ps1 | 64 ----------------- ...Set-EntraMSPermissionGrantPolicy.Tests.ps1 | 39 ----------- .../Set-EntraPermissionGrantPolicy.Tests.ps1 | 42 +++++++++++ ...-EntraBetaPermissionGrantPolicy.Tests.ps1} | 21 +++--- 16 files changed, 372 insertions(+), 339 deletions(-) create mode 100644 test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 delete mode 100644 test/module/Entra/Add-EntraMSLifecyclePolicyGroup.Tests.ps1 rename test/module/Entra/{Get-EntraMSAuthorizationPolicy.Tests.ps1 => Get-EntraAuthorizationPolicy.Tests.ps1} (83%) rename test/module/Entra/{Get-EntraMSPermissionGrantPolicy.Tests.ps1 => Get-EntraPermissionGrantPolicy.Tests.ps1} (63%) rename test/module/Entra/{Get-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 => Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1} (55%) create mode 100644 test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 delete mode 100644 test/module/Entra/New-EntraMSGroupLifecyclePolicy.Tests.ps1 rename test/module/Entra/{New-EntraMSNamedLocationPolicy.Tests.ps1 => New-EntraNamedLocationPolicy.Tests.ps1} (59%) rename test/module/Entra/{New-EntraMSPermissionGrantPolicy.Tests.ps1 => New-EntraPermissionGrantPolicy.Tests.ps1} (55%) create mode 100644 test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 create mode 100644 test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 delete mode 100644 test/module/Entra/Set-EntraMSAuthorizationPolicy.Tests.ps1 delete mode 100644 test/module/Entra/Set-EntraMSGroupLifecyclePolicy.Tests.ps1 delete mode 100644 test/module/Entra/Set-EntraMSPermissionGrantPolicy.Tests.ps1 create mode 100644 test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 rename test/module/EntraBeta/{Get-EntraBetaMSPermissionGrantPolicy.Tests.ps1 => Get-EntraBetaPermissionGrantPolicy.Tests.ps1} (63%) diff --git a/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 new file mode 100644 index 000000000..11f80af3c --- /dev/null +++ b/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 @@ -0,0 +1,52 @@ +# ------------------------------------------------------------------------------ +# 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 = { + return @( + [PSCustomObject]@{ + "Value" = "True" + "AdditionalProperties" = "{[@odata.context, https://graph.microsoft.com/v1.0/$metadata#Edm.Boolean]}" + "Parameters" = $args + } + ) + } + + Mock -CommandName Add-MgGroupToLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Add-EntraLifecyclePolicyGroup " { + Context "Test for Add-EntraLifecyclePolicyGroup" { + It "Should return created LifecyclePolicyGroup" { + $result = Add-EntraLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b + $result | Should -Not -BeNullOrEmpty" + $result.Value | should -Be "True" + + Should -Invoke -CommandName Add-MgGroupToLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is invalid" { + { Add-EntraLifecyclePolicyGroup -Id "" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + } + It "Should fail when Id is empty" { + { Add-EntraLifecyclePolicyGroup -Id -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + It "Should fail when GroupId is invalid" { + { Add-EntraLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "" } | Should -Throw "Cannot bind argument to parameter 'GroupId' because it is an empty string.*" + } + It "Should fail when GroupId is empty" { + { Add-EntraLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId } | Should -Throw "Missing an argument for parameter 'GroupId'.*" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraLifecyclePolicyGroup" + + $result = Add-EntraLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Add-EntraMSLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Add-EntraMSLifecyclePolicyGroup.Tests.ps1 deleted file mode 100644 index b7f644fff..000000000 --- a/test/module/Entra/Add-EntraMSLifecyclePolicyGroup.Tests.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -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 = { - return @( - [PSCustomObject]@{ - "Value" = "True" - "AdditionalProperties" = "{[@odata.context, https://graph.microsoft.com/v1.0/$metadata#Edm.Boolean]}" - "Parameters" = $args - } - ) - } - - Mock -CommandName Add-MgGroupToLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra -} - -Describe "Add-EntraMSLifecyclePolicyGroup " { - Context "Test for Add-EntraMSLifecyclePolicyGroup" { - It "Should return created LifecyclePolicyGroup" { - $result = Add-EntraMSLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b - $result | Should -Not -BeNullOrEmpty" - $result.Value | should -Be "True" - - Should -Invoke -CommandName Add-MgGroupToLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when Id is invalid" { - { Add-EntraMSLifecyclePolicyGroup -Id "" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" - } - It "Should fail when Id is empty" { - { Add-EntraMSLifecyclePolicyGroup -Id -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" } | Should -Throw "Missing an argument for parameter 'Id'.*" - } - It "Should fail when GroupId is invalid" { - { Add-EntraMSLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "" } | Should -Throw "Cannot bind argument to parameter 'GroupId' because it is an empty string.*" - } - It "Should fail when GroupId is empty" { - { Add-EntraMSLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId } | Should -Throw "Missing an argument for parameter 'GroupId'.*" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraMSLifecyclePolicyGroup" - - $result = Add-EntraMSLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Get-EntraMSAuthorizationPolicy.Tests.ps1 b/test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 similarity index 83% rename from test/module/Entra/Get-EntraMSAuthorizationPolicy.Tests.ps1 rename to test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 index b99652a69..09fb24efb 100644 --- a/test/module/Entra/Get-EntraMSAuthorizationPolicy.Tests.ps1 +++ b/test/module/Entra/Get-EntraAuthorizationPolicy.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 @@ -30,10 +33,10 @@ BeforeAll { Mock -CommandName Get-MgPolicyAuthorizationPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "Get-EntraMSAuthorizationPolicy" { - Context "Test for Get-EntraMSAuthorizationPolicy" { +Describe "Get-EntraAuthorizationPolicy" { + Context "Test for Get-EntraAuthorizationPolicy" { It "Should return AuthorizationPolicy" { - $result = Get-EntraMSAuthorizationPolicy + $result = Get-EntraAuthorizationPolicy $result | Should -Not -BeNullOrEmpty $result.Id | should -Be 'authorizationPolicy' $result.DisplayName | should -Be 'AuthorizationPolicy' @@ -48,9 +51,9 @@ Describe "Get-EntraMSAuthorizationPolicy" { Should -Invoke -CommandName Get-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSAuthorizationPolicy" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraAuthorizationPolicy" - $result = Get-EntraMSAuthorizationPolicy + $result = Get-EntraAuthorizationPolicy $params = Get-Parameters -data $result.Parameters $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } diff --git a/test/module/Entra/Get-EntraMSPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1 similarity index 63% rename from test/module/Entra/Get-EntraMSPermissionGrantPolicy.Tests.ps1 rename to test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1 index a7ed5549a..aa86dc529 100644 --- a/test/module/Entra/Get-EntraMSPermissionGrantPolicy.Tests.ps1 +++ b/test/module/Entra/Get-EntraPermissionGrantPolicy.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 @@ -21,34 +24,34 @@ BeforeAll { Mock -CommandName Get-MgPolicyPermissionGrantPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "Get-EntraMSPermissionGrantPolicy" { - Context "Test for Get-EntraMSPermissionGrantPolicy" { +Describe "Get-EntraPermissionGrantPolicy" { + Context "Test for Get-EntraPermissionGrantPolicy" { It "Should return specific PermissionGrantPolicy" { - $result = Get-EntraMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result = Get-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions" $result | Should -Not -BeNullOrEmpty $result.Id | should -Be "microsoft-all-application-permissions" Should -Invoke -CommandName Get-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when Id is empty" { - { Get-EntraMSPermissionGrantPolicy -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." + { Get-EntraPermissionGrantPolicy -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." } It "Should fail when Id is empty" { - { Get-EntraMSPermissionGrantPolicy -Id } | Should -Throw "Missing an argument for parameter 'Id'. Specify a parameter of type 'System.String' and try again." + { Get-EntraPermissionGrantPolicy -Id } | Should -Throw "Missing an argument for parameter 'Id'. Specify a parameter of type 'System.String' and try again." } It "Result should Contain ObjectId" { - $result = Get-EntraMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result = Get-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions" $result.ObjectId | should -Be "microsoft-all-application-permissions" } It "Should contain PermissionGrantPolicyId in parameters when passed ObjectId to it" { - $result = Get-EntraMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result = Get-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions" $params = Get-Parameters -data $result.Parameters $params.PermissionGrantPolicyId | Should -Be "microsoft-all-application-permissions" } It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSPermissionGrantPolicy" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraPermissionGrantPolicy" - $result = Get-EntraMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result = Get-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions" $params = Get-Parameters -data $result.Parameters $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } diff --git a/test/module/Entra/Get-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 similarity index 55% rename from test/module/Entra/Get-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 rename to test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 index 880f69217..100df89ab 100644 --- a/test/module/Entra/Get-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 +++ b/test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.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 @@ -19,10 +22,10 @@ BeforeAll { Mock -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "Get-EntraMSServicePrincipalDelegatedPermissionClassification" { - Context "Test for Get-EntraMSServicePrincipalDelegatedPermissionClassification" { +Describe "Get-EntraServicePrincipalDelegatedPermissionClassification" { + Context "Test for Get-EntraServicePrincipalDelegatedPermissionClassification" { It "Should return specific ServicePrincipalDelegatedPermissionClassification" { - $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 + $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 $result | Should -Not -BeNullOrEmpty Write-Host ($result | convertto-json) $result.Id | should -Be "T2qU_E28O0GgkLLIYRPsTwE" @@ -30,24 +33,24 @@ Describe "Get-EntraMSServicePrincipalDelegatedPermissionClassification" { Should -Invoke -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when ServicePrincipalId is invalid" { - { Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "" } | Should -Throw "Cannot bind argument to parameter 'ServicePrincipalId' because it is an empty string.*" + { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "" } | Should -Throw "Cannot bind argument to parameter 'ServicePrincipalId' because it is an empty string.*" } It "Should fail when ServicePrincipalId is empty" { - { Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId } | Should -Throw "Missing an argument for parameter 'ServicePrincipalId'.*" + { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId } | Should -Throw "Missing an argument for parameter 'ServicePrincipalId'.*" } It "Should return specific ServicePrincipalDelegatedPermissionClassification when Id passed to it" { - $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id T2qU_E28O0GgkLLIYRPsTwE + $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id T2qU_E28O0GgkLLIYRPsTwE $params = Get-Parameters -data $result.Parameters $params.DelegatedPermissionClassificationId | should -Be "T2qU_E28O0GgkLLIYRPsTwE" } It "Should fail when Id is invalid" { - { Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" } It "Should fail when Id is empty" { - { Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id } | Should -Throw "Missing an argument for parameter 'Id'.*" + { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id } | Should -Throw "Missing an argument for parameter 'Id'.*" } It "Should return specific ServicePrincipalDelegatedPermissionClassification when applied filter to it" { - $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Filter "PermissionName eq 'LicenseManager.AccessAsUser'" + $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Filter "PermissionName eq 'LicenseManager.AccessAsUser'" $result.PermissionName | should -Be "LicenseManager.AccessAsUser" $result.ObjectId | should -Be "T2qU_E28O0GgkLLIYRPsTwE" } @@ -55,9 +58,9 @@ Describe "Get-EntraMSServicePrincipalDelegatedPermissionClassification" { { Get-AzureADMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Filter } | Should -Throw "Missing an argument for parameter 'Filter'.*" } It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSServicePrincipalDelegatedPermissionClassification" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalDelegatedPermissionClassification" - $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 + $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 $params = Get-Parameters -data $result.Parameters $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } diff --git a/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 new file mode 100644 index 000000000..8c44f8e39 --- /dev/null +++ b/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 @@ -0,0 +1,67 @@ +# ------------------------------------------------------------------------------ +# 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 = { + return @( + [PSCustomObject]@{ + "Id" = "a47d4510-08c8-4437-99e9-71ca88e7af0f" + "AlternateNotificationEmails" = "example@contoso.com" + "GroupLifetimeInDays" = "99" + "ManagedGroupTypes" = "Selected" + "Parameters" = $args + } + ) + } + + Mock -CommandName New-MgGroupLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "New-EntraGroupLifecyclePolicy " { + Context "Test for New-EntraGroupLifecyclePolicy" { + It "Should return created GroupLifecyclePolicy" { + $result = New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + $result.GroupLifetimeInDays | should -Be "99" + $result.ManagedGroupTypes | should -Be "Selected" + $result.AlternateNotificationEmails | should -Be "example@contoso.com" + + Should -Invoke -CommandName New-MgGroupLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when GroupLifetimeInDays is invalid" { + { New-EntraGroupLifecyclePolicy -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot process argument transformation on parameter 'GroupLifetimeInDays'.*" + } + It "Should fail when GroupLifetimeInDays is empty" { + { New-EntraGroupLifecyclePolicy -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'GroupLifetimeInDays'.*" + } + It "Should fail when ManagedGroupTypes is invalid" { + { New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot bind argument to parameter 'ManagedGroupTypes' because it is an empty string.*" + } + It "Should fail when ManagedGroupTypes is empty" { + { New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'ManagedGroupTypes'.*" + } + It "Should fail when AlternateNotificationEmails is invalid" { + { New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "" } | Should -Throw "Cannot bind argument to parameter 'AlternateNotificationEmails' because it is an empty string.*" + } + It "Should fail when AlternateNotificationEmails is empty" { + { New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails } | Should -Throw "Missing an argument for parameter 'AlternateNotificationEmails'.*" + } + It "Result should Contain ObjectId" { + $result = New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" + $result.ObjectId | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraGroupLifecyclePolicy" + + $result = New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/New-EntraMSGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/New-EntraMSGroupLifecyclePolicy.Tests.ps1 deleted file mode 100644 index 2846d9706..000000000 --- a/test/module/Entra/New-EntraMSGroupLifecyclePolicy.Tests.ps1 +++ /dev/null @@ -1,64 +0,0 @@ -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 = { - return @( - [PSCustomObject]@{ - "Id" = "a47d4510-08c8-4437-99e9-71ca88e7af0f" - "AlternateNotificationEmails" = "example@contoso.com" - "GroupLifetimeInDays" = "99" - "ManagedGroupTypes" = "Selected" - "Parameters" = $args - } - ) - } - - Mock -CommandName New-MgGroupLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra -} - -Describe "New-EntraMSGroupLifecyclePolicy " { - Context "Test for New-EntraMSGroupLifecyclePolicy" { - It "Should return created GroupLifecyclePolicy" { - $result = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" - $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" - $result.GroupLifetimeInDays | should -Be "99" - $result.ManagedGroupTypes | should -Be "Selected" - $result.AlternateNotificationEmails | should -Be "example@contoso.com" - - Should -Invoke -CommandName New-MgGroupLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when GroupLifetimeInDays is invalid" { - { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot process argument transformation on parameter 'GroupLifetimeInDays'.*" - } - It "Should fail when GroupLifetimeInDays is empty" { - { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'GroupLifetimeInDays'.*" - } - It "Should fail when ManagedGroupTypes is invalid" { - { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot bind argument to parameter 'ManagedGroupTypes' because it is an empty string.*" - } - It "Should fail when ManagedGroupTypes is empty" { - { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'ManagedGroupTypes'.*" - } - It "Should fail when AlternateNotificationEmails is invalid" { - { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "" } | Should -Throw "Cannot bind argument to parameter 'AlternateNotificationEmails' because it is an empty string.*" - } - It "Should fail when AlternateNotificationEmails is empty" { - { New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails } | Should -Throw "Missing an argument for parameter 'AlternateNotificationEmails'.*" - } - It "Result should Contain ObjectId" { - $result = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" - $result.ObjectId | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSGroupLifecyclePolicy" - - $result = New-EntraMSGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } - } -} \ No newline at end of file diff --git a/test/module/Entra/New-EntraMSNamedLocationPolicy.Tests.ps1 b/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 similarity index 59% rename from test/module/Entra/New-EntraMSNamedLocationPolicy.Tests.ps1 rename to test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 index d15bd8774..ac04e4720 100644 --- a/test/module/Entra/New-EntraMSNamedLocationPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraNamedLocationPolicy.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 @@ -29,43 +32,43 @@ BeforeAll { Mock -CommandName New-MgIdentityConditionalAccessNamedLocation -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "New-EntraMSNamedLocationPolicy " { - Context "Test for New-EntraMSNamedLocationPolicy" { +Describe "New-EntraNamedLocationPolicy " { + Context "Test for New-EntraNamedLocationPolicy" { It "Should return created NamedLocationPolicy" { $ipRanges1 = New-Object -TypeName Microsoft.Open.MSGraph.Model.IpRange $ipRanges1.cidrAddress = "6.5.4.1/30" $ipRanges2 = New-Object -TypeName Microsoft.Open.MSGraph.Model.IpRange $ipRanges2.cidrAddress = "6.5.4.2/30" - $result = New-EntraMSNamedLocationPolicy -OdataType "#microsoft.graph.ipNamedLocation" -DisplayName "NamedLocation" -IpRanges @($ipRanges1, $ipRanges2) -IsTrusted $false + $result = New-EntraNamedLocationPolicy -OdataType "#microsoft.graph.ipNamedLocation" -DisplayName "NamedLocation" -IpRanges @($ipRanges1, $ipRanges2) -IsTrusted $false $result | Should -Not -BeNullOrEmpty $result.Id | should -Be "04fee326-10cf-4211-8edd-d2bd3f4a9a9c" Should -Invoke -CommandName New-MgIdentityConditionalAccessNamedLocation -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when OdataType is empty" { - { New-EntraMSNamedLocationPolicy -OdataType } | Should -Throw "Missing an argument for parameter 'OdataType'. Specify a parameter of type 'System.String' and try again." + { New-EntraNamedLocationPolicy -OdataType } | Should -Throw "Missing an argument for parameter 'OdataType'. Specify a parameter of type 'System.String' and try again." } It "Should fail when DisplayName is empty" { - { New-EntraMSNamedLocationPolicy -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'. Specify a parameter of type 'System.String' and try again." + { New-EntraNamedLocationPolicy -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'. Specify a parameter of type 'System.String' and try again." } It "Should fail when IpRanges is empty" { - { New-EntraMSNamedLocationPolicy -IpRanges } | Should -Throw "Missing an argument for parameter 'IpRanges'.*" + { New-EntraNamedLocationPolicy -IpRanges } | Should -Throw "Missing an argument for parameter 'IpRanges'.*" } It "Should fail when IsTrusted is empty" { - { New-EntraMSNamedLocationPolicy -IsTrusted } | Should -Throw "Missing an argument for parameter 'IsTrusted'.*" + { New-EntraNamedLocationPolicy -IsTrusted } | Should -Throw "Missing an argument for parameter 'IsTrusted'.*" } It "Should fail when CountriesAndRegions is empty" { - { New-EntraMSNamedLocationPolicy -CountriesAndRegions } | Should -Throw "Missing an argument for parameter 'CountriesAndRegions'.*" + { New-EntraNamedLocationPolicy -CountriesAndRegions } | Should -Throw "Missing an argument for parameter 'CountriesAndRegions'.*" } It "Should fail when IncludeUnknownCountriesAndRegions is empty" { - { New-EntraMSNamedLocationPolicy -IncludeUnknownCountriesAndRegions } | Should -Throw "Missing an argument for parameter 'IncludeUnknownCountriesAndRegions'.*" + { New-EntraNamedLocationPolicy -IncludeUnknownCountriesAndRegions } | Should -Throw "Missing an argument for parameter 'IncludeUnknownCountriesAndRegions'.*" } It "Result should Contain ObjectId" { - $result = New-EntraMSNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true + $result = New-EntraNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true $result.ObjectId | should -Be "04fee326-10cf-4211-8edd-d2bd3f4a9a9c" } It "Should contain params inside BodyParameter" { - $result = New-EntraMSNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true + $result = New-EntraNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true $params = Get-Parameters -data $result.Parameters $BodyParameters = $params.BodyParameter.AdditionalProperties $BodyParameters.includeUnknownCountriesAndRegions | Should -Be "True" @@ -73,9 +76,9 @@ Describe "New-EntraMSNamedLocationPolicy " { $BodyParameters.countriesAndRegions | Should -Be @('US', 'ID', 'CA') } It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSNamedLocationPolicy" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraNamedLocationPolicy" - $result = New-EntraMSNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true + $result = New-EntraNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true $params = Get-Parameters -data $result.Parameters $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } diff --git a/test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/New-EntraPermissionGrantPolicy.Tests.ps1 similarity index 55% rename from test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 rename to test/module/Entra/New-EntraPermissionGrantPolicy.Tests.ps1 index 08d480e12..0d6803c23 100644 --- a/test/module/Entra/New-EntraMSPermissionGrantPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraPermissionGrantPolicy.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 @@ -21,10 +24,10 @@ BeforeAll { Mock -CommandName New-MgPolicyPermissionGrantPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "New-EntraMSPermissionGrantPolicy" { - Context "Test for New-EntraMSPermissionGrantPolicy" { +Describe "New-EntraPermissionGrantPolicy" { + Context "Test for New-EntraPermissionGrantPolicy" { It "Should return created PermissionGrantPolicy" { - $result = New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" + $result = New-EntraPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" $result | Should -Not -BeNullOrEmpty $result.Id | should -Be "my_new_permission_grant_policy_id" $result.DisplayName | should -Be "My new permission grant policy" @@ -35,22 +38,22 @@ Describe "New-EntraMSPermissionGrantPolicy" { Should -Invoke -CommandName New-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when Id is empty" { - { New-EntraMSPermissionGrantPolicy -Id -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" } | Should -Throw "Missing an argument for parameter 'Id'.*" + { New-EntraPermissionGrantPolicy -Id -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" } | Should -Throw "Missing an argument for parameter 'Id'.*" } It "Should fail when DisplayName is empty" { - { New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName -Description "My new permission grant policy" } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" + { New-EntraPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName -Description "My new permission grant policy" } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" } It "Should fail when Description is empty" { - { New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description } | Should -Throw "Missing an argument for parameter 'Description'.*" + { New-EntraPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description } | Should -Throw "Missing an argument for parameter 'Description'.*" } It "Result should Contain ObjectId" { - $result = New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" + $result = New-EntraPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" $result.ObjectId | should -Be "my_new_permission_grant_policy_id" } It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSPermissionGrantPolicy" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraPermissionGrantPolicy" - $result = New-EntraMSPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" + $result = New-EntraPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" $params = Get-Parameters -data $result.Parameters $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } diff --git a/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 b/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 new file mode 100644 index 000000000..fbe75c238 --- /dev/null +++ b/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 @@ -0,0 +1,70 @@ +# ------------------------------------------------------------------------------ +# 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 Update-MgPolicyAuthorizationPolicy -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Set-EntraAuthorizationPolicy" { + Context "Test for Set-EntraAuthorizationPolicy" { + It "Should update AuthorizationPolicy" { + $DefaultUserRolePermissions = New-Object -TypeName Microsoft.Open.MSGraph.Model.DefaultUserRolePermissions + $DefaultUserRolePermissions.AllowedToCreateApps = $true + $DefaultUserRolePermissions.AllowedToCreateSecurityGroups = $true + $DefaultUserRolePermissions.AllowedToReadOtherUsers = $true + $result = Set-EntraAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions $false -AllowedToUseSSPR $false -AllowEmailVerifiedUsersToJoinOrganization $true -BlockMsolPowerShell $true -DefaultUserRolePermissions $DefaultUserRolePermissions -Description "test" -DisplayName "Authorization Policies" + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName Update-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when AllowedToSignUpEmailBasedSubscriptions is invalid" { + { Set-EntraAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowedToSignUpEmailBasedSubscriptions'.*" + } + It "Should fail when AllowedToSignUpEmailBasedSubscriptions is empty" { + { Set-EntraAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions } | Should -Throw "Missing an argument for parameter 'AllowedToSignUpEmailBasedSubscriptions'.*" + } + It "Should fail when AllowedToUseSSPR is invalid" { + { Set-EntraAuthorizationPolicy -AllowedToUseSSPR 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowedToUseSSPR'*" + } + It "Should fail when AllowedToUseSSPR is empty" { + { Set-EntraAuthorizationPolicy -AllowedToUseSSPR } | Should -Throw "Missing an argument for parameter 'AllowedToUseSSPR'.*" + } + It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is invalid" { + { Set-EntraAuthorizationPolicy -AllowEmailVerifiedUsersToJoinOrganization 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowEmailVerifiedUsersToJoinOrganization'*" + } + It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is empty" { + { Set-EntraAuthorizationPolicy -AllowEmailVerifiedUsersToJoinOrganization } | Should -Throw "Missing an argument for parameter 'AllowEmailVerifiedUsersToJoinOrganization'.*" + } + It "Should fail when BlockMsolPowerShell is invalid" { + { Set-EntraAuthorizationPolicy -BlockMsolPowerShell 'a' } | Should -Throw "Cannot process argument transformation on parameter 'BlockMsolPowerShell'*" + } + It "Should fail when BlockMsolPowerShell is empty" { + { Set-EntraAuthorizationPolicy -BlockMsolPowerShell } | Should -Throw "Missing an argument for parameter 'BlockMsolPowerShell'.*" + } + It "Should fail when DefaultUserRolePermissions is invalid" { + { Set-EntraAuthorizationPolicy -DefaultUserRolePermissions 'a' } | Should -Throw "Cannot process argument transformation on parameter 'DefaultUserRolePermissions'*" + } + It "Should fail when DefaultUserRolePermissions is empty" { + { Set-EntraAuthorizationPolicy -DefaultUserRolePermissions } | Should -Throw "Missing an argument for parameter 'DefaultUserRolePermissions'.*" + } + It "Should fail when Description is empty" { + { Set-EntraAuthorizationPolicy -Description } | Should -Throw "Missing an argument for parameter 'Description'.*" + } + It "Should fail when DisplayName is empty" { + { Set-EntraAuthorizationPolicy -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Update-MgPolicyAuthorizationPolicy -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraAuthorizationPolicy" + + $result = Set-EntraAuthorizationPolicy + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 new file mode 100644 index 000000000..e1f9cd5f3 --- /dev/null +++ b/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 @@ -0,0 +1,67 @@ +# ------------------------------------------------------------------------------ +# 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 = { + return @( + [PSCustomObject]@{ + "Id" = "a47d4510-08c8-4437-99e9-71ca88e7af0f" + "AlternateNotificationEmails" = "admingroup@contoso.com" + "GroupLifetimeInDays" = "100" + "ManagedGroupTypes" = "All" + "Parameters" = $args + } + ) + } + + Mock -CommandName Update-MgGroupLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Set-EntraGroupLifecyclePolicy " { + Context "Test for Set-EntraGroupLifecyclePolicy" { + It "Should return updated GroupLifecyclePolicy" { + $result = Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + $result.GroupLifetimeInDays | should -Be "100" + $result.ManagedGroupTypes | should -Be "All" + $result.AlternateNotificationEmails | should -Be "admingroup@contoso.com" + + Should -Invoke -CommandName Update-MgGroupLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is invalid" { + { Set-EntraGroupLifecyclePolicy -Id "" -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + } + It "Should fail when Id is empty" { + { Set-EntraGroupLifecyclePolicy -Id -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + It "Should fail when GroupLifetimeInDays is invalid" { + { Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot process argument transformation on parameter 'GroupLifetimeInDays'.*" + } + It "Should fail when GroupLifetimeInDays is empty" { + { Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'GroupLifetimeInDays'.*" + } + It "Should fail when ManagedGroupTypes is empty" { + { Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 99 -ManagedGroupTypes -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'ManagedGroupTypes'.*" + } + It "Should fail when AlternateNotificationEmails is empty" { + { Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails } | Should -Throw "Missing an argument for parameter 'AlternateNotificationEmails'.*" + } + It "Result should Contain ObjectId" { + $result = Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $result.ObjectId | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraGroupLifecyclePolicy" + + $result = Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Set-EntraMSAuthorizationPolicy.Tests.ps1 b/test/module/Entra/Set-EntraMSAuthorizationPolicy.Tests.ps1 deleted file mode 100644 index 877a2f29a..000000000 --- a/test/module/Entra/Set-EntraMSAuthorizationPolicy.Tests.ps1 +++ /dev/null @@ -1,67 +0,0 @@ -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 Update-MgPolicyAuthorizationPolicy -MockWith {} -ModuleName Microsoft.Graph.Entra -} - -Describe "Set-EntraMSAuthorizationPolicy" { - Context "Test for Set-EntraMSAuthorizationPolicy" { - It "Should update AuthorizationPolicy" { - $DefaultUserRolePermissions = New-Object -TypeName Microsoft.Open.MSGraph.Model.DefaultUserRolePermissions - $DefaultUserRolePermissions.AllowedToCreateApps = $true - $DefaultUserRolePermissions.AllowedToCreateSecurityGroups = $true - $DefaultUserRolePermissions.AllowedToReadOtherUsers = $true - $result = Set-EntraMSAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions $false -AllowedToUseSSPR $false -AllowEmailVerifiedUsersToJoinOrganization $true -BlockMsolPowerShell $true -DefaultUserRolePermissions $DefaultUserRolePermissions -Description "test" -DisplayName "Authorization Policies" - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Update-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when AllowedToSignUpEmailBasedSubscriptions is invalid" { - { Set-EntraMSAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowedToSignUpEmailBasedSubscriptions'.*" - } - It "Should fail when AllowedToSignUpEmailBasedSubscriptions is empty" { - { Set-EntraMSAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions } | Should -Throw "Missing an argument for parameter 'AllowedToSignUpEmailBasedSubscriptions'.*" - } - It "Should fail when AllowedToUseSSPR is invalid" { - { Set-EntraMSAuthorizationPolicy -AllowedToUseSSPR 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowedToUseSSPR'*" - } - It "Should fail when AllowedToUseSSPR is empty" { - { Set-EntraMSAuthorizationPolicy -AllowedToUseSSPR } | Should -Throw "Missing an argument for parameter 'AllowedToUseSSPR'.*" - } - It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is invalid" { - { Set-EntraMSAuthorizationPolicy -AllowEmailVerifiedUsersToJoinOrganization 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowEmailVerifiedUsersToJoinOrganization'*" - } - It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is empty" { - { Set-EntraMSAuthorizationPolicy -AllowEmailVerifiedUsersToJoinOrganization } | Should -Throw "Missing an argument for parameter 'AllowEmailVerifiedUsersToJoinOrganization'.*" - } - It "Should fail when BlockMsolPowerShell is invalid" { - { Set-EntraMSAuthorizationPolicy -BlockMsolPowerShell 'a' } | Should -Throw "Cannot process argument transformation on parameter 'BlockMsolPowerShell'*" - } - It "Should fail when BlockMsolPowerShell is empty" { - { Set-EntraMSAuthorizationPolicy -BlockMsolPowerShell } | Should -Throw "Missing an argument for parameter 'BlockMsolPowerShell'.*" - } - It "Should fail when DefaultUserRolePermissions is invalid" { - { Set-EntraMSAuthorizationPolicy -DefaultUserRolePermissions 'a' } | Should -Throw "Cannot process argument transformation on parameter 'DefaultUserRolePermissions'*" - } - It "Should fail when DefaultUserRolePermissions is empty" { - { Set-EntraMSAuthorizationPolicy -DefaultUserRolePermissions } | Should -Throw "Missing an argument for parameter 'DefaultUserRolePermissions'.*" - } - It "Should fail when Description is empty" { - { Set-EntraMSAuthorizationPolicy -Description } | Should -Throw "Missing an argument for parameter 'Description'.*" - } - It "Should fail when DisplayName is empty" { - { Set-EntraMSAuthorizationPolicy -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" - } - It "Should contain 'User-Agent' header" { - Mock -CommandName Update-MgPolicyAuthorizationPolicy -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraMSAuthorizationPolicy" - - $result = Set-EntraMSAuthorizationPolicy - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Set-EntraMSGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/Set-EntraMSGroupLifecyclePolicy.Tests.ps1 deleted file mode 100644 index d369ba6e9..000000000 --- a/test/module/Entra/Set-EntraMSGroupLifecyclePolicy.Tests.ps1 +++ /dev/null @@ -1,64 +0,0 @@ -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 = { - return @( - [PSCustomObject]@{ - "Id" = "a47d4510-08c8-4437-99e9-71ca88e7af0f" - "AlternateNotificationEmails" = "admingroup@contoso.com" - "GroupLifetimeInDays" = "100" - "ManagedGroupTypes" = "All" - "Parameters" = $args - } - ) - } - - Mock -CommandName Update-MgGroupLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra -} - -Describe "Set-EntraMSGroupLifecyclePolicy " { - Context "Test for Set-EntraMSGroupLifecyclePolicy" { - It "Should return updated GroupLifecyclePolicy" { - $result = Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" - $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" - $result.GroupLifetimeInDays | should -Be "100" - $result.ManagedGroupTypes | should -Be "All" - $result.AlternateNotificationEmails | should -Be "admingroup@contoso.com" - - Should -Invoke -CommandName Update-MgGroupLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when Id is invalid" { - { Set-EntraMSGroupLifecyclePolicy -Id "" -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" - } - It "Should fail when Id is empty" { - { Set-EntraMSGroupLifecyclePolicy -Id -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'Id'.*" - } - It "Should fail when GroupLifetimeInDays is invalid" { - { Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot process argument transformation on parameter 'GroupLifetimeInDays'.*" - } - It "Should fail when GroupLifetimeInDays is empty" { - { Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'GroupLifetimeInDays'.*" - } - It "Should fail when ManagedGroupTypes is empty" { - { Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 99 -ManagedGroupTypes -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'ManagedGroupTypes'.*" - } - It "Should fail when AlternateNotificationEmails is empty" { - { Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails } | Should -Throw "Missing an argument for parameter 'AlternateNotificationEmails'.*" - } - It "Result should Contain ObjectId" { - $result = Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" - $result.ObjectId | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" - } - It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraMSGroupLifecyclePolicy" - - $result = Set-EntraMSGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Set-EntraMSPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/Set-EntraMSPermissionGrantPolicy.Tests.ps1 deleted file mode 100644 index 353d04fe3..000000000 --- a/test/module/Entra/Set-EntraMSPermissionGrantPolicy.Tests.ps1 +++ /dev/null @@ -1,39 +0,0 @@ -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 Update-MgPolicyPermissionGrantPolicy -MockWith {} -ModuleName Microsoft.Graph.Entra -} - -Describe "Set-EntraMSPermissionGrantPolicy" { - Context "Test for Set-EntraMSPermissionGrantPolicy" { - It "Should return updated PermissionGrantPolicy" { - $result = Set-EntraMSPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName "Test" - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Update-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when Id is empty" { - { Set-EntraMSPermissionGrantPolicy -Id -Description "test" -DisplayName "Test" } | Should -Throw "Missing an argument for parameter 'Id'.*" - } - It "Should fail when Id is invalid" { - { Set-EntraMSPermissionGrantPolicy -Id "" -Description "test" -DisplayName "Test" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" - } - It "Should fail when Description is empty" { - { Set-EntraMSPermissionGrantPolicy -Id "permission_grant_policy" -Description -DisplayName "Test" } | Should -Throw "Missing an argument for parameter 'Description'.*" - } - It "Should fail when DisplayName is empty" { - { Set-EntraMSPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" - } - It "Should contain 'User-Agent' header" { - Mock -CommandName Update-MgPolicyPermissionGrantPolicy -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraMSPermissionGrantPolicy" - - $result = Set-EntraMSPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName "Test" - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 new file mode 100644 index 000000000..384ca22da --- /dev/null +++ b/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 @@ -0,0 +1,42 @@ +# ------------------------------------------------------------------------------ +# 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 Update-MgPolicyPermissionGrantPolicy -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Set-EntraPermissionGrantPolicy" { + Context "Test for Set-EntraPermissionGrantPolicy" { + It "Should return updated PermissionGrantPolicy" { + $result = Set-EntraPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName "Test" + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName Update-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is empty" { + { Set-EntraPermissionGrantPolicy -Id -Description "test" -DisplayName "Test" } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + It "Should fail when Id is invalid" { + { Set-EntraPermissionGrantPolicy -Id "" -Description "test" -DisplayName "Test" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + } + It "Should fail when Description is empty" { + { Set-EntraPermissionGrantPolicy -Id "permission_grant_policy" -Description -DisplayName "Test" } | Should -Throw "Missing an argument for parameter 'Description'.*" + } + It "Should fail when DisplayName is empty" { + { Set-EntraPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Update-MgPolicyPermissionGrantPolicy -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraPermissionGrantPolicy" + + $result = Set-EntraPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName "Test" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Get-EntraBetaMSPermissionGrantPolicy.Tests.ps1 b/test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 similarity index 63% rename from test/module/EntraBeta/Get-EntraBetaMSPermissionGrantPolicy.Tests.ps1 rename to test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 index 1cac61bc1..8a6afa3d9 100644 --- a/test/module/EntraBeta/Get-EntraBetaMSPermissionGrantPolicy.Tests.ps1 +++ b/test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.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.Beta) -eq $null) { Import-Module Microsoft.Graph.Entra.Beta @@ -21,34 +24,34 @@ BeforeAll { Mock -CommandName Get-MgBetaPolicyPermissionGrantPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.Beta } -Describe "Get-EntraBetaMSPermissionGrantPolicy" { - Context "Test for Get-EntraBetaMSPermissionGrantPolicy" { +Describe "Get-EntraBetaPermissionGrantPolicy" { + Context "Test for Get-EntraBetaPermissionGrantPolicy" { It "Should return specific PermissionGrantPolicy" { - $result = Get-EntraBetaMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result = Get-EntraBetaPermissionGrantPolicy -Id "microsoft-all-application-permissions" $result | Should -Not -BeNullOrEmpty $result.Id | should -Be "microsoft-all-application-permissions" Should -Invoke -CommandName Get-MgBetaPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra.Beta -Times 1 } It "Should fail when Id is empty" { - { Get-EntraBetaMSPermissionGrantPolicy -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." + { Get-EntraBetaPermissionGrantPolicy -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." } It "Should fail when Id is empty" { - { Get-EntraBetaMSPermissionGrantPolicy -Id } | Should -Throw "Missing an argument for parameter 'Id'. Specify a parameter of type 'System.String' and try again." + { Get-EntraBetaPermissionGrantPolicy -Id } | Should -Throw "Missing an argument for parameter 'Id'. Specify a parameter of type 'System.String' and try again." } It "Result should Contain ObjectId" { - $result = Get-EntraBetaMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result = Get-EntraBetaPermissionGrantPolicy -Id "microsoft-all-application-permissions" $result.ObjectId | should -Be "microsoft-all-application-permissions" } It "Should contain PermissionGrantPolicyId in parameters when passed ObjectId to it" { - $result = Get-EntraBetaMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result = Get-EntraBetaPermissionGrantPolicy -Id "microsoft-all-application-permissions" $params = Get-Parameters -data $result.Parameters $params.PermissionGrantPolicyId | Should -Be "microsoft-all-application-permissions" } It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaMSPermissionGrantPolicy" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaPermissionGrantPolicy" - $result = Get-EntraBetaMSPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result = Get-EntraBetaPermissionGrantPolicy -Id "microsoft-all-application-permissions" $params = Get-Parameters -data $result.Parameters $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } From d53a1b27a576a6e64846d29c30f0b1c09b4d763d Mon Sep 17 00:00:00 2001 From: Ashwini Karke Date: Wed, 21 Aug 2024 16:32:59 +0530 Subject: [PATCH 06/11] fixed CertificateAuthorities issue --- .../customizations/Get-EntraTrustedCertificateAuthority.ps1 | 4 +++- .../Get-EntraBetaTrustedCertificateAuthority.ps1 | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/module/Entra/customizations/Get-EntraTrustedCertificateAuthority.ps1 b/module/Entra/customizations/Get-EntraTrustedCertificateAuthority.ps1 index c62f3c8b5..0a82ba7c7 100644 --- a/module/Entra/customizations/Get-EntraTrustedCertificateAuthority.ps1 +++ b/module/Entra/customizations/Get-EntraTrustedCertificateAuthority.ps1 @@ -74,7 +74,8 @@ $responseData = Get-MgOrganizationCertificateBasedAuthConfiguration @params -Headers $customHeaders $response= @() - $responseData.CertificateAuthorities | ForEach-Object { + if($responseData){ + $responseData.CertificateAuthorities | ForEach-Object { if ( ([string]::IsNullOrEmpty($TrustedIssuer) -and [string]::IsNullOrEmpty($TrustedIssuerSki)) -or (![string]::IsNullOrEmpty($TrustedIssuer) -and ![string]::IsNullOrEmpty($TrustedIssuerSki) -and $_.Issuer -eq $TrustedIssuer -and $_.IssuerSki -eq $TrustedIssuerSki) -or @@ -96,6 +97,7 @@ $dataJson = ConvertTo-Json $data $response += [Newtonsoft.Json.JsonConvert]::DeserializeObject($dataJson, [Microsoft.Open.AzureAD.Model.CertificateAuthorityInformation]) } + } } $response } diff --git a/module/EntraBeta/customizations/Get-EntraBetaTrustedCertificateAuthority.ps1 b/module/EntraBeta/customizations/Get-EntraBetaTrustedCertificateAuthority.ps1 index 7c996af5c..4c0b94481 100644 --- a/module/EntraBeta/customizations/Get-EntraBetaTrustedCertificateAuthority.ps1 +++ b/module/EntraBeta/customizations/Get-EntraBetaTrustedCertificateAuthority.ps1 @@ -75,7 +75,8 @@ $responseData = Get-MgBetaOrganizationCertificateBasedAuthConfiguration @params -Headers $customHeaders $response= @() - $responseData.CertificateAuthorities | ForEach-Object { + if($responseData){ + $responseData.CertificateAuthorities | ForEach-Object { if ( ([string]::IsNullOrEmpty($TrustedIssuer) -and [string]::IsNullOrEmpty($TrustedIssuerSki)) -or (![string]::IsNullOrEmpty($TrustedIssuer) -and ![string]::IsNullOrEmpty($TrustedIssuerSki) -and $_.Issuer -eq $TrustedIssuer -and $_.IssuerSki -eq $TrustedIssuerSki) -or @@ -97,6 +98,7 @@ $dataJson = ConvertTo-Json $data $response += [Newtonsoft.Json.JsonConvert]::DeserializeObject($dataJson, [Microsoft.Open.AzureAD.Model.CertificateAuthorityInformation]) } + } } $response } From 0bbdb3c7ad38423c923786459e59b22569aa1a97 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Thu, 29 Aug 2024 16:00:46 +0530 Subject: [PATCH 07/11] updated mock test cases --- .../Add-EntraLifecyclePolicyGroup.Tests.ps1 | 25 ++++++++--- .../Get-EntraAuthorizationPolicy.Tests.ps1 | 27 +++++++++++- .../Get-EntraPermissionGrantPolicy.Tests.ps1 | 27 +++++++++++- ...elegatedPermissionClassification.Tests.ps1 | 42 ++++++++++++++----- .../New-EntraGroupLifecyclePolicy.Tests.ps1 | 19 +++++++-- .../New-EntraNamedLocationPolicy.Tests.ps1 | 19 +++++++-- .../New-EntraPermissionGrantPolicy.Tests.ps1 | 17 +++++++- .../Set-EntraAuthorizationPolicy.Tests.ps1 | 41 ++++++++++++------ .../Set-EntraGroupLifecyclePolicy.Tests.ps1 | 31 ++++++++++---- .../Set-EntraPermissionGrantPolicy.Tests.ps1 | 13 ++++++ ...t-EntraBetaPermissionGrantPolicy.Tests.ps1 | 27 +++++++++++- 11 files changed, 237 insertions(+), 51 deletions(-) diff --git a/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 index 11f80af3c..d1fb3034d 100644 --- a/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 +++ b/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 @@ -23,30 +23,43 @@ BeforeAll { Describe "Add-EntraLifecyclePolicyGroup " { Context "Test for Add-EntraLifecyclePolicyGroup" { It "Should return created LifecyclePolicyGroup" { - $result = Add-EntraLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b + $result = Add-EntraLifecyclePolicyGroup -Id "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -GroupId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff $result | Should -Not -BeNullOrEmpty" $result.Value | should -Be "True" Should -Invoke -CommandName Add-MgGroupToLifecyclePolicy -ModuleName Microsoft.Graph.Entra -Times 1 } It "Should fail when Id is invalid" { - { Add-EntraLifecyclePolicyGroup -Id "" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + { Add-EntraLifecyclePolicyGroup -Id "" -GroupId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" } It "Should fail when Id is empty" { - { Add-EntraLifecyclePolicyGroup -Id -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" } | Should -Throw "Missing an argument for parameter 'Id'.*" + { Add-EntraLifecyclePolicyGroup -Id -GroupId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" } | Should -Throw "Missing an argument for parameter 'Id'.*" } It "Should fail when GroupId is invalid" { - { Add-EntraLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "" } | Should -Throw "Cannot bind argument to parameter 'GroupId' because it is an empty string.*" + { Add-EntraLifecyclePolicyGroup -Id "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -GroupId "" } | Should -Throw "Cannot bind argument to parameter 'GroupId' because it is an empty string.*" } It "Should fail when GroupId is empty" { - { Add-EntraLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId } | Should -Throw "Missing an argument for parameter 'GroupId'.*" + { Add-EntraLifecyclePolicyGroup -Id "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -GroupId } | Should -Throw "Missing an argument for parameter 'GroupId'.*" } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraLifecyclePolicyGroup" - $result = Add-EntraLifecyclePolicyGroup -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupId "0d34b8e3-67ad-4a96-aec6-1c983d2adc5b" + $result = Add-EntraLifecyclePolicyGroup -Id "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -GroupId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" $params = Get-Parameters -data $result.Parameters $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 + { Add-EntraLifecyclePolicyGroup -Id "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -GroupId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 b/test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 index 09fb24efb..27034e939 100644 --- a/test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 +++ b/test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 @@ -15,7 +15,7 @@ BeforeAll { AdditionalProperties = "" } "DeletedDateTime" = $null - "GuestUserRoleId" = "111cc9b5-fce9-485e-9566-c68debafac5f" + "GuestUserRoleId" = "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" "DisplayName" = "AuthorizationPolicy" "Description" = "AuthorizationPolicy" "AllowEmailVerifiedUsersToJoinOrganization" = $True @@ -42,7 +42,7 @@ Describe "Get-EntraAuthorizationPolicy" { $result.DisplayName | should -Be 'AuthorizationPolicy' $result.Description | should -Be 'AuthorizationPolicy' $result.AllowInvitesFrom | should -Be 'everyone' - $result.GuestUserRoleId | should -Be '111cc9b5-fce9-485e-9566-c68debafac5f' + $result.GuestUserRoleId | should -Be '00aa00aa-bb11-cc22-dd33-44ee44ee44ee' $result.AllowEmailVerifiedUsersToJoinOrganization | should -Be $True $result.AllowedToSignUpEmailBasedSubscriptions | should -Be $True $result.AllowedToUseSspr | should -Be $True @@ -50,6 +50,16 @@ Describe "Get-EntraAuthorizationPolicy" { Should -Invoke -CommandName Get-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1 } + It "Property parameter should work" { + $result = Get-EntraAuthorizationPolicy -Property DisplayName + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | Should -Be 'AuthorizationPolicy' + + Should -Invoke -CommandName Get-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Property is empty" { + { Get-EntraAuthorizationPolicy -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraAuthorizationPolicy" @@ -57,5 +67,18 @@ Describe "Get-EntraAuthorizationPolicy" { $params = Get-Parameters -data $result.Parameters $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-EntraAuthorizationPolicy -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1 index aa86dc529..539c272f9 100644 --- a/test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1 +++ b/test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1 @@ -13,9 +13,9 @@ BeforeAll { "Id" = "microsoft-all-application-permissions" "DeletedDateTime" = "2/8/2024 6:39:16 AM" "Description" = "Includes all application permissions (app roles), for all APIs, for any client application." - "DisplayName" = "All application permissions, for any client app" + "DisplayName" = "All application" "Excludes" = @{} - "Includes" = @("bddda1ec-0174-44d5-84e2-47fb0ac01595") + "Includes" = @("00aa00aa-bb11-cc22-dd33-44ee44ee44ee") "Parameters" = $args } ) @@ -48,6 +48,16 @@ Describe "Get-EntraPermissionGrantPolicy" { $params = Get-Parameters -data $result.Parameters $params.PermissionGrantPolicyId | Should -Be "microsoft-all-application-permissions" } + It "Property parameter should work" { + $result = Get-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions" -Property DisplayName + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | Should -Be 'All application' + + Should -Invoke -CommandName Get-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Property is empty" { + { Get-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraPermissionGrantPolicy" @@ -55,5 +65,18 @@ Describe "Get-EntraPermissionGrantPolicy" { $params = Get-Parameters -data $result.Parameters $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-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 index 100df89ab..c76fc9b84 100644 --- a/test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 +++ b/test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 @@ -12,7 +12,7 @@ BeforeAll { [PSCustomObject]@{ "Id" = "T2qU_E28O0GgkLLIYRPsTwE" "Classification" = "low" - "PermissionId" = "fc946a4f-bc4d-413b-a090-b2c86113ec4f" + "PermissionId" = "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" "PermissionName" = "LicenseManager.AccessAsUser" "Parameters" = $args } @@ -25,9 +25,8 @@ BeforeAll { Describe "Get-EntraServicePrincipalDelegatedPermissionClassification" { Context "Test for Get-EntraServicePrincipalDelegatedPermissionClassification" { It "Should return specific ServicePrincipalDelegatedPermissionClassification" { - $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 + $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" $result | Should -Not -BeNullOrEmpty - Write-Host ($result | convertto-json) $result.Id | should -Be "T2qU_E28O0GgkLLIYRPsTwE" Should -Invoke -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -ModuleName Microsoft.Graph.Entra -Times 1 @@ -39,30 +38,53 @@ Describe "Get-EntraServicePrincipalDelegatedPermissionClassification" { { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId } | Should -Throw "Missing an argument for parameter 'ServicePrincipalId'.*" } It "Should return specific ServicePrincipalDelegatedPermissionClassification when Id passed to it" { - $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id T2qU_E28O0GgkLLIYRPsTwE + $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Id 'T2qU_E28O0GgkLLIYRPsTwE' $params = Get-Parameters -data $result.Parameters $params.DelegatedPermissionClassificationId | should -Be "T2qU_E28O0GgkLLIYRPsTwE" } It "Should fail when Id is invalid" { - { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" + { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string.*" } It "Should fail when Id is empty" { - { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Id } | Should -Throw "Missing an argument for parameter 'Id'.*" + { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Id } | Should -Throw "Missing an argument for parameter 'Id'.*" } It "Should return specific ServicePrincipalDelegatedPermissionClassification when applied filter to it" { - $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Filter "PermissionName eq 'LicenseManager.AccessAsUser'" + $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Filter "PermissionName eq 'LicenseManager.AccessAsUser'" $result.PermissionName | should -Be "LicenseManager.AccessAsUser" $result.ObjectId | should -Be "T2qU_E28O0GgkLLIYRPsTwE" } It "Should fail when Filter is empty" { - { Get-AzureADMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 -Filter } | Should -Throw "Missing an argument for parameter 'Filter'.*" - } + { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Filter } | Should -Throw "Missing an argument for parameter 'Filter'.*" + } + It "Property parameter should work" { + $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Property PermissionName + $result | Should -Not -BeNullOrEmpty + $result.PermissionName | Should -Be 'LicenseManager.AccessAsUser' + + Should -Invoke -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Property is empty" { + { Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalDelegatedPermissionClassification" - $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId 0008861a-d455-4671-bd24-ce9b3bfce288 + $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" $params = Get-Parameters -data $result.Parameters $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-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 index 8c44f8e39..959fcdbb8 100644 --- a/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 @@ -10,7 +10,7 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "Id" = "a47d4510-08c8-4437-99e9-71ca88e7af0f" + "Id" = "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" "AlternateNotificationEmails" = "example@contoso.com" "GroupLifetimeInDays" = "99" "ManagedGroupTypes" = "Selected" @@ -27,7 +27,7 @@ Describe "New-EntraGroupLifecyclePolicy " { It "Should return created GroupLifecyclePolicy" { $result = New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + $result.Id | should -Be "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" $result.GroupLifetimeInDays | should -Be "99" $result.ManagedGroupTypes | should -Be "Selected" $result.AlternateNotificationEmails | should -Be "example@contoso.com" @@ -54,7 +54,7 @@ Describe "New-EntraGroupLifecyclePolicy " { } It "Result should Contain ObjectId" { $result = New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" - $result.ObjectId | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + $result.ObjectId | should -Be "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraGroupLifecyclePolicy" @@ -63,5 +63,18 @@ Describe "New-EntraGroupLifecyclePolicy " { $params = Get-Parameters -data $result.Parameters $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 + { New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 b/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 index ac04e4720..22efd90cc 100644 --- a/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 @@ -10,7 +10,7 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "Id" = "04fee326-10cf-4211-8edd-d2bd3f4a9a9c" + "Id" = "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" "CreatedDateTime" = "5/7/2024 10:52:23 AM" "DisplayName" = "NamedLocation" "ModifiedDateTime" = "5/7/2024 10:52:23 AM" @@ -41,7 +41,7 @@ Describe "New-EntraNamedLocationPolicy " { $ipRanges2.cidrAddress = "6.5.4.2/30" $result = New-EntraNamedLocationPolicy -OdataType "#microsoft.graph.ipNamedLocation" -DisplayName "NamedLocation" -IpRanges @($ipRanges1, $ipRanges2) -IsTrusted $false $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be "04fee326-10cf-4211-8edd-d2bd3f4a9a9c" + $result.Id | should -Be "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" Should -Invoke -CommandName New-MgIdentityConditionalAccessNamedLocation -ModuleName Microsoft.Graph.Entra -Times 1 } @@ -65,7 +65,7 @@ Describe "New-EntraNamedLocationPolicy " { } It "Result should Contain ObjectId" { $result = New-EntraNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true - $result.ObjectId | should -Be "04fee326-10cf-4211-8edd-d2bd3f4a9a9c" + $result.ObjectId | should -Be "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" } It "Should contain params inside BodyParameter" { $result = New-EntraNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true @@ -82,5 +82,18 @@ Describe "New-EntraNamedLocationPolicy " { $params = Get-Parameters -data $result.Parameters $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 + { New-EntraNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/New-EntraPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/New-EntraPermissionGrantPolicy.Tests.ps1 index 0d6803c23..810f654a3 100644 --- a/test/module/Entra/New-EntraPermissionGrantPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraPermissionGrantPolicy.Tests.ps1 @@ -15,7 +15,7 @@ BeforeAll { "Description" = "My new permission grant policy" "DisplayName" = "My new permission grant policy" "Excludes" = @{} - "Includes" = @("bddda1ec-0174-44d5-84e2-47fb0ac01595") + "Includes" = @("22cc22cc-dd33-ee44-ff55-66aa66aa66aa") "Parameters" = $args } ) @@ -32,7 +32,7 @@ Describe "New-EntraPermissionGrantPolicy" { $result.Id | should -Be "my_new_permission_grant_policy_id" $result.DisplayName | should -Be "My new permission grant policy" $result.Description | should -Be "My new permission grant policy" - $result.Includes | should -Be @("bddda1ec-0174-44d5-84e2-47fb0ac01595") + $result.Includes | should -Be @("22cc22cc-dd33-ee44-ff55-66aa66aa66aa") $result.DeletedDateTime | should -Be "2/8/2024 6:39:16 AM" Should -Invoke -CommandName New-MgPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra -Times 1 @@ -57,5 +57,18 @@ Describe "New-EntraPermissionGrantPolicy" { $params = Get-Parameters -data $result.Parameters $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 + { New-EntraPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 b/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 index fbe75c238..079fd8af5 100644 --- a/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 +++ b/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 @@ -22,40 +22,40 @@ Describe "Set-EntraAuthorizationPolicy" { Should -Invoke -CommandName Update-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1 } - It "Should fail when AllowedToSignUpEmailBasedSubscriptions is invalid" { + It "Should fail when AllowedToSignUpEmailBasedSubscriptions is invalid" { { Set-EntraAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowedToSignUpEmailBasedSubscriptions'.*" } - It "Should fail when AllowedToSignUpEmailBasedSubscriptions is empty" { + It "Should fail when AllowedToSignUpEmailBasedSubscriptions is empty" { { Set-EntraAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions } | Should -Throw "Missing an argument for parameter 'AllowedToSignUpEmailBasedSubscriptions'.*" } - It "Should fail when AllowedToUseSSPR is invalid" { + It "Should fail when AllowedToUseSSPR is invalid" { { Set-EntraAuthorizationPolicy -AllowedToUseSSPR 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowedToUseSSPR'*" } - It "Should fail when AllowedToUseSSPR is empty" { + It "Should fail when AllowedToUseSSPR is empty" { { Set-EntraAuthorizationPolicy -AllowedToUseSSPR } | Should -Throw "Missing an argument for parameter 'AllowedToUseSSPR'.*" } - It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is invalid" { + It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is invalid" { { Set-EntraAuthorizationPolicy -AllowEmailVerifiedUsersToJoinOrganization 'a' } | Should -Throw "Cannot process argument transformation on parameter 'AllowEmailVerifiedUsersToJoinOrganization'*" } - It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is empty" { + It "Should fail when AllowEmailVerifiedUsersToJoinOrganization is empty" { { Set-EntraAuthorizationPolicy -AllowEmailVerifiedUsersToJoinOrganization } | Should -Throw "Missing an argument for parameter 'AllowEmailVerifiedUsersToJoinOrganization'.*" } - It "Should fail when BlockMsolPowerShell is invalid" { + It "Should fail when BlockMsolPowerShell is invalid" { { Set-EntraAuthorizationPolicy -BlockMsolPowerShell 'a' } | Should -Throw "Cannot process argument transformation on parameter 'BlockMsolPowerShell'*" } - It "Should fail when BlockMsolPowerShell is empty" { + It "Should fail when BlockMsolPowerShell is empty" { { Set-EntraAuthorizationPolicy -BlockMsolPowerShell } | Should -Throw "Missing an argument for parameter 'BlockMsolPowerShell'.*" } - It "Should fail when DefaultUserRolePermissions is invalid" { + It "Should fail when DefaultUserRolePermissions is invalid" { { Set-EntraAuthorizationPolicy -DefaultUserRolePermissions 'a' } | Should -Throw "Cannot process argument transformation on parameter 'DefaultUserRolePermissions'*" } - It "Should fail when DefaultUserRolePermissions is empty" { + It "Should fail when DefaultUserRolePermissions is empty" { { Set-EntraAuthorizationPolicy -DefaultUserRolePermissions } | Should -Throw "Missing an argument for parameter 'DefaultUserRolePermissions'.*" } - It "Should fail when Description is empty" { + It "Should fail when Description is empty" { { Set-EntraAuthorizationPolicy -Description } | Should -Throw "Missing an argument for parameter 'Description'.*" } - It "Should fail when DisplayName is empty" { + It "Should fail when DisplayName is empty" { { Set-EntraAuthorizationPolicy -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" } It "Should contain 'User-Agent' header" { @@ -66,5 +66,22 @@ Describe "Set-EntraAuthorizationPolicy" { $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' + $DefaultUserRolePermissions = New-Object -TypeName Microsoft.Open.MSGraph.Model.DefaultUserRolePermissions + $DefaultUserRolePermissions.AllowedToCreateApps = $true + $DefaultUserRolePermissions.AllowedToCreateSecurityGroups = $true + $DefaultUserRolePermissions.AllowedToReadOtherUsers = $true + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Set-EntraAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions $false -AllowedToUseSSPR $false -AllowEmailVerifiedUsersToJoinOrganization $true -BlockMsolPowerShell $true -DefaultUserRolePermissions $DefaultUserRolePermissions -Description "test" -DisplayName "Authorization Policies" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 index e1f9cd5f3..c03e24809 100644 --- a/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 +++ b/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 @@ -10,7 +10,7 @@ BeforeAll { $scriptblock = { return @( [PSCustomObject]@{ - "Id" = "a47d4510-08c8-4437-99e9-71ca88e7af0f" + "Id" = "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" "AlternateNotificationEmails" = "admingroup@contoso.com" "GroupLifetimeInDays" = "100" "ManagedGroupTypes" = "All" @@ -27,7 +27,7 @@ Describe "Set-EntraGroupLifecyclePolicy " { It "Should return updated GroupLifecyclePolicy" { $result = Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + $result.Id | should -Be "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" $result.GroupLifetimeInDays | should -Be "100" $result.ManagedGroupTypes | should -Be "All" $result.AlternateNotificationEmails | should -Be "admingroup@contoso.com" @@ -41,27 +41,40 @@ Describe "Set-EntraGroupLifecyclePolicy " { { Set-EntraGroupLifecyclePolicy -Id -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'Id'.*" } It "Should fail when GroupLifetimeInDays is invalid" { - { Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot process argument transformation on parameter 'GroupLifetimeInDays'.*" + { Set-EntraGroupLifecyclePolicy -Id "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" -GroupLifetimeInDays a -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Cannot process argument transformation on parameter 'GroupLifetimeInDays'.*" } It "Should fail when GroupLifetimeInDays is empty" { - { Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'GroupLifetimeInDays'.*" + { Set-EntraGroupLifecyclePolicy -Id "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" -GroupLifetimeInDays -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'GroupLifetimeInDays'.*" } It "Should fail when ManagedGroupTypes is empty" { - { Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 99 -ManagedGroupTypes -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'ManagedGroupTypes'.*" + { Set-EntraGroupLifecyclePolicy -Id "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" -GroupLifetimeInDays 99 -ManagedGroupTypes -AlternateNotificationEmails "example@contoso.com" } | Should -Throw "Missing an argument for parameter 'ManagedGroupTypes'.*" } It "Should fail when AlternateNotificationEmails is empty" { - { Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails } | Should -Throw "Missing an argument for parameter 'AlternateNotificationEmails'.*" + { Set-EntraGroupLifecyclePolicy -Id "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails } | Should -Throw "Missing an argument for parameter 'AlternateNotificationEmails'.*" } It "Result should Contain ObjectId" { - $result = Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" - $result.ObjectId | should -Be "a47d4510-08c8-4437-99e9-71ca88e7af0f" + $result = Set-EntraGroupLifecyclePolicy -Id "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $result.ObjectId | should -Be "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraGroupLifecyclePolicy" - $result = Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $result = Set-EntraGroupLifecyclePolicy -Id "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" $params = Get-Parameters -data $result.Parameters $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 + { Set-EntraGroupLifecyclePolicy -Id "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 index 384ca22da..4f96e7fe5 100644 --- a/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 +++ b/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 @@ -38,5 +38,18 @@ Describe "Set-EntraPermissionGrantPolicy" { $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 + { Set-EntraPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName "Test" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 b/test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 index 8a6afa3d9..851a21e5c 100644 --- a/test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 +++ b/test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 @@ -13,9 +13,9 @@ BeforeAll { "Id" = "microsoft-all-application-permissions" "DeletedDateTime" = "2/8/2024 6:39:16 AM" "Description" = "Includes all application permissions (app roles), for all APIs, for any client application." - "DisplayName" = "All application permissions, for any client app" + "DisplayName" = "All application" "Excludes" = @{} - "Includes" = @("bddda1ec-0174-44d5-84e2-47fb0ac01595") + "Includes" = @("00aa00aa-bb11-cc22-dd33-44ee44ee44ee") "Parameters" = $args } ) @@ -48,6 +48,16 @@ Describe "Get-EntraBetaPermissionGrantPolicy" { $params = Get-Parameters -data $result.Parameters $params.PermissionGrantPolicyId | Should -Be "microsoft-all-application-permissions" } + It "Property parameter should work" { + $result = Get-EntraBetaPermissionGrantPolicy -Id "microsoft-all-application-permissions" -Property DisplayName + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | Should -Be 'All application' + + Should -Invoke -CommandName Get-MgBetaPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when Property is empty" { + { Get-EntraBetaPermissionGrantPolicy -Id "microsoft-all-application-permissions" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" + } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaPermissionGrantPolicy" @@ -55,5 +65,18 @@ Describe "Get-EntraBetaPermissionGrantPolicy" { $params = Get-Parameters -data $result.Parameters $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-EntraBetaPermissionGrantPolicy -Id "microsoft-all-application-permissions" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file From 7517a17deaec0396ab05ebfbd5702090c80d3f39 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Thu, 29 Aug 2024 16:03:33 +0530 Subject: [PATCH 08/11] conflict --- .../customizations/Get-EntraTrustedCertificateAuthority.ps1 | 4 +--- .../Get-EntraBetaTrustedCertificateAuthority.ps1 | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/module/Entra/customizations/Get-EntraTrustedCertificateAuthority.ps1 b/module/Entra/customizations/Get-EntraTrustedCertificateAuthority.ps1 index 0a82ba7c7..c62f3c8b5 100644 --- a/module/Entra/customizations/Get-EntraTrustedCertificateAuthority.ps1 +++ b/module/Entra/customizations/Get-EntraTrustedCertificateAuthority.ps1 @@ -74,8 +74,7 @@ $responseData = Get-MgOrganizationCertificateBasedAuthConfiguration @params -Headers $customHeaders $response= @() - if($responseData){ - $responseData.CertificateAuthorities | ForEach-Object { + $responseData.CertificateAuthorities | ForEach-Object { if ( ([string]::IsNullOrEmpty($TrustedIssuer) -and [string]::IsNullOrEmpty($TrustedIssuerSki)) -or (![string]::IsNullOrEmpty($TrustedIssuer) -and ![string]::IsNullOrEmpty($TrustedIssuerSki) -and $_.Issuer -eq $TrustedIssuer -and $_.IssuerSki -eq $TrustedIssuerSki) -or @@ -97,7 +96,6 @@ $dataJson = ConvertTo-Json $data $response += [Newtonsoft.Json.JsonConvert]::DeserializeObject($dataJson, [Microsoft.Open.AzureAD.Model.CertificateAuthorityInformation]) } - } } $response } diff --git a/module/EntraBeta/customizations/Get-EntraBetaTrustedCertificateAuthority.ps1 b/module/EntraBeta/customizations/Get-EntraBetaTrustedCertificateAuthority.ps1 index 4c0b94481..7c996af5c 100644 --- a/module/EntraBeta/customizations/Get-EntraBetaTrustedCertificateAuthority.ps1 +++ b/module/EntraBeta/customizations/Get-EntraBetaTrustedCertificateAuthority.ps1 @@ -75,8 +75,7 @@ $responseData = Get-MgBetaOrganizationCertificateBasedAuthConfiguration @params -Headers $customHeaders $response= @() - if($responseData){ - $responseData.CertificateAuthorities | ForEach-Object { + $responseData.CertificateAuthorities | ForEach-Object { if ( ([string]::IsNullOrEmpty($TrustedIssuer) -and [string]::IsNullOrEmpty($TrustedIssuerSki)) -or (![string]::IsNullOrEmpty($TrustedIssuer) -and ![string]::IsNullOrEmpty($TrustedIssuerSki) -and $_.Issuer -eq $TrustedIssuer -and $_.IssuerSki -eq $TrustedIssuerSki) -or @@ -98,7 +97,6 @@ $dataJson = ConvertTo-Json $data $response += [Newtonsoft.Json.JsonConvert]::DeserializeObject($dataJson, [Microsoft.Open.AzureAD.Model.CertificateAuthorityInformation]) } - } } $response } From 15b807b67497264bea27701696519a53900acdf9 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Wed, 4 Sep 2024 13:30:44 +0530 Subject: [PATCH 09/11] updated mock test cases --- .../Add-EntraLifecyclePolicyGroup.Tests.ps1 | 11 ++++++++--- .../Get-EntraPermissionGrantPolicy.Tests.ps1 | 12 +++++++++--- ...lDelegatedPermissionClassification.Tests.ps1 | 10 ++++++++-- .../New-EntraGroupLifecyclePolicy.Tests.ps1 | 10 ++++++++-- .../New-EntraNamedLocationPolicy.Tests.ps1 | 10 ++++++++-- .../New-EntraPermissionGrantPolicy.Tests.ps1 | 10 ++++++++-- .../Set-EntraAuthorizationPolicy.Tests.ps1 | 17 +++++++++++++---- .../Set-EntraGroupLifecyclePolicy.Tests.ps1 | 14 ++++++++++---- .../Set-EntraPermissionGrantPolicy.Tests.ps1 | 12 ++++++++---- ...Get-EntraBetaPermissionGrantPolicy.Tests.ps1 | 10 ++++++++-- 10 files changed, 88 insertions(+), 28 deletions(-) diff --git a/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 index d1fb3034d..cdf5117b2 100644 --- a/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 +++ b/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 @@ -44,9 +44,14 @@ Describe "Add-EntraLifecyclePolicyGroup " { It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraLifecyclePolicyGroup" - $result = Add-EntraLifecyclePolicyGroup -Id "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -GroupId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + Add-EntraLifecyclePolicyGroup -Id "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -GroupId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraLifecyclePolicyGroup" + + Should -Invoke -CommandName Add-MgGroupToLifecyclePolicy -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-EntraPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1 index 539c272f9..a30a4470a 100644 --- a/test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1 +++ b/test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1 @@ -61,9 +61,15 @@ Describe "Get-EntraPermissionGrantPolicy" { It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraPermissionGrantPolicy" - $result = Get-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + $result = Get-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions" + $result | Should -Not -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraPermissionGrantPolicy" + + Should -Invoke -CommandName Get-MgPolicyPermissionGrantPolicy -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-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 index c76fc9b84..18f3a261f 100644 --- a/test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 +++ b/test/module/Entra/Get-EntraServicePrincipalDelegatedPermissionClassification.Tests.ps1 @@ -70,8 +70,14 @@ Describe "Get-EntraServicePrincipalDelegatedPermissionClassification" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalDelegatedPermissionClassification" $result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + $result | Should -Not -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalDelegatedPermissionClassification" + + Should -Invoke -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -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/New-EntraGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 index 959fcdbb8..c5a4038a9 100644 --- a/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 @@ -60,8 +60,14 @@ Describe "New-EntraGroupLifecyclePolicy " { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraGroupLifecyclePolicy" $result = New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + $result | Should -Not -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraGroupLifecyclePolicy" + + Should -Invoke -CommandName New-MgGroupLifecyclePolicy -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/New-EntraNamedLocationPolicy.Tests.ps1 b/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 index 22efd90cc..066371d07 100644 --- a/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 @@ -79,8 +79,14 @@ Describe "New-EntraNamedLocationPolicy " { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraNamedLocationPolicy" $result = New-EntraNamedLocationPolicy -OdataType "#microsoft.graph.countryNamedLocation" -DisplayName "NamedLocation" -CountriesAndRegions @("US", "ID", "CA") -IncludeUnknownCountriesAndRegions $true - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + $result | Should -Not -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraNamedLocationPolicy" + + Should -Invoke -CommandName New-MgIdentityConditionalAccessNamedLocation -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/New-EntraPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/New-EntraPermissionGrantPolicy.Tests.ps1 index 810f654a3..7525967b2 100644 --- a/test/module/Entra/New-EntraPermissionGrantPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraPermissionGrantPolicy.Tests.ps1 @@ -54,8 +54,14 @@ Describe "New-EntraPermissionGrantPolicy" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraPermissionGrantPolicy" $result = New-EntraPermissionGrantPolicy -Id "my_new_permission_grant_policy_id" -DisplayName "MyNewPermissionGrantPolicy" -Description "My new permission grant policy" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + $result | Should -Not -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraPermissionGrantPolicy" + + Should -Invoke -CommandName New-MgPolicyPermissionGrantPolicy -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/Set-EntraAuthorizationPolicy.Tests.ps1 b/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 index 079fd8af5..6e8aeb385 100644 --- a/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 +++ b/test/module/Entra/Set-EntraAuthorizationPolicy.Tests.ps1 @@ -59,13 +59,22 @@ Describe "Set-EntraAuthorizationPolicy" { { Set-EntraAuthorizationPolicy -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" } It "Should contain 'User-Agent' header" { - Mock -CommandName Update-MgPolicyAuthorizationPolicy -MockWith {$args} -ModuleName Microsoft.Graph.Entra $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraAuthorizationPolicy" + + $DefaultUserRolePermissions = New-Object -TypeName Microsoft.Open.MSGraph.Model.DefaultUserRolePermissions + $DefaultUserRolePermissions.AllowedToCreateApps = $true + $DefaultUserRolePermissions.AllowedToCreateSecurityGroups = $true + $DefaultUserRolePermissions.AllowedToReadOtherUsers = $true + Set-EntraAuthorizationPolicy -AllowedToSignUpEmailBasedSubscriptions $false -AllowedToUseSSPR $false -AllowEmailVerifiedUsersToJoinOrganization $true -BlockMsolPowerShell $true -DefaultUserRolePermissions $DefaultUserRolePermissions -Description "test" -DisplayName "Authorization Policies" - $result = Set-EntraAuthorizationPolicy - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraAuthorizationPolicy" + + Should -Invoke -CommandName Update-MgPolicyAuthorizationPolicy -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/Set-EntraGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 index c03e24809..70f848b0d 100644 --- a/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 +++ b/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 @@ -25,7 +25,7 @@ BeforeAll { Describe "Set-EntraGroupLifecyclePolicy " { Context "Test for Set-EntraGroupLifecyclePolicy" { It "Should return updated GroupLifecyclePolicy" { - $result = Set-EntraGroupLifecyclePolicy -Id a47d4510-08c8-4437-99e9-71ca88e7af0f -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $result = Set-EntraGroupLifecyclePolicy -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" $result | Should -Not -BeNullOrEmpty $result.Id | should -Be "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" $result.GroupLifetimeInDays | should -Be "100" @@ -59,9 +59,15 @@ Describe "Set-EntraGroupLifecyclePolicy " { It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraGroupLifecyclePolicy" - $result = Set-EntraGroupLifecyclePolicy -Id "22cc22cc-dd33-ee44-ff55-66aa66aa66aa" -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + $result = Set-EntraGroupLifecyclePolicy -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All" + $result | Should -Not -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraGroupLifecyclePolicy" + + Should -Invoke -CommandName Update-MgGroupLifecyclePolicy -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/Set-EntraPermissionGrantPolicy.Tests.ps1 b/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 index 4f96e7fe5..bc7e6030f 100644 --- a/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 +++ b/test/module/Entra/Set-EntraPermissionGrantPolicy.Tests.ps1 @@ -31,12 +31,16 @@ Describe "Set-EntraPermissionGrantPolicy" { { Set-EntraPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*" } It "Should contain 'User-Agent' header" { - Mock -CommandName Update-MgPolicyPermissionGrantPolicy -MockWith {$args} -ModuleName Microsoft.Graph.Entra $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraPermissionGrantPolicy" - $result = Set-EntraPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName "Test" - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + Set-EntraPermissionGrantPolicy -Id "permission_grant_policy" -Description "test" -DisplayName "Test" + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraPermissionGrantPolicy" + + Should -Invoke -CommandName Update-MgPolicyPermissionGrantPolicy -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/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 b/test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 index 851a21e5c..faa1cb932 100644 --- a/test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 +++ b/test/module/EntraBeta/Get-EntraBetaPermissionGrantPolicy.Tests.ps1 @@ -62,8 +62,14 @@ Describe "Get-EntraBetaPermissionGrantPolicy" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaPermissionGrantPolicy" $result = Get-EntraBetaPermissionGrantPolicy -Id "microsoft-all-application-permissions" - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + $result | Should -Not -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaPermissionGrantPolicy" + + Should -Invoke -CommandName Get-MgBetaPolicyPermissionGrantPolicy -ModuleName Microsoft.Graph.Entra.Beta -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } } It "Should execute successfully without throwing an error" { # Disable confirmation prompts From b1405cbe9b6dd444494b7691d99b2cd37edaced9 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Wed, 4 Sep 2024 13:35:32 +0530 Subject: [PATCH 10/11] updated --- .../Entra/Get-EntraAuthorizationPolicy.Tests.ps1 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 b/test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 index 27034e939..8328a29a0 100644 --- a/test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 +++ b/test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1 @@ -61,11 +61,16 @@ Describe "Get-EntraAuthorizationPolicy" { { Get-EntraAuthorizationPolicy -Property } | Should -Throw "Missing an argument for parameter 'Property'*" } It "Should contain 'User-Agent' header" { - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraAuthorizationPolicy" + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraAuthorizationPolicy" - $result = Get-EntraAuthorizationPolicy - $params = Get-Parameters -data $result.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + Get-EntraAuthorizationPolicy + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraAuthorizationPolicy" + + Should -Invoke -CommandName Get-MgPolicyAuthorizationPolicy -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 From 9f31257ba88e913a2f23f4dea823c0c6e36aa772 Mon Sep 17 00:00:00 2001 From: "Snehal Kotwal (Perennial Systems Inc)" Date: Thu, 19 Sep 2024 12:54:26 +0530 Subject: [PATCH 11/11] updated --- test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 | 2 +- test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 | 2 +- test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 | 2 +- test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 b/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 index cdf5117b2..ed2bfc30d 100644 --- a/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 +++ b/test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1 @@ -20,7 +20,7 @@ BeforeAll { Mock -CommandName Add-MgGroupToLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "Add-EntraLifecyclePolicyGroup " { +Describe "Add-EntraLifecyclePolicyGroup" { Context "Test for Add-EntraLifecyclePolicyGroup" { It "Should return created LifecyclePolicyGroup" { $result = Add-EntraLifecyclePolicyGroup -Id "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -GroupId "11bb11bb-cc22-dd33-ee44-55ff55ff55ff diff --git a/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 index c5a4038a9..9d7c2fb5f 100644 --- a/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraGroupLifecyclePolicy.Tests.ps1 @@ -22,7 +22,7 @@ BeforeAll { Mock -CommandName New-MgGroupLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "New-EntraGroupLifecyclePolicy " { +Describe "New-EntraGroupLifecyclePolicy" { Context "Test for New-EntraGroupLifecyclePolicy" { It "Should return created GroupLifecyclePolicy" { $result = New-EntraGroupLifecyclePolicy -GroupLifetimeInDays 99 -ManagedGroupTypes "Selected" -AlternateNotificationEmails "example@contoso.com" diff --git a/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 b/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 index 066371d07..0b471c63e 100644 --- a/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraNamedLocationPolicy.Tests.ps1 @@ -32,7 +32,7 @@ BeforeAll { Mock -CommandName New-MgIdentityConditionalAccessNamedLocation -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "New-EntraNamedLocationPolicy " { +Describe "New-EntraNamedLocationPolicy" { Context "Test for New-EntraNamedLocationPolicy" { It "Should return created NamedLocationPolicy" { $ipRanges1 = New-Object -TypeName Microsoft.Open.MSGraph.Model.IpRange diff --git a/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 b/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 index 70f848b0d..de87873ed 100644 --- a/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 +++ b/test/module/Entra/Set-EntraGroupLifecyclePolicy.Tests.ps1 @@ -22,7 +22,7 @@ BeforeAll { Mock -CommandName Update-MgGroupLifecyclePolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra } -Describe "Set-EntraGroupLifecyclePolicy " { +Describe "Set-EntraGroupLifecyclePolicy" { Context "Test for Set-EntraGroupLifecyclePolicy" { It "Should return updated GroupLifecyclePolicy" { $result = Set-EntraGroupLifecyclePolicy -Id "a47d4510-08c8-4437-99e9-71ca88e7af0f" -GroupLifetimeInDays 200 -AlternateNotificationEmails "admingroup@contoso.com" -ManagedGroupTypes "All"