Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions test/module/Entra/Add-EntraLifecyclePolicyGroup.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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

$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 "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 "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 "11bb11bb-cc22-dd33-ee44-55ff55ff55ff" } | Should -Throw "Missing an argument for parameter 'Id'.*"
}
It "Should fail when GroupId is invalid" {
{ 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 "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"

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
$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
}
}
}
}
89 changes: 89 additions & 0 deletions test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# ------------------------------------------------------------------------------
# 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]@{
"DefaultUserRolePermissions" = @{AllowedToCreateApps = "False"; AllowedToCreateSecurityGroups = "False"; AllowedToCreateTenants = "True";
AllowedToReadBitlockerKeysForOwnedDevice = "True"; AllowedToReadOtherUsers = "False"; PermissionGrantPoliciesAssigned = "";
AdditionalProperties = ""
}
"DeletedDateTime" = $null
"GuestUserRoleId" = "00aa00aa-bb11-cc22-dd33-44ee44ee44ee"
"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-EntraAuthorizationPolicy" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test for parameter Id

Copy link
Collaborator

@snehalkotwal snehalkotwal Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KenitoInc Id parameter is missing in mg graph so it is not working on the Entra cmdlet.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context "Test for Get-EntraAuthorizationPolicy" {
It "Should return AuthorizationPolicy" {
$result = Get-EntraAuthorizationPolicy
$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 '00aa00aa-bb11-cc22-dd33-44ee44ee44ee'
$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 "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"

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
$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
}
}
}
}
88 changes: 88 additions & 0 deletions test/module/Entra/Get-EntraPermissionGrantPolicy.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# ------------------------------------------------------------------------------
# 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" = "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"
"Excludes" = @{}
"Includes" = @("00aa00aa-bb11-cc22-dd33-44ee44ee44ee")
"Parameters" = $args
}
)
}

Mock -CommandName Get-MgPolicyPermissionGrantPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra
}

Describe "Get-EntraPermissionGrantPolicy" {
Context "Test for Get-EntraPermissionGrantPolicy" {
It "Should return specific PermissionGrantPolicy" {
$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-EntraPermissionGrantPolicy -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string."
}
It "Should fail when Id is empty" {
{ 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-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-EntraPermissionGrantPolicy -Id "microsoft-all-application-permissions"
$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"

$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
$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
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# ------------------------------------------------------------------------------
# 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" = "T2qU_E28O0GgkLLIYRPsTwE"
"Classification" = "low"
"PermissionId" = "22cc22cc-dd33-ee44-ff55-66aa66aa66aa"
"PermissionName" = "LicenseManager.AccessAsUser"
"Parameters" = $args
}
)
}

Mock -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra
}

Describe "Get-EntraServicePrincipalDelegatedPermissionClassification" {
Context "Test for Get-EntraServicePrincipalDelegatedPermissionClassification" {
It "Should return specific ServicePrincipalDelegatedPermissionClassification" {
$result = Get-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "aaaaaaaa-bbbb-cccc-1111-222222222222"
$result | Should -Not -BeNullOrEmpty
$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-EntraServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "" } | Should -Throw "Cannot bind argument to parameter 'ServicePrincipalId' because it is an empty string.*"
}
It "Should fail when ServicePrincipalId is empty" {
{ 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 "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 "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 "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 "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-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 "aaaaaaaa-bbbb-cccc-1111-222222222222"
$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
$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
}
}
}
}
Loading