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/Entra/Add-EntraApplicationOwner.Tests.ps1 b/test/module/Entra/Add-EntraApplicationOwner.Tests.ps1 new file mode 100644 index 000000000..144c4e32d --- /dev/null +++ b/test/module/Entra/Add-EntraApplicationOwner.Tests.ps1 @@ -0,0 +1,38 @@ +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 New-MgApplicationOwnerByRef -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Add-EntraApplicationOwner" { + Context "Test for Add-EntraApplicationOwner" { + It "Should return empty object"{ + $result = Add-EntraApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -RefObjectId "412be9d1-1460-4061-8eed-cca203fcb215" + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName New-MgApplicationOwnerByRef -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { Add-EntraApplicationOwner -ObjectId "" -RefObjectId "" } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + Mock -CommandName New-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Add-EntraApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -RefObjectId "412be9d1-1460-4061-8eed-cca203fcb215" + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "c81d387e-d431-43b4-b12e-f07cbb35b771" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName New-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraApplicationOwner" + + $result = Add-EntraApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -RefObjectId "412be9d1-1460-4061-8eed-cca203fcb215" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Add-EntraMSAdministrativeUnitMember.Tests.ps1 b/test/module/Entra/Add-EntraMSAdministrativeUnitMember.Tests.ps1 new file mode 100644 index 000000000..41a7fe3c1 --- /dev/null +++ b/test/module/Entra/Add-EntraMSAdministrativeUnitMember.Tests.ps1 @@ -0,0 +1,38 @@ +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 New-MgDirectoryAdministrativeUnitMemberByRef -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Add-EntraMSAdministrativeUnitMember" { + Context "Test for Add-EntraMSAdministrativeUnitMember" { + It "Should return empty object"{ + $result = Add-EntraMSAdministrativeUnitMember -Id "f306a126-cf2e-439d-b20f-95ce4bcb7ffa" -RefObjectId "d6873b36-81d6-4c5e-bec0-9e3ca2c86846" + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName New-MgDirectoryAdministrativeUnitMemberByRef -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { Add-EntraMSAdministrativeUnitMember -Id "" -RefObjectId "" } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should contain AdministrativeUnitId in parameters when passed Id to it" { + Mock -CommandName New-MgDirectoryAdministrativeUnitMemberByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Add-EntraMSAdministrativeUnitMember -Id "f306a126-cf2e-439d-b20f-95ce4bcb7ffa" -RefObjectId "d6873b36-81d6-4c5e-bec0-9e3ca2c86846" + $params = Get-Parameters -data $result + $params.AdministrativeUnitId | Should -Be "f306a126-cf2e-439d-b20f-95ce4bcb7ffa" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName New-MgDirectoryAdministrativeUnitMemberByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraMSAdministrativeUnitMember" + + $result = Add-EntraMSAdministrativeUnitMember -Id "f306a126-cf2e-439d-b20f-95ce4bcb7ffa" -RefObjectId "d6873b36-81d6-4c5e-bec0-9e3ca2c86846" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Add-EntraMSApplicationOwner.Tests.ps1 b/test/module/Entra/Add-EntraMSApplicationOwner.Tests.ps1 new file mode 100644 index 000000000..8d464b73c --- /dev/null +++ b/test/module/Entra/Add-EntraMSApplicationOwner.Tests.ps1 @@ -0,0 +1,45 @@ +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 New-MgApplicationOwnerByRef -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Add-EntraMSApplicationOwner" { + Context "Test for Add-EntraMSApplicationOwner" { + It "Should return empty object"{ + $result = Add-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -RefObjectId "412be9d1-1460-4061-8eed-cca203fcb215" + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName New-MgApplicationOwnerByRef -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { Add-EntraMSApplicationOwner -ObjectId "" -RefObjectId "" } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + Mock -CommandName New-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Add-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -RefObjectId "412be9d1-1460-4061-8eed-cca203fcb215" + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "c81d387e-d431-43b4-b12e-f07cbb35b771" + } + It "Should contain OdataId in parameters when passed RefObjectId to it" { + Mock -CommandName New-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Add-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -RefObjectId "412be9d1-1460-4061-8eed-cca203fcb215" + $params = Get-Parameters -data $result + $params.OdataId | Should -Be "https://graph.microsoft.com/v1.0/directoryObjects/412be9d1-1460-4061-8eed-cca203fcb215" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName New-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraMSApplicationOwner" + + $result = Add-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -RefObjectId "412be9d1-1460-4061-8eed-cca203fcb215" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Add-EntraMSScopedRoleMembership.Tests.ps1 b/test/module/Entra/Add-EntraMSScopedRoleMembership.Tests.ps1 new file mode 100644 index 000000000..5605c4dd5 --- /dev/null +++ b/test/module/Entra/Add-EntraMSScopedRoleMembership.Tests.ps1 @@ -0,0 +1,54 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + + $scriptblock = { + # Write-Host "Mocking New-MgDirectoryAdministrativeUnitScopedRoleMember with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "Id" = "412be9d1-1460-4061-8eed-cca203fcb215" + "AdministrativeUnitId" = "c9ab56cc-e349-4237-856e-cab03157a91e" + "RoleId" = "526b7173-5a6e-49dc-88ec-b677a9093709" + } + ) + } + + Mock -CommandName New-MgDirectoryAdministrativeUnitScopedRoleMember -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra + + $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRolememberinfo + $RoleMember.Id = "96d4258f-9187-4e6c-b031-724e789b9323" +} + +Describe "Add-EntraMSScopedRoleMembership" { + Context "Test for Add-EntraMSScopedRoleMembership" { + It "Should not return empty object"{ + $result = Add-EntraMSScopedRoleMembership -Id "c9ab56cc-e349-4237-856e-cab03157a91e" -RoleId "526b7173-5a6e-49dc-88ec-b677a9093709" -RoleMemberInfo $RoleMember + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be @('412be9d1-1460-4061-8eed-cca203fcb215') + + Should -Invoke -CommandName New-MgDirectoryAdministrativeUnitScopedRoleMember -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { Add-EntraMSScopedRoleMembership -Id "" -RoleId "" } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should contain AdministrativeUnitId in parameters when passed Id to it" { + Mock -CommandName New-MgDirectoryAdministrativeUnitScopedRoleMember -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Add-EntraMSScopedRoleMembership -Id "c9ab56cc-e349-4237-856e-cab03157a91e" -RoleId "526b7173-5a6e-49dc-88ec-b677a9093709" -RoleMemberInfo $RoleMember + $params = Get-Parameters -data $result + $params.AdministrativeUnitId | Should -Be "c9ab56cc-e349-4237-856e-cab03157a91e" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName New-MgDirectoryAdministrativeUnitScopedRoleMember -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraMSScopedRoleMembership" + + $result = Add-EntraMSScopedRoleMembership -Id "c9ab56cc-e349-4237-856e-cab03157a91e" -RoleId "526b7173-5a6e-49dc-88ec-b677a9093709" -RoleMemberInfo $RoleMember + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Mock-Enable-EntraDirectoryRole.Tests.ps1 b/test/module/Entra/Enable-EntraDirectoryRole.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-Enable-EntraDirectoryRole.Tests.ps1 rename to test/module/Entra/Enable-EntraDirectoryRole.Tests.ps1 diff --git a/test/module/Entra/Entra.Tests.ps1 b/test/module/Entra/Entra.Tests.ps1 deleted file mode 100644 index f8aa11c46..000000000 --- a/test/module/Entra/Entra.Tests.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -if($null -eq (Get-Module -Name Microsoft.Graph.Entra)){ - Import-Module Microsoft.Graph.Entra -} - -Import-Module Pester - -$psmPath = (Get-Module Microsoft.Graph.Entra).Path -$testReportPath = join-path $psscriptroot "..\..\..\TestReport\Entra" -$mockScriptsPath = join-path $psscriptroot "..\..\..\test\module\Entra\Mock-*.Tests.ps1" - -$testOutputFile = "$testReportPath\TestResults.xml" -if (!(test-path -path $testReportPath)) {new-item -path $testReportPath -itemtype directory} - -$mockScripts = Get-ChildItem -Path $mockScriptsPath | ForEach-Object { $_.FullName } - -$config = New-PesterConfiguration -$config.Run.Path = $mockScripts -$config.Run.PassThru = $true -$config.Run.Exit = $true -$config.CodeCoverage.Enabled = $true -$config.CodeCoverage.CoveragePercentTarget = 100 -$config.CodeCoverage.Path = $psmPath -$config.TestResult.Enabled = $true -$config.TestResult.OutputPath = $testOutputFile -$config.Output.Verbosity = "Detailed" - -Invoke-Pester -Configuration $config \ No newline at end of file diff --git a/test/module/Entra/Get-EntraApplication.Tests.ps1 b/test/module/Entra/Get-EntraApplication.Tests.ps1 index 61c81cc91..592fe354d 100644 --- a/test/module/Entra/Get-EntraApplication.Tests.ps1 +++ b/test/module/Entra/Get-EntraApplication.Tests.ps1 @@ -1,44 +1,126 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -# ------------------------------------------------------------------------------ -Describe "Get-EntraApplication" { - BeforeAll { - if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ - Import-Module Microsoft.Graph.Entra - } - } - - It "Should support minimum set of parameter sets" { - $GetAzureADApplication = Get-Command Get-EntraApplication - $GetAzureADApplication.ParameterSets.Name | Should -BeIn @("GetQuery", "GetVague", "GetById") - $GetAzureADApplication.Visibility | Should -Be "Public" - $GetAzureADApplication.CommandType | Should -Be "Function" +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra } - - It "Should return a list of applications by default" { - $GetAzureADApplication = Get-Command Get-EntraApplication - $GetAzureADApplication.ModuleName | Should -Be "Microsoft.Graph.Entra" - $GetAzureADApplication.DefaultParameterSet | Should -Be "GetQuery" + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + # Write-Host "Mocking Get-MgApplication with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "AppId" = "5f783237-3457-45d8-93e7-a0edb1cfbfd1" + "DeletedDateTime" = $null + "Id" = "111cc9b5-fce9-485e-9566-c68debafac5f" + "DisplayName" = "Mock-App" + "Info" = @{LogoUrl=""; MarketingUrl=""; PrivacyStatementUrl=""; SupportUrl=""; TermsOfServiceUrl=""} + "IsDeviceOnlyAuthSupported" = $True + "IsFallbackPublicClient" = $true + "KeyCredentials" = @{CustomKeyIdentifier = @(211, 174, 247);DisplayName =""; Key="";KeyId="d903c7a3-75ea-4772-8935-5c0cf82068a7";Type="Symmetric";Usage="Sign"} + "OptionalClaims" = @{AccessToken=""; IdToken=""; Saml2Token=""} + "ParentalControlSettings" = @{CountriesBlockedForMinors=$null; LegalAgeGroupRule="Allow"} + "PasswordCredentials" = @{} + "PublicClient" = @{RedirectUris=$null} + "PublisherDomain" = "M365x99297270.onmicrosoft.com" + "SignInAudience" = "AzureADandPersonalMicrosoftAccount" + "Web" = @{HomePageUrl="https://localhost/demoapp"; ImplicitGrantSettings=""; LogoutUrl="";} + "Parameters" = $args + } + ) } - It 'Should have List parameterSet' { - $GetAzureADApplication = Get-Command Get-EntraApplication - $ListParameterSet = $GetAzureADApplication.ParameterSets | Where-Object Name -eq "GetQuery" - $ListParameterSet.Parameters.Name | Should -Contain All - $ListParameterSet.Parameters.Name | Should -Contain Filter - $ListParameterSet.Parameters.Name | Should -Contain Top - } + Mock -CommandName Get-MgApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraApplication" { + Context "Test for Get-EntraApplication" { + It "Should return specific application" { + $result = Get-EntraApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be @('111cc9b5-fce9-485e-9566-c68debafac5f') - It 'Should have Get parameterSet' { - $GetAzureADApplication = Get-Command Get-EntraApplication - $GetParameterSet = $GetAzureADApplication.ParameterSets | Where-Object Name -eq "GetById" - $GetParameterSet.Parameters.Name | Should -Contain ObjectId - } + Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraApplication -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should return all applications" { + $result = Get-EntraApplication -All $true + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraApplication -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should return specific application by searchstring" { + $result = Get-EntraApplication -SearchString 'Mock-App' + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be 'Mock-App' + + Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should return specific application by filter" { + $result = Get-EntraApplication -Filter "DisplayName -eq 'Mock-App'" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be 'Mock-App' - It 'Should have GetViaIdentity parameterSet' { - $GetAzureADApplication = Get-Command Get-EntraApplication - $GetViaIdentityParameterSet = $GetAzureADApplication.ParameterSets | Where-Object Name -eq "GetVague" - $GetViaIdentityParameterSet.Parameters.Name | Should -Contain SearchString - $GetViaIdentityParameterSet.Parameters.Name | Should -Contain All + Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should return top application" { + $result = Get-EntraApplication -Top 1 + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $result.ObjectId | should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + $result = Get-EntraApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $params = Get-Parameters -data $result.Parameters + $params.ApplicationId | Should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" + } + It "Should contain Filter in parameters when passed SearchString to it" { + $result = Get-EntraApplication -SearchString 'Mock-App' + $params = Get-Parameters -data $result.Parameters + $params.Filter | Should -Match "Mock-App" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplication" + $result = Get-EntraApplication -SearchString 'Mock-App' + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + It "Should support minimum set of parameter sets" { + $GetAzureADApplication = Get-Command Get-EntraApplication + $GetAzureADApplication.ParameterSets.Name | Should -BeIn @("GetQuery", "GetVague", "GetById") + $GetAzureADApplication.Visibility | Should -Be "Public" + $GetAzureADApplication.CommandType | Should -Be "Function" + } + + It "Should return a list of applications by default" { + $GetAzureADApplication = Get-Command Get-EntraApplication + $GetAzureADApplication.ModuleName | Should -Be "Microsoft.Graph.Entra" + $GetAzureADApplication.DefaultParameterSet | Should -Be "GetQuery" + } + It 'Should have List parameterSet' { + $GetAzureADApplication = Get-Command Get-EntraApplication + $ListParameterSet = $GetAzureADApplication.ParameterSets | Where-Object Name -eq "GetQuery" + $ListParameterSet.Parameters.Name | Should -Contain All + $ListParameterSet.Parameters.Name | Should -Contain Filter + $ListParameterSet.Parameters.Name | Should -Contain Top + } + It 'Should have Get parameterSet' { + $GetAzureADApplication = Get-Command Get-EntraApplication + $GetParameterSet = $GetAzureADApplication.ParameterSets | Where-Object Name -eq "GetById" + $GetParameterSet.Parameters.Name | Should -Contain ObjectId + } + It 'Should have GetViaIdentity parameterSet' { + $GetAzureADApplication = Get-Command Get-EntraApplication + $GetViaIdentityParameterSet = $GetAzureADApplication.ParameterSets | Where-Object Name -eq "GetVague" + $GetViaIdentityParameterSet.Parameters.Name | Should -Contain SearchString + $GetViaIdentityParameterSet.Parameters.Name | Should -Contain All + } } } \ No newline at end of file diff --git a/test/module/Entra/Get-EntraApplicationExtensionProperty.Tests.ps1 b/test/module/Entra/Get-EntraApplicationExtensionProperty.Tests.ps1 new file mode 100644 index 000000000..5b7fc4d33 --- /dev/null +++ b/test/module/Entra/Get-EntraApplicationExtensionProperty.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 = { + # Write-Host "Mocking Get-EntraApplicationExtensionProperty with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "Id" = "dc587a80-d49c-4700-a73b-57227856fc32" + "Name" = "extension_36ee4c6c081240a2b820b22ebd02bce3_NewAttribute" + "TargetObjects" = {} + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgApplicationExtensionProperty -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra + } + + Describe "Get-EntraApplicationExtensionProperty" { + Context "Test for Get-EntraApplicationExtensionProperty" { + It "Should not return empty" { + $result = Get-EntraApplicationExtensionProperty -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgApplicationExtensionProperty -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraApplicationExtensionProperty -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Result should Contain ObjectId" { + $result = Get-EntraApplicationExtensionProperty -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" + $result.ObjectId | should -Be "dc587a80-d49c-4700-a73b-57227856fc32" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + $result = Get-EntraApplicationExtensionProperty -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" + $params = Get-Parameters -data $result.Parameters + $params.ApplicationId | Should -Be "dc587a80-d49c-4700-a73b-57227856fc32" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationExtensionProperty" + $result = Get-EntraApplicationExtensionProperty -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" + $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-EntraApplicationKeyCredential.Tests.ps1 b/test/module/Entra/Get-EntraApplicationKeyCredential.Tests.ps1 new file mode 100644 index 000000000..cb47d14bf --- /dev/null +++ b/test/module/Entra/Get-EntraApplicationKeyCredential.Tests.ps1 @@ -0,0 +1,44 @@ +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 = { + @{ + "KeyCredentials" = @( + @{ + "CustomKeyIdentifier" = "" + "EndDate" = "10/23/2024 11:36:56 AM" + "KeyId" = "52ab6cca-bc59-4f06-8450-75a3d2b8e53b" + "StartDate" = "11/22/2023 11:35:16 AM" + "Type" = "Symmetric" + "Usage" = "Sign" + "Value" = "" + "Parameters" = $args + } + ) + } + } + + Mock -CommandName Get-MgApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra + } + + Describe "Get-EntraApplicationKeyCredential" { + Context "Test for Get-EntraApplicationKeyCredential" { + It "Should not return empty" { + $result = Get-EntraApplicationKeyCredential -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraApplicationKeyCredential -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationKeyCredential" + $result = Get-EntraApplicationKeyCredential -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" + $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-EntraApplicationOwner.Tests.ps1 b/test/module/Entra/Get-EntraApplicationOwner.Tests.ps1 new file mode 100644 index 000000000..e806d2502 --- /dev/null +++ b/test/module/Entra/Get-EntraApplicationOwner.Tests.ps1 @@ -0,0 +1,51 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $mockResponse = { + return @{ + value = @( + @{ + Id = "e3108c4d-86ff-4ceb-9429-24e85b4b8cea" + ageGroup = $null + onPremisesLastSyncDateTime = $null + creationType = $null + imAddresses = {"adelev@m365x99297270.onmicrosoft.com"} + preferredLanguage = $null + mail = "AdeleV@M365x99297270.OnMicrosoft.com" + securityIdentifier = "S-1-12-1-1093396945-1080104032-2731339150-364051459" + identities = {} + consentProvidedForMinor = $null + onPremisesUserPrincipalName = $null + Parameters = $args + } + ) + } + } + + Mock -CommandName Invoke-GraphRequest -MockWith $mockResponse -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraApplicationOwner"{ + Context "Test for Get-EntraApplicationOwner"{ + It "Should return application owner" { + $result = Get-EntraApplicationOwner -ObjectId "e3108c4d-86ff-4ceb-9429-24e85b4b8cea" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be @('e3108c4d-86ff-4ceb-9429-24e85b4b8cea') + + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraApplicationOwner -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationOwner" + $result = Get-EntraApplicationOwner -ObjectId "e3108c4d-86ff-4ceb-9429-24e85b4b8cea" + $params = Get-Parameters -data $result.Parameters + $a= $params | ConvertTo-json | ConvertFrom-Json + $a.headers.'User-Agent' | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Get-EntraApplicationPasswordCredential.Tests.ps1 b/test/module/Entra/Get-EntraApplicationPasswordCredential.Tests.ps1 new file mode 100644 index 000000000..52a9babd4 --- /dev/null +++ b/test/module/Entra/Get-EntraApplicationPasswordCredential.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 = { + @{ + "PasswordCredentials" = @( + @{ + "CustomKeyIdentifier" = {116, 101, 115, 116} + "DisplayName" = "" + "EndDateTime" = "10/23/2024 11:36:56 AM" + "KeyId" = "52ab6cca-bc59-4f06-8450-75a3d2b8e53b" + "StartDateTime" = "11/22/2023 11:35:16 AM" + "Hint" = "123" + "SecretText" = "" + "Parameters" = $args + } + ) + } + } + + Mock -CommandName Get-MgApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra + } + + Describe "Get-EntraApplicationPasswordCredential" { + Context "Test for Get-EntraApplicationPasswordCredential" { + It "Should not return empty" { + $result = Get-EntraApplicationPasswordCredential -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraApplicationPasswordCredential -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId'*" + } + It "Should fail when ObjectId is null" { + { Get-EntraApplicationPasswordCredential -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" + } + It "Should fail when invalid parameter is passed" { + { Get-EntraApplicationPasswordCredential -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'*" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationPasswordCredential" + $result = Get-EntraApplicationPasswordCredential -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" + $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-EntraDeletedApplication.Tests.ps1 b/test/module/Entra/Get-EntraDeletedApplication.Tests.ps1 new file mode 100644 index 000000000..b32b7e398 --- /dev/null +++ b/test/module/Entra/Get-EntraDeletedApplication.Tests.ps1 @@ -0,0 +1,140 @@ +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]@{ + "AddIns" = {} + "AppRoles" = {} + "GroupMembershipClaims" = {} + "IdentifierUris" = {} + "Info" = @{ + LogoUrl=""; + MarketingUrl=""; + PrivacyStatementUrl=""; + SupportUrl=""; + TermsOfServiceUrl=""; + } + "IsDeviceOnlyAuthSupported" = $null + "KeyCredentials" = {} + "OptionalClaims" = {} + "ParentalControlSettings" = @{ + CountriesBlockedForMinors=@{}; + LegalAgeGroupRule="Allow"; + } + "PasswordCredentials" = {} + "Api" = @{ + AcceptMappedClaims=@{}; + KnownClientApplications=@{}; + Oauth2PermissionScopes=@{}; + PreAuthorizedApplications=@{}; + RequestedAccessTokenVersion="2"; + } + "PublicClient" = @{ + RedirectUris=@{}; + } + "PublisherDomain" = "M365x99297270.onmicrosoft.com" + "Web" = @{ + HomePageUrl=""; + ImplicitGrantSettings=""; + LogoutUrl=""; + RedirectUriSettings=@{}; + RedirectUris=@{}; + } + "RequiredResourceAccess" = $null + "AppId" = "9c17362d-20b6-4572-bb6f-600e57c840e5" + "AppManagementPolicies" = $null + "ApplicationTemplateId" = $null + "Certification" = {} + "CreatedDateTime" = "12/12/2023 11:28:45 AM" + "CreatedOnBehalfOf" = {} + "DefaultRedirectUri" = $null + "DeletedDateTime" = "12/12/2023 12:23:39 PM" + "Description" = $null + "DisabledByMicrosoftStatus" = $null + "DisplayName" = "Mock-test-App" + "ExtensionProperties" = $null + "FederatedIdentityCredentials" = $null + "HomeRealmDiscoveryPolicies" = $null + "Id" = "01157307-373c-47b0-889a-3bc57033d73e" + "IsFallbackPublicClient" = $null + "Logo" = $null + "Notes" = $null + "Oauth2RequirePostResponse" = $null + "Owners" = $null + "RequestSignatureVerification" = {} + "SamlMetadataUrl" = $null + "ServiceManagementReference" = $null + "ServicePrincipalLockConfiguration" = {} + "SignInAudience" = "AzureADandPersonalMicrosoftAccount" + "Spa" = {} + "Synchronization" = {} + "Tags" = {} + "TokenEncryptionKeyId" = $null + "TokenIssuancePolicies" = $null + "TokenLifetimePolicies" = $null + "UniqueName" = $null + "VerifiedPublisher" = {} + "AdditionalProperties" = {} + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgDirectoryDeletedItemAsApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraDeletedApplication" { + Context "Test for Get-EntraDeletedApplication" { + It "Should return all applications" { + $result = Get-EntraDeletedApplication | ConvertTo-Json | ConvertFrom-Json + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraDeletedApplication -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should fail when invalid parameter is passed" { + { Get-EntraDeletedApplication -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'*" + } + It "Should return specific application by searchstring" { + $result = Get-EntraDeletedApplication -SearchString 'Mock-test-App' | ConvertTo-Json | ConvertFrom-Json + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be 'Mock-test-App' + + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should return specific application by filter" { + $result = Get-EntraDeletedApplication -Filter "DisplayName -eq 'Mock-test-App'" | ConvertTo-Json | ConvertFrom-Json + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be 'Mock-test-App' + + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should return top application" { + $result = Get-EntraDeletedApplication -Top 1 | ConvertTo-Json | ConvertFrom-Json + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraDeletedApplication -Filter "DisplayName -eq 'Mock-test-App'" | ConvertTo-Json | ConvertFrom-Json + $result.ObjectId | should -Be "01157307-373c-47b0-889a-3bc57033d73e" + } + It "Should contain Filter in parameters when passed SearchString to it" { + $result = Get-EntraDeletedApplication -SearchString 'Mock-test-App' | ConvertTo-Json | ConvertFrom-Json + $params = Get-Parameters -data $result.Parameters + $params.Filter | Should -Match "Mock-test-App" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDeletedApplication" + $result = Get-EntraDeletedApplication -Top 1 | ConvertTo-Json | ConvertFrom-Json + $params = Get-Parameters -data $result.Parameters + $a= $params | ConvertTo-json | ConvertFrom-Json + $a.headers.'User-Agent' | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Mock-Get-EntraDevice.Tests.ps1 b/test/module/Entra/Get-EntraDevice.Tests.ps1 similarity index 92% rename from test/module/Entra/Mock-Get-EntraDevice.Tests.ps1 rename to test/module/Entra/Get-EntraDevice.Tests.ps1 index d0c363daa..66921f422 100644 --- a/test/module/Entra/Mock-Get-EntraDevice.Tests.ps1 +++ b/test/module/Entra/Get-EntraDevice.Tests.ps1 @@ -37,6 +37,7 @@ BeforeAll { "TransitiveMemberOf" = $null "TrustType" = $null "PhysicalIds" = @{} + "Parameters" = $args } ) } @@ -90,26 +91,19 @@ Describe "Get-EntraDevice" { $result.ObjectId | should -Be "74825acb-c984-4b54-ab65-d38347ea5e90" } It "Should contain DeviceId in parameters when passed ObjectId to it" { - Mock -CommandName Get-MgDevice -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Get-EntraDevice -ObjectId "74825acb-c984-4b54-ab65-d38347ea5e90" - $params = Get-Parameters -data $result + $params = Get-Parameters -data $result.Parameters $params.DeviceId | Should -Be "74825acb-c984-4b54-ab65-d38347ea5e90" } It "Should contain Filter in parameters when passed SearchString to it" { - Mock -CommandName Get-MgDevice -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Get-EntraDevice -SearchString 'Mock-Device' - $params = Get-Parameters -data $result + $params = Get-Parameters -data $result.Parameters $params.Filter | Should -Match "Mock-Device" } It "Should contain 'User-Agent' header" { - Mock -CommandName Get-MgDevice -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDevice" - $result = Get-EntraDevice -SearchString 'Mock-Device' - $params = Get-Parameters -data $result + $params = Get-Parameters -data $result.Parameters $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } } diff --git a/test/module/Entra/Mock-Get-EntraDirectoryRole.Tests.ps1 b/test/module/Entra/Get-EntraDirectoryRole.Tests.ps1 similarity index 90% rename from test/module/Entra/Mock-Get-EntraDirectoryRole.Tests.ps1 rename to test/module/Entra/Get-EntraDirectoryRole.Tests.ps1 index 33c9ae24c..523c0930e 100644 --- a/test/module/Entra/Mock-Get-EntraDirectoryRole.Tests.ps1 +++ b/test/module/Entra/Get-EntraDirectoryRole.Tests.ps1 @@ -15,6 +15,7 @@ BeforeAll { "RoleTemplateId" = "ffd52fa5-98dc-465c-991d-fc073eb59f8f" "Members" = $null "ScopedMembers" = $null + "Parameters" = $args } ) } @@ -46,19 +47,14 @@ BeforeAll { $result.ObjectId | should -Be "dc587a80-d49c-4700-a73b-57227856fc32" } It "Should contain DirectoryRoleId in parameters when passed ObjectId to it" { - Mock -CommandName Get-MgDirectoryRole -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Get-EntraDirectoryRole -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" - $params = Get-Parameters -data $result + $params = Get-Parameters -data $result.Parameters $params.DirectoryRoleId | Should -Be "dc587a80-d49c-4700-a73b-57227856fc32" } It "Should contain 'User-Agent' header" { - Mock -CommandName Get-MgDirectoryRole -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDirectoryRole" - $result = Get-EntraDirectoryRole -ObjectId "dc587a80-d49c-4700-a73b-57227856fc32" - $params = Get-Parameters -data $result + $params = Get-Parameters -data $result.Parameters $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } } diff --git a/test/module/Entra/Mock-Get-EntraGroup.Tests.ps1 b/test/module/Entra/Get-EntraGroup.Tests.ps1 similarity index 89% rename from test/module/Entra/Mock-Get-EntraGroup.Tests.ps1 rename to test/module/Entra/Get-EntraGroup.Tests.ps1 index 9cfcaad48..37e5e4a1f 100644 --- a/test/module/Entra/Mock-Get-EntraGroup.Tests.ps1 +++ b/test/module/Entra/Get-EntraGroup.Tests.ps1 @@ -14,6 +14,7 @@ BeforeAll { "Description" = "test" "MailNickname" = "demoNickname" "SecurityEnabled" = "True" + "Parameters" = $args } ) } @@ -67,26 +68,19 @@ Describe "Get-EntraGroup" { $result.ObjectId | should -Be "056b2531-005e-4f3e-be78-01a71ea30a04" } It "Should contain GroupId in parameters when passed ObjectId to it" { - Mock -CommandName Get-MgGroup -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Get-EntraGroup -ObjectId "056b2531-005e-4f3e-be78-01a71ea30a04" - $params = Get-Parameters -data $result + $params = Get-Parameters -data $result.Parameters $params.GroupId | Should -Be "056b2531-005e-4f3e-be78-01a71ea30a04" } It "Should contain Filter in parameters when passed SearchString to it" { - Mock -CommandName Get-MgGroup -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $result = Get-EntraGroup -SearchString 'demo' - $params = Get-Parameters -data $result + $params = Get-Parameters -data $result.Parameters $params.Filter | Should -Match "demo" } It "Should contain 'User-Agent' header" { - Mock -CommandName Get-MgGroup -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraGroup" - $result = Get-EntraGroup -SearchString 'demo' - $params = Get-Parameters -data $result + $params = Get-Parameters -data $result.Parameters $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue } } diff --git a/test/module/Entra/Get-EntraMSAdministrativeUnit.Tests.ps1 b/test/module/Entra/Get-EntraMSAdministrativeUnit.Tests.ps1 new file mode 100644 index 000000000..cece368dc --- /dev/null +++ b/test/module/Entra/Get-EntraMSAdministrativeUnit.Tests.ps1 @@ -0,0 +1,78 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + # Write-Host "Mocking Get-MgDirectoryAdministrativeUnit with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "DeletedDateTime" = $null + "Description" = "Mock-Unit" + "DisplayName" = "Mock-Unit" + "Extensions" = $null + "Id" = "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + "Members" = $null + "ScopedRoleMembers" = $null + "Visibility" = $null + "AdditionalProperties" = {} + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgDirectoryAdministrativeUnit -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraMSAdministrativeUnit" { + Context "Test for Get-EntraMSAdministrativeUnit" { + It "Should return specific application" { + $result = Get-EntraMSAdministrativeUnit -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be @('09cb73a9-6d82-4d4d-a9f5-9e7ba0329106') + + Should -Invoke -CommandName Get-MgDirectoryAdministrativeUnit -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is empty" { + { Get-EntraMSAdministrativeUnit -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." + } + It "Should return all administrative units" { + $result = Get-EntraMSAdministrativeUnit -All $true + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgDirectoryAdministrativeUnit -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraMSAdministrativeUnit -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should return specific administrative unit by filter" { + $result = Get-EntraMSAdministrativeUnit -Filter "DisplayName -eq 'Mock-Unit'" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be 'Mock-Unit' + + Should -Invoke -CommandName Get-MgDirectoryAdministrativeUnit -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should return top administrative unit" { + $result = Get-EntraMSAdministrativeUnit -Top 1 + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgDirectoryAdministrativeUnit -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraMSAdministrativeUnit -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + $result.ObjectId | should -Be "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + } + It "Should contain AdministrativeUnitId in parameters when passed ObjectId to it" { + $result = Get-EntraMSAdministrativeUnit -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + $params = Get-Parameters -data $result.Parameters + $params.AdministrativeUnitId | Should -Be "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSAdministrativeUnit" + $result = Get-EntraMSAdministrativeUnit -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + $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-EntraMSAdministrativeUnitMember.Tests.ps1 b/test/module/Entra/Get-EntraMSAdministrativeUnitMember.Tests.ps1 new file mode 100644 index 000000000..72dfa5b66 --- /dev/null +++ b/test/module/Entra/Get-EntraMSAdministrativeUnitMember.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 = { + # Write-Host "Mocking Get-MgDirectoryAdministrativeUnitMember with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "DeletedDateTime" = $null + "Id" = "d67d8b7b-57e1-486e-9361-26a1e2f0e8fe" + "AdditionalProperties" = @{displayName="Tests1";givenName="Tests1"} + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgDirectoryAdministrativeUnitMember -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraMSAdministrativeUnitMember" { + Context "Test for Get-EntraMSAdministrativeUnitMember" { + It "Should return administrative unit member" { + $result = Get-EntraMSAdministrativeUnitMember -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgDirectoryAdministrativeUnitMember -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is empty" { + { Get-EntraMSAdministrativeUnitMember -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." + } + It "Should return all administrative units" { + $result = Get-EntraMSAdministrativeUnitMember -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" -All $true + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgDirectoryAdministrativeUnitMember -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraMSAdministrativeUnitMember -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should return top administrative unit" { + $result = Get-EntraMSAdministrativeUnitMember -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" -Top 1 + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgDirectoryAdministrativeUnitMember -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraMSAdministrativeUnitMember -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" -Top 1 + $result.ObjectId | should -Be "d67d8b7b-57e1-486e-9361-26a1e2f0e8fe" + } + It "Should contain AdministrativeUnitId in parameters when passed ObjectId to it" { + $result = Get-EntraMSAdministrativeUnitMember -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + $params = Get-Parameters -data $result.Parameters + $params.AdministrativeUnitId | Should -Be "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSAdministrativeUnitMember" + $result = Get-EntraMSAdministrativeUnitMember -Id "09cb73a9-6d82-4d4d-a9f5-9e7ba0329106" + $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/Mock-Get-EntraMSApplication.Tests.ps1 b/test/module/Entra/Get-EntraMSApplication.Tests.ps1 similarity index 77% rename from test/module/Entra/Mock-Get-EntraMSApplication.Tests.ps1 rename to test/module/Entra/Get-EntraMSApplication.Tests.ps1 index 31bab45b6..117eed4ff 100644 --- a/test/module/Entra/Mock-Get-EntraMSApplication.Tests.ps1 +++ b/test/module/Entra/Get-EntraMSApplication.Tests.ps1 @@ -32,6 +32,7 @@ BeforeAll { "PublisherDomain" = "M365x99297270.onmicrosoft.com" "SignInAudience" = "AzureADandPersonalMicrosoftAccount" "Web" = @{HomePageUrl="https://localhost/demoapp"; ImplicitGrantSettings=""; LogoutUrl="";} + "Parameters" = $args } ) } @@ -83,30 +84,22 @@ Describe "Get-EntraMSApplication" { It "Result should Contain ObjectId" { $result = Get-EntraMSApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" $result.ObjectId | should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" - } - # issue in addins param transformation in args, will uncomment after resolve. - # It "Should contain ApplicationId in parameters when passed ObjectId to it" { - # Mock -CommandName Get-MgApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra - - # $result = Get-EntraMSApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" - # $params = Get-Parameters -data $result - # $params.ApplicationId | Should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" - # } - # It "Should contain Filter in parameters when passed SearchString to it" { - # Mock -CommandName Get-MgApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra - - # $result = Get-EntraMSApplication -SearchString 'Mock-App' - # $params = Get-Parameters -data $result - # $params.Filter | Should -Match "Mock-App" - # } - # It "Should contain 'User-Agent' header" { - # Mock -CommandName Get-MgApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra - - # $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSApplication" - - # $result = Get-EntraMSApplication -SearchString 'Mock-App' - # $params = Get-Parameters -data $result - # $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - # } + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + $result = Get-EntraMSApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $params = Get-Parameters -data $result.Parameters + $params.ApplicationId | Should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" + } + It "Should contain Filter in parameters when passed SearchString to it" { + $result = Get-EntraMSApplication -SearchString 'Mock-App' + $params = Get-Parameters -data $result.Parameters + $params.Filter | Should -Match "Mock-App" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSApplication" + $result = Get-EntraMSApplication -SearchString 'Mock-App' + $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-EntraMSApplicationOwner.Tests.ps1 b/test/module/Entra/Get-EntraMSApplicationOwner.Tests.ps1 new file mode 100644 index 000000000..fb34e531d --- /dev/null +++ b/test/module/Entra/Get-EntraMSApplicationOwner.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 = { + # Write-Host "Mocking Get-MgApplicationOwner with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "Id" = "fd560167-ff1f-471a-8d74-3b0070abcea1" + "AdditionalProperties" = @{businessPhones={}; displayName="Conf Room Adams"; + mail="Adams@M365x99297270.OnMicrosoft.com"} + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgApplicationOwner -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraMSApplicationOwner" { + Context "Test for Get-EntraMSApplicationOwner" { + It "Should fail when ObjectId is empty" { + { Get-EntraMSApplicationOwner -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should return all application owners" { + $result = Get-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -All $true + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgApplicationOwner -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should return top application owner" { + $result = Get-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" -Top 1 + $result | Should -Not -BeNullOrEmpty + + Should -Invoke -CommandName Get-MgApplicationOwner -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" + $result.ObjectId | should -Be "fd560167-ff1f-471a-8d74-3b0070abcea1" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + $result = Get-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" + $params = Get-Parameters -data $result.Parameters + $params.ApplicationId | Should -Be "c81d387e-d431-43b4-b12e-f07cbb35b771" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSApplicationOwner" + $result = Get-EntraMSApplicationOwner -ObjectId "c81d387e-d431-43b4-b12e-f07cbb35b771" + $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-EntraMSDeletedDirectoryObject.Tests.ps1 b/test/module/Entra/Get-EntraMSDeletedDirectoryObject.Tests.ps1 new file mode 100644 index 000000000..5a043f8cd --- /dev/null +++ b/test/module/Entra/Get-EntraMSDeletedDirectoryObject.Tests.ps1 @@ -0,0 +1,46 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + return @( + [PSCustomObject]@{ + "Id" = "fd560167-ff1f-471a-8d74-3b0070abcea1" + "AdditionalProperties" = @{DisplayName="Test-App";} + "DeletedDateTime" = "2/2/2024 5:33:56 AM" + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgDirectoryDeletedItem -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraMSDeletedDirectoryObject"{ + It "Should fail when Id is empty" { + { Get-EntraMSDeletedDirectoryObject -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id'*" + } + It "Should fail when Id is null" { + { Get-EntraMSDeletedDirectoryObject -Id } | Should -Throw "Missing an argument for parameter 'Id'*" + } + It "Should fail when invalid parameter is passed" { + { Get-EntraMSDeletedDirectoryObject -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'*" + } + It "Result should Contain ObjectId" { + $result = Get-EntraMSDeletedDirectoryObject -Id "fd560167-ff1f-471a-8d74-3b0070abcea1" + $result.ObjectId | should -Be "fd560167-ff1f-471a-8d74-3b0070abcea1" + } + It "Should contain DirectoryObjectId in parameters when passed Id to it" { + $result = Get-EntraMSDeletedDirectoryObject -Id "fd560167-ff1f-471a-8d74-3b0070abcea1" + $params = Get-Parameters -data $result.Parameters + $params.DirectoryObjectId | Should -Be "fd560167-ff1f-471a-8d74-3b0070abcea1" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSDeletedDirectoryObject" + $result = Get-EntraMSDeletedDirectoryObject -Id "fd560167-ff1f-471a-8d74-3b0070abcea1" + $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-EntraMSPermissionGrantConditionSet.Tests.ps1 b/test/module/Entra/Get-EntraMSPermissionGrantConditionSet.Tests.ps1 new file mode 100644 index 000000000..d4ca9f7a3 --- /dev/null +++ b/test/module/Entra/Get-EntraMSPermissionGrantConditionSet.Tests.ps1 @@ -0,0 +1,57 @@ +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" = "4ccf1a57-4c5e-4ba6-9175-00407743b0e2" + "ClientApplicationIds" = {"All"} + "ClientApplicationPublisherIds" = {"All"} + "ClientApplicationTenantIds" = {"All"} + "ClientApplicationsFromVerifiedPublisherOnly" = $true + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgPolicyPermissionGrantPolicyInclude -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra + + Mock -CommandName Get-MgPolicyPermissionGrantPolicyExclude -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} +Describe "Get-EntraMSPermissionGrantConditionSet"{ + It "Should not return empty object for condition set 'includes'"{ + $result = Get-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "includes" -Id "4ccf1a57-4c5e-4ba6-9175-00407743b0e2" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgPolicyPermissionGrantPolicyInclude -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should not return empty object for condition set 'excludes'"{ + $result = Get-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "excludes" -Id "4ccf1a57-4c5e-4ba6-9175-00407743b0e2" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgPolicyPermissionGrantPolicyExclude -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { Get-EntraMSPermissionGrantConditionSet -PolicyId "" -ConditionSetType "" -Id ""} | Should -Throw "Cannot bind argument to parameter*" + } + It "Should fail when parameters are null" { + { Get-EntraMSPermissionGrantConditionSet -PolicyId -ConditionSetType -Id} | Should -Throw "Missing an argument for parameter*" + } + It "Should contain PermissionGrantConditionSetId in parameters when passed Id to it" { + $result = Get-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "includes" -Id "4ccf1a57-4c5e-4ba6-9175-00407743b0e2" + $params = Get-Parameters -data $result.Parameters + $params.PermissionGrantConditionSetId | Should -Be "4ccf1a57-4c5e-4ba6-9175-00407743b0e2" + } + It "Should contain PermissionGrantPolicyId in parameters when passed PolicyId to it" { + $result = Get-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "includes" -Id "4ccf1a57-4c5e-4ba6-9175-00407743b0e2" + $params = Get-Parameters -data $result.Parameters + $params.PermissionGrantPolicyId | Should -Be "policy1" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSPermissionGrantConditionSet" + $result = Get-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "includes" + $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-EntraMSScopedRoleMembership.Tests.ps1 b/test/module/Entra/Get-EntraMSScopedRoleMembership.Tests.ps1 new file mode 100644 index 000000000..81fdb11f2 --- /dev/null +++ b/test/module/Entra/Get-EntraMSScopedRoleMembership.Tests.ps1 @@ -0,0 +1,52 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + # Write-Host "Mocking Get-MgDirectoryAdministrativeUnitScopedRoleMember with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "RoleMemberInfo" = @{DisplayName="Raul Razo"; Id="97d57292-02b9-4360-afb9-058268b77754"; AdditionalProperties={}} + "AdministrativeUnitId" = "c9ab56cc-e349-4237-856e-cab03157a91e" + "Id" = "zTVcE8KFQ0W4bI9tvt6kz5G_C9Qom7tCpCzyrakzL7aSctWXuQJgQ6-5BYJot3dUU" + "RoleId" = "526b7173-5a6e-49dc-88ec-b677a9093709" + "AdditionalProperties" = {} + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgDirectoryAdministrativeUnitScopedRoleMember -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "Get-EntraMSScopedRoleMembership" { + Context "Test for Get-EntraMSScopedRoleMembership" { + It "Should not return empty object"{ + $result = Get-EntraMSScopedRoleMembership -Id "c9ab56cc-e349-4237-856e-cab03157a91e" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgDirectoryAdministrativeUnitScopedRoleMember -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should return specific scoped role membership"{ + $result = Get-EntraMSScopedRoleMembership -Id "c9ab56cc-e349-4237-856e-cab03157a91e" -ScopedRoleMembershipId "526b7173-5a6e-49dc-88ec-b677a9093709" + $result | Should -Not -BeNullOrEmpty + $result.Id | Should -Be "zTVcE8KFQ0W4bI9tvt6kz5G_C9Qom7tCpCzyrakzL7aSctWXuQJgQ6-5BYJot3dUU" + Should -Invoke -CommandName Get-MgDirectoryAdministrativeUnitScopedRoleMember -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { Get-EntraMSScopedRoleMembership -Id "" -ScopedRoleMembershipId "" } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should contain AdministrativeUnitId in parameters when passed Id to it" { + $result = Get-EntraMSScopedRoleMembership -Id "c9ab56cc-e349-4237-856e-cab03157a91e" -ScopedRoleMembershipId "526b7173-5a6e-49dc-88ec-b677a9093709" + $params = Get-Parameters -data $result.Parameters + $params.AdministrativeUnitId | Should -Be "c9ab56cc-e349-4237-856e-cab03157a91e" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSScopedRoleMembership" + $result = Get-EntraMSScopedRoleMembership -Id "c9ab56cc-e349-4237-856e-cab03157a91e" -ScopedRoleMembershipId "526b7173-5a6e-49dc-88ec-b677a9093709" + $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-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 b/test/module/Entra/Get-EntraMSServicePrincipalDelegatedPermissionClassification.Tests.ps1 new file mode 100644 index 000000000..cd28cac17 --- /dev/null +++ b/test/module/Entra/Get-EntraMSServicePrincipalDelegatedPermissionClassification.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" = "5XBeIKarUkypdm0tRsSAQwE" + "Classification" = "low" + "PermissionId" = "205e70e5-aba6-4c52-a976-6d2d46c48043" + "PermissionName" = "Sites.Read.All" + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} +Describe "Get-EntraMSServicePrincipalDelegatedPermissionClassification"{ + It "Should fail when ServicePrincipalId is empty" { + { Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "" } | Should -Throw "Cannot bind argument to parameter 'ServicePrincipalId' because it is an empty string." + } + It "Result should Contain ObjectId when ServicePrincipalId is passed" { + $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "fd560167-ff1f-471a-8d74-3b0070abcea1" + $result.ObjectId | should -Be "5XBeIKarUkypdm0tRsSAQwE" + } + It "Result should Contain ObjectId when Id is passed" { + $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "fd560167-ff1f-471a-8d74-3b0070abcea1" -Id "5XBeIKarUkypdm0tRsSAQwE" + $result.ObjectId | should -Be "5XBeIKarUkypdm0tRsSAQwE" + } + It "Should return specific application by filter" { + $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "fd560167-ff1f-471a-8d74-3b0070abcea1" -Filter "PermissionName eq 'Sites.Read.All'" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be '5XBeIKarUkypdm0tRsSAQwE' + Should -Invoke -CommandName Get-MgServicePrincipalDelegatedPermissionClassification -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should contain DelegatedPermissionClassificationId in parameters when passed Id to it" { + $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "fd560167-ff1f-471a-8d74-3b0070abcea1" -Id "5XBeIKarUkypdm0tRsSAQwE" + $params = Get-Parameters -data $result.Parameters + $params.DelegatedPermissionClassificationId | Should -Be "5XBeIKarUkypdm0tRsSAQwE" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraMSServicePrincipalDelegatedPermissionClassification" + $result = Get-EntraMSServicePrincipalDelegatedPermissionClassification -ServicePrincipalId "fd560167-ff1f-471a-8d74-3b0070abcea1" + $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-EntraServicePrincipalMembership.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalMembership.Tests.ps1 new file mode 100644 index 000000000..ec9d0d3fe --- /dev/null +++ b/test/module/Entra/Get-EntraServicePrincipalMembership.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" = "7dc3a38a-4c92-40bd-b290-ea00f85b478c" + "AdditionalProperties" = @{DeletedDateTime = $null} + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgServicePrincipalTransitiveMemberOf -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} +Describe "Get-EntraServicePrincipalMembership"{ + It "Result should not be empty" { + $result = Get-EntraServicePrincipalMembership -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgServicePrincipalTransitiveMemberOf -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraServicePrincipalMembership -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should return all applications" { + $result = Get-EntraServicePrincipalMembership -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -All $true + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgServicePrincipalTransitiveMemberOf -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraServicePrincipalMembership -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should return top application" { + $result = Get-EntraServicePrincipalMembership -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -Top 1 + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgServicePrincipalTransitiveMemberOf -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraServicePrincipalMembership -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $result.ObjectId | should -Be "7dc3a38a-4c92-40bd-b290-ea00f85b478c" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + $result = Get-EntraServicePrincipalMembership -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $params = Get-Parameters -data $result.Parameters + $params.ServicePrincipalId | Should -Be "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalMembership" + $result = Get-EntraServicePrincipalMembership -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $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-EntraServicePrincipalOAuth2PermissionGrant.tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalOAuth2PermissionGrant.tests.ps1 new file mode 100644 index 000000000..f5e18d753 --- /dev/null +++ b/test/module/Entra/Get-EntraServicePrincipalOAuth2PermissionGrant.tests.ps1 @@ -0,0 +1,60 @@ +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" = "9uBzRwC0s0CFCDQN6O4Ik_fW8XpadQNIoHik9aQxrVE" + "ClientId" = "4773e0f6-b400-40b3-8508-340de8ee0893" + "ConsentType" = "AllPrincipals" + "PrincipalId" = "7af1d6f7-755a-4803-a078-a4f5a431ad5" + "ResourceId" = "412be9d1-1460-4061-8eed-cca203fcb215" + "Scope" = "openid" + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgServicePrincipalOauth2PermissionGrant -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} +Describe "Get-EntraServicePrincipalOAuth2PermissionGrant"{ + It "Result should not be empty" { + $result = Get-EntraServicePrincipalOAuth2PermissionGrant -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgServicePrincipalOauth2PermissionGrant -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraServicePrincipalOAuth2PermissionGrant -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should return all applications" { + $result = Get-EntraServicePrincipalOAuth2PermissionGrant -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -All $true + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgServicePrincipalOauth2PermissionGrant -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraServicePrincipalOAuth2PermissionGrant -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should return top application" { + $result = Get-EntraServicePrincipalOAuth2PermissionGrant -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -Top 1 + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgServicePrincipalOauth2PermissionGrant -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraServicePrincipalOAuth2PermissionGrant -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $result.ObjectId | should -Be "9uBzRwC0s0CFCDQN6O4Ik_fW8XpadQNIoHik9aQxrVE" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + $result = Get-EntraServicePrincipalOAuth2PermissionGrant -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $params = Get-Parameters -data $result.Parameters + $params.ServicePrincipalId | Should -Be "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalOAuth2PermissionGrant" + $result = Get-EntraServicePrincipalOAuth2PermissionGrant -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $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-EntraServicePrincipalOwner.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalOwner.Tests.ps1 new file mode 100644 index 000000000..93b2ac7e4 --- /dev/null +++ b/test/module/Entra/Get-EntraServicePrincipalOwner.Tests.ps1 @@ -0,0 +1,80 @@ +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" = "fd560167-ff1f-471a-8d74-3b0070abcea1" + "DisplayName" = "Adams Smith" + "UserPrincipalName" = "Adams@contoso.com" + "UserType" = "Member" + "appRoles" = @{ + allowedMemberTypes=$null; + description="msiam_access"; + displayName="msiam_access"; + id="d0d7e4e4-96be-41c9-805a-08e0526868ad"; + isEnabled=$True; + origin="Application" + } + "oauth2PermissionScopes" = @{ + adminConsentDescription="Allow the application to access from tmplate test 3 on behalf of the signed-in user."; + adminConsentDisplayName="Access from tmplate test 3"; + id="64c2cef3-e118-4795-a580-a32bdbd7ba88"; + isEnabled=$True; + type="User"; + userConsentDescription="Allow the application to access from tmplate test 3 on your behalf."; + userConsentDisplayName="Access from tmplate test 3"; + value="user_impersonation" + } + "AdditionalProperties" = @{ + "@odata.type" = "#microsoft.graph.servicePrincipal"; + accountEnabled = $true + } + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgServicePrincipalOwner -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} +Describe "Get-EntraServicePrincipalOwner"{ + It "Result should not be empty" { + $result = Get-EntraServicePrincipalOwner -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgServicePrincipalOwner -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraServicePrincipalOwner -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should return all applications" { + $result = Get-EntraServicePrincipalOwner -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -All $true + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgServicePrincipalOwner -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraServicePrincipalOwner -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should return top application" { + $result = Get-EntraServicePrincipalOwner -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -Top 1 + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgServicePrincipalOwner -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraServicePrincipalOwner -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $result.ObjectId | should -Be "fd560167-ff1f-471a-8d74-3b0070abcea1" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + $result = Get-EntraServicePrincipalOwner -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $params = Get-Parameters -data $result.Parameters + $params.ServicePrincipalId | Should -Be "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalOwner" + $result = Get-EntraServicePrincipalOwner -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + $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-EntraTrustedCertificateAuthority.Tests.ps1 b/test/module/Entra/Get-EntraTrustedCertificateAuthority.Tests.ps1 new file mode 100644 index 000000000..79e4f920b --- /dev/null +++ b/test/module/Entra/Get-EntraTrustedCertificateAuthority.Tests.ps1 @@ -0,0 +1,59 @@ +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 = { + @{ + "CertificateAuthorities" = @( + @{ + "isRootAuthority" = $true + "certificateRevocationListUrl"= "https://example.crl" + "deltaCertificateRevocationListUrl"= "https://test.crl" + "certificate"= + "MIIDADCCAeigAwIBAgIQZUf+HS6ftbZKl+KtsZRsTDANBgkqhkiG9w0BAQsFADATMREwDwYDVQQDDAhtc2NtZGxldDAeFw0yNDAzMDYwNzIwMzhaFw0yNT + AzMDYwNzQwMzhaMBMxETAPBgNVBAMMCG1zY21kbGV0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApxIWxFGyuCi8kxmdjJI1WfY7zWqtgwvpk + wswBKrYmzN1/MzG2YX9yXsSLSd8Exh45P28ET3HpstVCXU1NnlQLW6c1ZEicRfj+Lv/h/z7Ckip8ccpJUNTaeyygC0pvqYjn+6zIVstMSOjNrWbQ8KrHTCh + lL3YvzD96PLbRHHHVcdT35fjezayWhMBSoc7rPO5Y0zgo9jKQt5rsIlEM72VssHy2H+dFkTCw2LbNy06oMoHpwXIDuQJSWXTu//G/DAuMIQ9hFDXh8hXJN5 + NCuesPF0tPqF4MbcGLREV2k6+MC7WZGsu2zcnr44Us0GZEq7F/h+hRGUeVGa/1Ve2oJmFqQIDAQABo1AwTjAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFA + YIKwYBBQUHAwIGCCsGAQUFBwMBMB0GA1UdDgQWBBSgpCZWuICzX6fIkpoBGmIRMVD3iDANBgkqhkiG9w0BAQsFAAOCAQEAAYGPkNJMnBQ44FEIc7uWBI1dy + 3qtSVX3oLIawt2qtRiy7QybJCrVFhh7L5P2wcJeQAKJCwc6kL+KzL1IUSrieNt2OK0FblcW6yqLE4RnJEaa30Uog5Cwji8EOXwo1SA6P6ltXMC3qULCNjsf + VivDE3urizDBDvA8qBnh7vaQooiIwwxA0i+lqeGjB4ySpIR4rjM7PNISOWctmdgoFydJkBsyjGfTilZWI2Y4duW+CULJtuIQtw/buY/Km+CcBbbLAbE+PGF + MpTynQ2Lh66QPFimLCldkgFBsy0ShM5zMHhd8zJP3iDZ46eO03Hw/NZK/GXya3gAzDxmzaEc6iiFSig==" + "issuer"= "CN=mscmdlet" + "issuerSki"= "A0A42656B880B35FA7C8929A011A62113150F788" + "Parameters" = $args + } + ) + } + } + + Mock -CommandName Get-MgOrganizationCertificateBasedAuthConfiguration -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} +Describe "Get-EntraTrustedCertificateAuthority"{ + It "Result should not be empty when no parameter passed" { + $result = Get-EntraTrustedCertificateAuthority + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgOrganizationCertificateBasedAuthConfiguration -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Result should not be empty when parameters are empty" { + $result = Get-EntraTrustedCertificateAuthority -TrustedIssuer '' -TrustedIssuerSki '' + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgOrganizationCertificateBasedAuthConfiguration -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when TrustedIssuer is null" { + { Get-EntraTrustedCertificateAuthority -TrustedIssuer } | Should -Throw "Missing an argument for parameter*" + } + It "Should fail when TrustedIssuerSki is null" { + { Get-EntraTrustedCertificateAuthority -TrustedIssuerSki } | Should -Throw "Missing an argument for parameter*" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraTrustedCertificateAuthority" + $result = Get-EntraTrustedCertificateAuthority | ConvertTo-json | ConvertFrom-Json + $params = Get-Parameters -data $result.Parameters + Write-Host $result + #$a.headers.'User-Agent' | Should -Be $userAgentHeaderValue + #$params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } +} \ No newline at end of file diff --git a/test/module/Entra/Invalid.Tests.ps1 b/test/module/Entra/Invalid.Tests.ps1 new file mode 100644 index 000000000..35edacd5f --- /dev/null +++ b/test/module/Entra/Invalid.Tests.ps1 @@ -0,0 +1,100 @@ +if($null -eq (Get-Module -Name Microsoft.Graph.Entra)){ + Import-Module Microsoft.Graph.Entra +} + +Describe "Invalid Tests"{ + It "Should fail when parameters are invalid"{ + $module = Get-Module -Name Microsoft.Graph.Entra + $module.ExportedCommands.Keys | ForEach-Object{ + $command = Get-Command $_ + { Invoke-Command $command -demo "" } | Should -Throw "A parameter cannot be found that matches parameter name 'demo'." + } + } + It "Should fail with 'TenantId' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'TenantId'){ + $commandScriptBlock = [scriptblock]::Create("$command -TenantId $objectId") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'TenantId'.*" + } + } + } + It "Should fail with 'Id' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'Id'){ + $commandScriptBlock = [scriptblock]::Create("$command -Id $objectId") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + } + } + It "Should fail with 'ObjectId' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'ObjectId'){ + $commandScriptBlock = [scriptblock]::Create("$command -ObjectId $objectId") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" + } + } + } + It "Should fail with 'All' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'All'){ + $commandScriptBlock = [scriptblock]::Create("$command -All ") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'All'*" + } + } + } + It "Should fail with 'Top' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'Top'){ + $commandScriptBlock = [scriptblock]::Create("$command -Top ") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'Top'*" + } + } + } + It "Should fail with 'Filter' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'Filter'){ + $commandScriptBlock = [scriptblock]::Create("$command -Filter ") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'Filter'*" + } + } + } + It "Should fail with 'SearchString' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'SearchString'){ + $commandScriptBlock = [scriptblock]::Create("$command -SearchString ") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'SearchString'*" + } + } + } + It "Should fail with exception when no parameter is passed" { + $cmdlets = @( + @{ CmdletName = 'Enable-EntraDirectoryRole'; Exception = "Could not resolve request to a valid role template." } + @{ CmdletName = 'New-EntraMSConditionalAccessPolicy'; Exception = "1006: 'displayName' cannot be null" }, + @{ CmdletName = 'New-EntraMSNamedLocationPolicy'; Exception = "1042: Unexpected type: namedLocationType for NamedLocations." }, + @{ CmdletName = 'New-EntraMSPermissionGrantPolicy'; Exception = "PermissionGrantPolicy's Id must not be null or empty." } + ) + $cmdlets | ForEach-Object { + $commandName = $_.CmdletName + $Exception = $_.Exception + $commandScriptBlock = [scriptblock]::Create("$commandName -ErrorAction Stop") + try { + Invoke-Command -ScriptBlock $commandScriptBlock + } + catch { $_ -match $Exception | Should -BeTrue } + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Mock-Get-EntraApplication.Tests.ps1 b/test/module/Entra/Mock-Get-EntraApplication.Tests.ps1 deleted file mode 100644 index 37517f687..000000000 --- a/test/module/Entra/Mock-Get-EntraApplication.Tests.ps1 +++ /dev/null @@ -1,102 +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 = { - # Write-Host "Mocking Get-MgApplication with parameters: $($args | ConvertTo-Json -Depth 3)" - return @( - [PSCustomObject]@{ - "AppId" = "5f783237-3457-45d8-93e7-a0edb1cfbfd1" - "DeletedDateTime" = $null - "Id" = "111cc9b5-fce9-485e-9566-c68debafac5f" - "DisplayName" = "Mock-App" - "Info" = @{LogoUrl=""; MarketingUrl=""; PrivacyStatementUrl=""; SupportUrl=""; TermsOfServiceUrl=""} - "IsDeviceOnlyAuthSupported" = $True - "IsFallbackPublicClient" = $true - "KeyCredentials" = @{CustomKeyIdentifier = @(211, 174, 247);DisplayName =""; Key="";KeyId="d903c7a3-75ea-4772-8935-5c0cf82068a7";Type="Symmetric";Usage="Sign"} - "OptionalClaims" = @{AccessToken=""; IdToken=""; Saml2Token=""} - "ParentalControlSettings" = @{CountriesBlockedForMinors=$null; LegalAgeGroupRule="Allow"} - "PasswordCredentials" = @{} - "PublicClient" = @{RedirectUris=$null} - "PublisherDomain" = "M365x99297270.onmicrosoft.com" - "SignInAudience" = "AzureADandPersonalMicrosoftAccount" - "Web" = @{HomePageUrl="https://localhost/demoapp"; ImplicitGrantSettings=""; LogoutUrl="";} - } - ) - } - - Mock -CommandName Get-MgApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra -} - -Describe "Get-EntraApplication" { - Context "Test for Get-EntraApplication" { - It "Should return specific application" { - $result = Get-EntraApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" - $result | Should -Not -BeNullOrEmpty - $result.Id | should -Be @('111cc9b5-fce9-485e-9566-c68debafac5f') - - Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when ObjectId is empty" { - { Get-EntraApplication -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." - } - It "Should return all applications" { - $result = Get-EntraApplication -All $true - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should fail when All is empty" { - { Get-EntraApplication -All } | Should -Throw "Missing an argument for parameter 'All'*" - } - It "Should return specific application by searchstring" { - $result = Get-EntraApplication -SearchString 'Mock-App' - $result | Should -Not -BeNullOrEmpty - $result.DisplayName | should -Be 'Mock-App' - - Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should return specific application by filter" { - $result = Get-EntraApplication -Filter "DisplayName -eq 'Mock-App'" - $result | Should -Not -BeNullOrEmpty - $result.DisplayName | should -Be 'Mock-App' - - Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Should return top application" { - $result = Get-EntraApplication -Top 1 - $result | Should -Not -BeNullOrEmpty - - Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 - } - It "Result should Contain ObjectId" { - $result = Get-EntraApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" - $result.ObjectId | should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" - } - It "Should contain ApplicationId in parameters when passed ObjectId to it" { - Mock -CommandName Get-MgApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra - - $result = Get-EntraApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" - $params = Get-Parameters -data $result - $params.ApplicationId | Should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" - } - It "Should contain Filter in parameters when passed SearchString to it" { - Mock -CommandName Get-MgApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra - - $result = Get-EntraApplication -SearchString 'Mock-App' - $params = Get-Parameters -data $result - $params.Filter | Should -Match "Mock-App" - } - It "Should contain 'User-Agent' header" { - Mock -CommandName Get-MgApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra - - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplication" - - $result = Get-EntraApplication -SearchString 'Mock-App' - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } - } -} \ No newline at end of file diff --git a/test/module/Entra/Mock-New-EntraApplication.Tests.ps1 b/test/module/Entra/New-EntraApplication.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-New-EntraApplication.Tests.ps1 rename to test/module/Entra/New-EntraApplication.Tests.ps1 diff --git a/test/module/Entra/New-EntraApplicationExtensionProperty.Tests.ps1 b/test/module/Entra/New-EntraApplicationExtensionProperty.Tests.ps1 new file mode 100644 index 000000000..0e70b3976 --- /dev/null +++ b/test/module/Entra/New-EntraApplicationExtensionProperty.Tests.ps1 @@ -0,0 +1,71 @@ +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]@{ + "DeletedDateTime" = $null + "Id" = "d083d12d-c280-4a23-a644-b4e71a09a4cb" + "AppDisplayName" = "Mock-App" + "DataType" = "String" + "IsSyncedFromOnPremises" = $False + "Name" = "extension_ec5edf3fe79749dd8d1e7760a1c1c943_NewAttribute" + "TargetObjects" = { "User" } + "Parameters" = $args + } + ) + } + + Mock -CommandName New-MgApplicationExtensionProperty -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra + + $targets = New-Object System.Collections.Generic.List[System.String] + $targets.Add('User') +} +Describe "New-EntraApplicationExtensionProperty"{ + It "Should return created extension property"{ + $result = New-EntraApplicationExtensionProperty -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -Name "NewAttribute" -TargetObjects $targets + $result | Should -Not -BeNullOrEmpty + $result.AppDisplayName | should -Be "Mock-App" + $result.Name | Should -Be "extension_ec5edf3fe79749dd8d1e7760a1c1c943_NewAttribute" + Should -Invoke -CommandName New-MgApplicationExtensionProperty -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { New-EntraApplicationExtensionProperty -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId'*" + } + It "Should fail when ObjectId is null" { + { New-EntraApplicationExtensionProperty -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" + } + It "Should fail when Name is null" { + { New-EntraApplicationExtensionProperty -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -Name } | Should -Throw "Missing an argument for parameter 'Name'*" + } + It "Should fail when DataType is null" { + { New-EntraApplicationExtensionProperty -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -Name "NewAttribute" -DataType } | Should -Throw "Missing an argument for parameter 'DataType'*" + } + It "Should fail when TargetObjects is null" { + { New-EntraApplicationExtensionProperty -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -Name "NewAttribute" -TargetObjects } | Should -Throw "Missing an argument for parameter 'TargetObjects'*" + } + It "Should fail when invalid parameter is passed" { + { New-EntraApplicationExtensionProperty -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'." + } + It "Should return result when TargetObjects is empty" { + New-EntraApplicationExtensionProperty -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -Name "NewAttribute" -TargetObjects {} | Should -Not -BeNullOrEmpty + } + It "Should contain ObjectId in result"{ + $result = New-EntraApplicationExtensionProperty -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -Name "NewAttribute" + $result.ObjectID | Should -Be "d083d12d-c280-4a23-a644-b4e71a09a4cb" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + $result = New-EntraApplicationExtensionProperty -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -Name "NewAttribute" + $params = Get-Parameters -data $result.Parameters + $params.ApplicationId | Should -Be "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraApplicationExtensionProperty" + $result = New-EntraApplicationExtensionProperty -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -Name "NewAttribute" + $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-EntraApplicationPasswordCredential.Tests.ps1 b/test/module/Entra/New-EntraApplicationPasswordCredential.Tests.ps1 new file mode 100644 index 000000000..4bcacb82c --- /dev/null +++ b/test/module/Entra/New-EntraApplicationPasswordCredential.Tests.ps1 @@ -0,0 +1,76 @@ +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]@{ + "CustomKeyIdentifier" = $null + "DisplayName" = "" + "EndDateTime" = "10/23/2024 11:36:56 AM" + "KeyId" = "52ab6cca-bc59-4f06-8450-75a3d2b8e53b" + "StartDateTime" = "11/22/2023 11:35:16 AM" + "Hint" = "123" + "SecretText" = "wbBNW8kCuiPjNRg9NX98W_EaU6cqG" + "Parameters" = $args + } + ) + } + + Mock -CommandName Add-MgApplicationPassword -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} +Describe "New-EntraApplicationPasswordCredential"{ + It "Should return created password credential"{ + $result = New-EntraApplicationPasswordCredential -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + $result | Should -Not -BeNullOrEmpty + $result.KeyId | should -Be "52ab6cca-bc59-4f06-8450-75a3d2b8e53b" + $result.SecretText | Should -Be "wbBNW8kCuiPjNRg9NX98W_EaU6cqG" + Should -Invoke -CommandName Add-MgApplicationPassword -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { New-EntraApplicationPasswordCredential -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId'*" + } + It "Should fail when ObjectId is null" { + { New-EntraApplicationPasswordCredential -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" + } + It "Should fail when StartDate is empty" { + { New-EntraApplicationPasswordCredential -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -StartDate "" } | Should -Throw "Cannot process argument transformation on parameter 'StartDate'*" + } + It "Should fail when StartDate is null" { + { New-EntraApplicationPasswordCredential -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -StartDate } | Should -Throw "Missing an argument for parameter 'StartDate'*" + } + It "Should fail when EndDate is empty" { + { New-EntraApplicationPasswordCredential -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -EndDate "" } | Should -Throw "Cannot process argument transformation on parameter 'EndDate'*" + } + It "Should fail when EndDate is null" { + { New-EntraApplicationPasswordCredential -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -EndDate } | Should -Throw "Missing an argument for parameter 'EndDate'*" + } + It "Should fail when invalid parameter is passed" { + { New-EntraApplicationPasswordCredential -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'." + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + $result = New-EntraApplicationPasswordCredential -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + $params = Get-Parameters -data $result.Parameters + $params.ApplicationId | Should -Be "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + } + It "should contain startDateTime in body parameter when passed StartDate to it"{ + $result = New-EntraApplicationPasswordCredential -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -StartDate (get-date).AddYears(0) + $params = Get-Parameters -data $result.Parameters + $a = $params.PasswordCredential | ConvertTo-json | ConvertFrom-Json + $a.startDateTime | Should -Not -BeNullOrEmpty + } + It "should contain endDateTime in body parameter when passed EndDate to it"{ + $result = New-EntraApplicationPasswordCredential -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -EndDate (get-date).AddYears(0) + $params = Get-Parameters -data $result.Parameters + $a = $params.PasswordCredential | ConvertTo-json | ConvertFrom-Json + $a.endDateTime | Should -Not -BeNullOrEmpty + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraApplicationPasswordCredential" + $result = New-EntraApplicationPasswordCredential -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + $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/Mock-New-EntraGroup.Tests.ps1 b/test/module/Entra/New-EntraGroup.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-New-EntraGroup.Tests.ps1 rename to test/module/Entra/New-EntraGroup.Tests.ps1 diff --git a/test/module/Entra/New-EntraMSAdministrativeUnit.Tests.ps1 b/test/module/Entra/New-EntraMSAdministrativeUnit.Tests.ps1 new file mode 100644 index 000000000..716cf70e2 --- /dev/null +++ b/test/module/Entra/New-EntraMSAdministrativeUnit.Tests.ps1 @@ -0,0 +1,48 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + # Write-Host "Mocking New-MgDirectoryAdministrativeUnit with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "DeletedDateTime" = $null + "Id" = "eb7dee2b-4938-4835-b3e1-bb8207ae0814" + "DisplayName" = "Mock-AU" + "AdditionalProperties" = {} + } + ) + } + + Mock -CommandName New-MgDirectoryAdministrativeUnit -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "New-EntraMSAdministrativeUnit"{ + Context "Test for New-EntraMSAdministrativeUnit" { + It "Should return created administrative unit"{ + $result = New-EntraMSAdministrativeUnit -DisplayName "Mock-AU" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be "Mock-AU" + + Should -Invoke -CommandName New-MgDirectoryAdministrativeUnit -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when DisplayName is empty" { + { New-EntraMSAdministrativeUnit -DisplayName "" } | Should -Throw "Cannot bind argument to parameter 'DisplayName' because it is an empty string." + } + It "Result should Contain ObjectId"{ + $result = New-EntraMSAdministrativeUnit -DisplayName "Mock-App" + $result.ObjectId | should -Be "eb7dee2b-4938-4835-b3e1-bb8207ae0814" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName New-MgDirectoryAdministrativeUnit -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSAdministrativeUnit" + + $result = New-EntraMSAdministrativeUnit -DisplayName "Mock-App" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Mock-New-EntraMSApplication.Tests.ps1 b/test/module/Entra/New-EntraMSApplication.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-New-EntraMSApplication.Tests.ps1 rename to test/module/Entra/New-EntraMSApplication.Tests.ps1 diff --git a/test/module/Entra/New-EntraMSApplicationPassword.Tests.ps1 b/test/module/Entra/New-EntraMSApplicationPassword.Tests.ps1 new file mode 100644 index 000000000..5352e3417 --- /dev/null +++ b/test/module/Entra/New-EntraMSApplicationPassword.Tests.ps1 @@ -0,0 +1,70 @@ +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]@{ + "CustomKeyIdentifier" = $null + "DisplayName" = "mypassword" + "EndDateTime" = "10/23/2024 11:36:56 AM" + "KeyId" = "52ab6cca-bc59-4f06-8450-75a3d2b8e53b" + "StartDateTime" = "11/22/2023 11:35:16 AM" + "Hint" = "123" + "SecretText" = "wbBNW8kCuiPjNRg9NX98W_EaU6cqG" + "Parameters" = $args + } + ) + } + + Mock -CommandName Add-MgApplicationPassword -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} +Describe "New-EntraMSApplicationPassword"{ + It "Should return created password credential"{ + $result = New-EntraMSApplicationPassword -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -PasswordCredential @{ displayname = "mypassword" } | ConvertTo-Json | ConvertFrom-Json + $result | Should -Not -BeNullOrEmpty + $result.KeyId | should -Be "52ab6cca-bc59-4f06-8450-75a3d2b8e53b" + $result.SecretText | Should -Be "wbBNW8kCuiPjNRg9NX98W_EaU6cqG" + Should -Invoke -CommandName Add-MgApplicationPassword -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { New-EntraMSApplicationPassword -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId'*" + } + It "Should fail when ObjectId is null" { + { New-EntraMSApplicationPassword -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" + } + It "Should fail when PasswordCredential is null" { + { New-EntraMSApplicationPassword -PasswordCredential } | Should -Throw "Missing an argument for parameter 'PasswordCredential'*" + } + It "Should fail when StartDate is empty" { + { New-EntraMSApplicationPassword -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -PasswordCredential @{ StartDateTime = "" } } | Should -Throw "Cannot process argument transformation on parameter 'PasswordCredential'*" + } + It "Should fail when EndDate is empty" { + { New-EntraMSApplicationPassword -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -PasswordCredential @{ EndDateTime = "" } } | Should -Throw "Cannot process argument transformation on parameter 'PasswordCredential'*" + } + It "Should fail when invalid parameter is passed" { + { New-EntraMSApplicationPassword -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'." + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + $result = New-EntraMSApplicationPassword -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -PasswordCredential @{ displayname = "mypassword" } + $params = Get-Parameters -data $result.Parameters + $params.ApplicationId | Should -Be "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + } + It "should contain password credential parameters in body parameter when passed PasswordCredential to it"{ + $result = New-EntraMSApplicationPassword -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -PasswordCredential @{ DisplayName = "mypassword"; Hint = "123"; StartDateTime=(get-date).AddYears(0); EndDateTime=(get-date).AddYears(2) } + $params = Get-Parameters -data $result.Parameters + $a = $params.PasswordCredential | ConvertTo-json | ConvertFrom-Json + $a.DisplayName | Should -Be "mypassword" + $a.Hint | Should -Be "123" + $a.StartDateTime | Should -Not -BeNullOrEmpty + $a.EndDateTime | Should -Not -BeNullOrEmpty + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSApplicationPassword" + $result = New-EntraMSApplicationPassword -ObjectID "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -PasswordCredential @{ displayname = "mypassword" } + $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-EntraMSPermissionGrantConditionSet.Tests.ps1 b/test/module/Entra/New-EntraMSPermissionGrantConditionSet.Tests.ps1 new file mode 100644 index 000000000..ed46df378 --- /dev/null +++ b/test/module/Entra/New-EntraMSPermissionGrantConditionSet.Tests.ps1 @@ -0,0 +1,54 @@ +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" = "4ccf1a57-4c5e-4ba6-9175-00407743b0e2" + "ClientApplicationIds" = {"All"} + "ClientApplicationPublisherIds" = {"All"} + "ClientApplicationTenantIds" = {"All"} + "ClientApplicationsFromVerifiedPublisherOnly" = $true + "PermissionClassification" = "all" + "PermissionType" = "delegated" + "Parameters" = $args + } + ) + } + + Mock -CommandName New-MgPolicyPermissionGrantPolicyInclude -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra + + Mock -CommandName New-MgPolicyPermissionGrantPolicyExclude -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} +Describe "New-EntraMSPermissionGrantConditionSet"{ + It "Should not return empty object for condition set 'includes'"{ + $result = New-EntraMSPermissionGrantConditionSet -PolicyId "test1" -ConditionSetType "includes" -PermissionType "delegated" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName New-MgPolicyPermissionGrantPolicyInclude -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should not return empty object for condition set 'excludes'"{ + $result = New-EntraMSPermissionGrantConditionSet -PolicyId "test1" -ConditionSetType "excludes" -PermissionType "delegated" + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName New-MgPolicyPermissionGrantPolicyExclude -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { New-EntraMSPermissionGrantConditionSet -PolicyId "" -ConditionSetType ""} | Should -Throw "Cannot bind argument to parameter*" + } + It "Should fail when parameters are null" { + { New-EntraMSPermissionGrantConditionSet -PolicyId -ConditionSetType } | Should -Throw "Missing an argument for parameter*" + } + It "Should contain PermissionGrantPolicyId in parameters when passed PolicyId to it" { + $result = New-EntraMSPermissionGrantConditionSet -PolicyId "test1" -ConditionSetType "includes" -PermissionType "delegated" + $params = Get-Parameters -data $result.Parameters + $params.PermissionGrantPolicyId | Should -Be "test1" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraMSPermissionGrantConditionSet" + $result = New-EntraMSPermissionGrantConditionSet -PolicyId "test1" -ConditionSetType "includes" -PermissionType "delegated" + $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-EntraServiceAppRoleAssignment.Tests.ps1 b/test/module/Entra/New-EntraServiceAppRoleAssignment.Tests.ps1 new file mode 100644 index 000000000..dcc18e511 --- /dev/null +++ b/test/module/Entra/New-EntraServiceAppRoleAssignment.Tests.ps1 @@ -0,0 +1,79 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + $scriptblock = { + # Write-Host "Mocking New-MgServicePrincipalAppRoleAssignment with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "DeletedDateTime" = $null + "Id" = "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + "PrincipalDisplayName" = "Mock-App" + "AppRoleId" = "e18f0405-fdec-4ae8-a8a0-d8edb98b061f" + "CreatedDateTime" = "3/12/2024 11:05:29 AM" + "PrincipalId" = "d2d0a585-0c52-4bab-8c64-a096b98b061f" + "Parameters" = $args + } + ) + } + + Mock -CommandName New-MgServicePrincipalAppRoleAssignment -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra +} + +Describe "New-EntraServiceAppRoleAssignment"{ + Context "Test for New-EntraServiceAppRoleAssignment" { + It "Should return EntraServiceAppRoleAssignment"{ + $result = New-EntraServiceAppRoleAssignment -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -ResourceId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -Id "e18f0405-fdec-4ae8-a8a0-d8edb98b061f" -PrincipalId "d2d0a585-0c52-4bab-8c64-a096b98b061f" + $result | Should -Not -BeNullOrEmpty + $result.PrincipalDisplayName | should -Be "Mock-App" + $result.PrincipalId | should -Be "d2d0a585-0c52-4bab-8c64-a096b98b061f" + + Should -Invoke -CommandName New-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { New-EntraServiceAppRoleAssignment -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId'*" + } + It "Should fail when ObjectId is null" { + { New-EntraServiceAppRoleAssignment -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" + } + It "Should fail when ResourceId is empty" { + { New-EntraServiceAppRoleAssignment -ResourceId "" } | Should -Throw "Cannot bind argument to parameter 'ResourceId'*" + } + It "Should fail when ResourceId is null" { + { New-EntraServiceAppRoleAssignment -ResourceId } | Should -Throw "Missing an argument for parameter 'ResourceId'*" + } + It "Should fail when Id is empty" { + { New-EntraServiceAppRoleAssignment -Id "" } | Should -Throw "Cannot bind argument to parameter 'Id'*" + } + It "Should fail when Id is null" { + { New-EntraServiceAppRoleAssignment -Id } | Should -Throw "Missing an argument for parameter 'Id'*" + } + It "Should fail when PrincipalId is empty" { + { New-EntraServiceAppRoleAssignment -PrincipalId "" } | Should -Throw "Cannot bind argument to parameter 'PrincipalId'*" + } + It "Should fail when PrincipalId is null" { + { New-EntraServiceAppRoleAssignment -PrincipalId } | Should -Throw "Missing an argument for parameter 'PrincipalId'*" + } + It "Should fail when invalid parameter is passed" { + { New-EntraServiceAppRoleAssignment -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'." + } + It "Should contain AppRoleId in parameters when passed Id to it" { + $result = New-EntraServiceAppRoleAssignment -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -ResourceId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -Id "e18f0405-fdec-4ae8-a8a0-d8edb98b061f" -PrincipalId "d2d0a585-0c52-4bab-8c64-a096b98b061f" + $params = Get-Parameters -data $result.Parameters + $params.AppRoleId | Should -Be "e18f0405-fdec-4ae8-a8a0-d8edb98b061f" + } + It "Should contain ServicePrincipalId in parameters when passed ObjectId to it" { + $result = New-EntraServiceAppRoleAssignment -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -ResourceId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -Id "e18f0405-fdec-4ae8-a8a0-d8edb98b061f" -PrincipalId "d2d0a585-0c52-4bab-8c64-a096b98b061f" + $params = Get-Parameters -data $result.Parameters + $params.ServicePrincipalId | Should -Be "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraServiceAppRoleAssignment" + $result = New-EntraServiceAppRoleAssignment -ObjectId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -ResourceId "02ed943d-6eca-4f99-83d6-e6fbf9dc63ae" -Id "e18f0405-fdec-4ae8-a8a0-d8edb98b061f" -PrincipalId "d2d0a585-0c52-4bab-8c64-a096b98b061f" + $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/Mock-Remove-EntraApplication.Tests.ps1 b/test/module/Entra/Remove-EntraApplication.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-Remove-EntraApplication.Tests.ps1 rename to test/module/Entra/Remove-EntraApplication.Tests.ps1 diff --git a/test/module/Entra/Remove-EntraApplicationExtensionProperty.Tests.ps1 b/test/module/Entra/Remove-EntraApplicationExtensionProperty.Tests.ps1 new file mode 100644 index 000000000..dd372e2d6 --- /dev/null +++ b/test/module/Entra/Remove-EntraApplicationExtensionProperty.Tests.ps1 @@ -0,0 +1,44 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgApplicationExtensionProperty -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Remove-EntraApplicationExtensionProperty"{ + It "Should return empty object" { + $result = Remove-EntraApplicationExtensionProperty -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -ExtensionPropertyId "c13dd34a-492b-4561-b171-40fcce2916c5" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Remove-MgApplicationExtensionProperty -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Remove-EntraApplicationExtensionProperty -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId'*" + } + It "Should fail when ObjectId is null" { + { Remove-EntraApplicationExtensionProperty -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" + } + It "Should fail when ExtensionPropertyId is empty" { + { Remove-EntraApplicationExtensionProperty -ExtensionPropertyId "" } | Should -Throw "Cannot bind argument to parameter 'ExtensionPropertyId'*" + } + It "Should fail when ExtensionPropertyId is null" { + { Remove-EntraApplicationExtensionProperty -ExtensionPropertyId } | Should -Throw "Missing an argument for parameter 'ExtensionPropertyId'*" + } + It "Should fail when invalid parameter is passed" { + { Remove-EntraApplicationExtensionProperty -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'." + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + Mock -CommandName Remove-MgApplicationExtensionProperty -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Remove-EntraApplicationExtensionProperty -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -ExtensionPropertyId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgApplicationExtensionProperty -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraApplicationExtensionProperty" + $result = Remove-EntraApplicationExtensionProperty -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -ExtensionPropertyId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } +} \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraApplicationOwner.Tests.ps1 b/test/module/Entra/Remove-EntraApplicationOwner.Tests.ps1 new file mode 100644 index 000000000..03ac65fe2 --- /dev/null +++ b/test/module/Entra/Remove-EntraApplicationOwner.Tests.ps1 @@ -0,0 +1,41 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgApplicationOwnerByRef -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Remove-EntraApplicationOwner"{ + It "Should return empty object" { + $result = Remove-EntraApplicationOwner -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -OwnerId "c13dd34a-492b-4561-b171-40fcce2916c5" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Remove-MgApplicationOwnerByRef -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Remove-EntraApplicationOwner -ObjectId "" } + } + It "Should fail when -OwnerId is empty" { + { Remove-EntraApplicationOwner -OwnerId "" } + } + It "Should contain DeviceId in parameters" { + Mock -CommandName Remove-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Remove-EntraApplicationOwner -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -OwnerId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + } + It "Should contain DirectoryObjectId in parameters" { + Mock -CommandName Remove-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Remove-EntraApplicationOwner -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -OwnerId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.DirectoryObjectId | Should -Be "c13dd34a-492b-4561-b171-40fcce2916c5" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraApplicationOwner" + $result = Remove-EntraApplicationOwner -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -OwnerId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } +} \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraApplicationPasswordCredential.Tests.ps1 b/test/module/Entra/Remove-EntraApplicationPasswordCredential.Tests.ps1 new file mode 100644 index 000000000..0c41af57c --- /dev/null +++ b/test/module/Entra/Remove-EntraApplicationPasswordCredential.Tests.ps1 @@ -0,0 +1,44 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgApplicationPassword -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Remove-EntraApplicationPasswordCredential"{ + It "Should return empty object" { + $result = Remove-EntraApplicationPasswordCredential -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -KeyId "c13dd34a-492b-4561-b171-40fcce2916c5" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Remove-MgApplicationPassword -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Remove-EntraApplicationPasswordCredential -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId'*" + } + It "Should fail when ObjectId is null" { + { Remove-EntraApplicationPasswordCredential -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" + } + It "Should fail when KeyId is empty" { + { Remove-EntraApplicationPasswordCredential -KeyId "" } | Should -Throw "Cannot bind argument to parameter 'KeyId'*" + } + It "Should fail when KeyId is null" { + { Remove-EntraApplicationPasswordCredential -KeyId } | Should -Throw "Missing an argument for parameter 'KeyId'*" + } + It "Should fail when invalid parameter is passed" { + { Remove-EntraApplicationPasswordCredential -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'." + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + Mock -CommandName Remove-MgApplicationPassword -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Remove-EntraApplicationPasswordCredential -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -KeyId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgApplicationPassword -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraApplicationPasswordCredential" + $result = Remove-EntraApplicationPasswordCredential -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -KeyId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } +} \ No newline at end of file diff --git a/test/module/Entra/Mock-Remove-EntraDevice.Tests.ps1 b/test/module/Entra/Remove-EntraDevice.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-Remove-EntraDevice.Tests.ps1 rename to test/module/Entra/Remove-EntraDevice.Tests.ps1 diff --git a/test/module/Entra/Mock-Remove-EntraGroup.Tests.ps1 b/test/module/Entra/Remove-EntraGroup.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-Remove-EntraGroup.Tests.ps1 rename to test/module/Entra/Remove-EntraGroup.Tests.ps1 diff --git a/test/module/Entra/Remove-EntraMSAdministrativeUnit.Tests.ps1 b/test/module/Entra/Remove-EntraMSAdministrativeUnit.Tests.ps1 new file mode 100644 index 000000000..835c94d42 --- /dev/null +++ b/test/module/Entra/Remove-EntraMSAdministrativeUnit.Tests.ps1 @@ -0,0 +1,38 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgDirectoryAdministrativeUnit -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Remove-EntraMSAdministrativeUnit" { + Context "Test for Remove-EntraMSAdministrativeUnit" { + It "Should return empty object" { + $result = Remove-EntraMSAdministrativeUnit -Id 76373ce0-821a-40b5-9aa2-e108e318f62e + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName Remove-MgDirectoryAdministrativeUnit -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id is empty" { + { Remove-EntraMSAdministrativeUnit -Id "" } + } + It "Should contain AdministrativeUnitId in parameters when passed Id to it" { + Mock -CommandName Remove-MgDirectoryAdministrativeUnit -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Remove-EntraMSAdministrativeUnit -Id 76373ce0-821a-40b5-9aa2-e108e318f62e + $params = Get-Parameters -data $result + $params.AdministrativeUnitId | Should -Be "76373ce0-821a-40b5-9aa2-e108e318f62e" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgDirectoryAdministrativeUnit -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraMSAdministrativeUnit" + + $result = Remove-EntraMSAdministrativeUnit -Id 76373ce0-821a-40b5-9aa2-e108e318f62e + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraMSAdministrativeUnitMember.Tests.ps1 b/test/module/Entra/Remove-EntraMSAdministrativeUnitMember.Tests.ps1 new file mode 100644 index 000000000..d9fe169f7 --- /dev/null +++ b/test/module/Entra/Remove-EntraMSAdministrativeUnitMember.Tests.ps1 @@ -0,0 +1,45 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgDirectoryAdministrativeUnitMemberByRef -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Remove-EntraMSAdministrativeUnitMember" { + Context "Test for Remove-EntraMSAdministrativeUnitMember" { + It "Should return empty object" { + $result = Remove-EntraMSAdministrativeUnitMember -Id c1c1decd-fec8-4899-9cea-5ca55a84965f -MemberId 201a21a3-201a-4101-92cb-239c00ef4a2a + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName Remove-MgDirectoryAdministrativeUnitMemberByRef -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { Remove-EntraMSAdministrativeUnitMember -Id "" -MemberId "" } + } + It "Should contain AdministrativeUnitId in parameters when passed Id to it" { + Mock -CommandName Remove-MgDirectoryAdministrativeUnitMemberByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Remove-EntraMSAdministrativeUnitMember -Id c1c1decd-fec8-4899-9cea-5ca55a84965f -MemberId 201a21a3-201a-4101-92cb-239c00ef4a2a + $params = Get-Parameters -data $result + $params.AdministrativeUnitId | Should -Be "c1c1decd-fec8-4899-9cea-5ca55a84965f" + } + It "Should contain DirectoryObjectId in parameters when passed MemberId to it" { + Mock -CommandName Remove-MgDirectoryAdministrativeUnitMemberByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Remove-EntraMSAdministrativeUnitMember -Id c1c1decd-fec8-4899-9cea-5ca55a84965f -MemberId 201a21a3-201a-4101-92cb-239c00ef4a2a + $params = Get-Parameters -data $result + $params.DirectoryObjectId | Should -Be "201a21a3-201a-4101-92cb-239c00ef4a2a" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgDirectoryAdministrativeUnitMemberByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraMSAdministrativeUnitMember" + + $result = Remove-EntraMSAdministrativeUnitMember -Id c1c1decd-fec8-4899-9cea-5ca55a84965f -MemberId 201a21a3-201a-4101-92cb-239c00ef4a2a + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Mock-Remove-EntraMSApplication.Tests.ps1 b/test/module/Entra/Remove-EntraMSApplication.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-Remove-EntraMSApplication.Tests.ps1 rename to test/module/Entra/Remove-EntraMSApplication.Tests.ps1 diff --git a/test/module/Entra/Remove-EntraMSApplicationOwner.Tests.ps1 b/test/module/Entra/Remove-EntraMSApplicationOwner.Tests.ps1 new file mode 100644 index 000000000..bfba0aa4d --- /dev/null +++ b/test/module/Entra/Remove-EntraMSApplicationOwner.Tests.ps1 @@ -0,0 +1,41 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgApplicationOwnerByRef -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Remove-EntraMSApplicationOwner"{ + It "Should return empty object" { + $result = Remove-EntraMSApplicationOwner -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -OwnerId "c13dd34a-492b-4561-b171-40fcce2916c5" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Remove-MgApplicationOwnerByRef -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Remove-EntraMSApplicationOwner -ObjectId "" } + } + It "Should fail when -OwnerId is empty" { + { Remove-EntraMSApplicationOwner -OwnerId "" } + } + It "Should contain DeviceId in parameters" { + Mock -CommandName Remove-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Remove-EntraMSApplicationOwner -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -OwnerId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + } + It "Should contain DirectoryObjectId in parameters" { + Mock -CommandName Remove-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Remove-EntraMSApplicationOwner -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -OwnerId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.DirectoryObjectId | Should -Be "c13dd34a-492b-4561-b171-40fcce2916c5" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgApplicationOwnerByRef -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraMSApplicationOwner" + $result = Remove-EntraMSApplicationOwner -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -OwnerId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } +} \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraMSApplicationPassword.Tests.ps1 b/test/module/Entra/Remove-EntraMSApplicationPassword.Tests.ps1 new file mode 100644 index 000000000..74fcca5fd --- /dev/null +++ b/test/module/Entra/Remove-EntraMSApplicationPassword.Tests.ps1 @@ -0,0 +1,41 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgApplicationPassword -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Remove-EntraMSApplicationPassword"{ + It "Should return empty object" { + $result = Remove-EntraMSApplicationPassword -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -KeyId "c13dd34a-492b-4561-b171-40fcce2916c5" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Remove-MgApplicationPassword -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when ObjectId is empty" { + { Remove-EntraMSApplicationPassword -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId'*" + } + It "Should fail when ObjectId is null" { + { Remove-EntraMSApplicationPassword -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" + } + It "Should fail when KeyId is null" { + { Remove-EntraMSApplicationPassword -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -KeyId } | Should -Throw "Missing an argument for parameter 'KeyId'*" + } + It "Should fail when invalid parameter is passed" { + { Remove-EntraMSApplicationPassword -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'." + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + Mock -CommandName Remove-MgApplicationPassword -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Remove-EntraMSApplicationPassword -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -KeyId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "3ddd22e7-a150-4bb3-b100-e410dea1cb84" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgApplicationPassword -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraMSApplicationPassword" + $result = Remove-EntraMSApplicationPassword -ObjectId "3ddd22e7-a150-4bb3-b100-e410dea1cb84" -KeyId "c13dd34a-492b-4561-b171-40fcce2916c5" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } +} \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraMSScopedRoleMembership.Tests.ps1 b/test/module/Entra/Remove-EntraMSScopedRoleMembership.Tests.ps1 new file mode 100644 index 000000000..84c311b49 --- /dev/null +++ b/test/module/Entra/Remove-EntraMSScopedRoleMembership.Tests.ps1 @@ -0,0 +1,38 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Remove-MgDirectoryAdministrativeUnitScopedRoleMember -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Remove-EntraMSScopedRoleMembership" { + Context "Test for Remove-EntraMSScopedRoleMembership" { + It "Should return empty object" { + $result = Remove-EntraMSScopedRoleMembership -Id "1026185e-25df-4522-a380-7ab697a7241c" -ScopedRoleMembershipId "3028185e-25df-4522-a380-7ab697a7241c" + $result | Should -BeNullOrEmpty + + Should -Invoke -CommandName Remove-MgDirectoryAdministrativeUnitScopedRoleMember -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { Remove-EntraMSScopedRoleMembership -Id "" -MemberId "" } + } + It "Should contain AdministrativeUnitId in parameters when passed Id to it" { + Mock -CommandName Remove-MgDirectoryAdministrativeUnitScopedRoleMember -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $result = Remove-EntraMSScopedRoleMembership -Id "1026185e-25df-4522-a380-7ab697a7241c" -ScopedRoleMembershipId "3028185e-25df-4522-a380-7ab697a7241c" + $params = Get-Parameters -data $result + $params.AdministrativeUnitId | Should -Be "1026185e-25df-4522-a380-7ab697a7241c" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgDirectoryAdministrativeUnitScopedRoleMember -MockWith {$args} -ModuleName Microsoft.Graph.Entra + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraMSScopedRoleMembership" + + $result = Remove-EntraMSScopedRoleMembership -Id "1026185e-25df-4522-a380-7ab697a7241c" -ScopedRoleMembershipId "3028185e-25df-4522-a380-7ab697a7241c" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Mock-Set-EntraApplication.Tests.ps1 b/test/module/Entra/Set-EntraApplication.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-Set-EntraApplication.Tests.ps1 rename to test/module/Entra/Set-EntraApplication.Tests.ps1 diff --git a/test/module/Entra/Mock-Set-EntraDevice.Tests.ps1 b/test/module/Entra/Set-EntraDevice.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-Set-EntraDevice.Tests.ps1 rename to test/module/Entra/Set-EntraDevice.Tests.ps1 diff --git a/test/module/Entra/Mock-Set-EntraGroup.Tests.ps1 b/test/module/Entra/Set-EntraGroup.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-Set-EntraGroup.Tests.ps1 rename to test/module/Entra/Set-EntraGroup.Tests.ps1 diff --git a/test/module/Entra/Set-EntraMSAdministrativeUnit.Tests.ps1 b/test/module/Entra/Set-EntraMSAdministrativeUnit.Tests.ps1 new file mode 100644 index 000000000..e6e93f61a --- /dev/null +++ b/test/module/Entra/Set-EntraMSAdministrativeUnit.Tests.ps1 @@ -0,0 +1,46 @@ +BeforeAll { + if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force + + Mock -CommandName Update-MgDirectoryAdministrativeUnit -MockWith {} -ModuleName Microsoft.Graph.Entra +} + +Describe "Set-EntraMSAdministrativeUnit" { + Context "Test for Set-EntraMSAdministrativeUnit" { + It "Should return empty object" { + $result = Set-EntraMSAdministrativeUnit -Id 76373ce0-821a-40b5-9aa2-e108e318f62e + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Update-MgDirectoryAdministrativeUnit -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when Id parameter is empty" { + { Set-EntraMSAdministrativeUnit -Id '' } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should fail when Id parameter is null" { + { Set-EntraMSAdministrativeUnit -Id } | Should -Throw "Missing an argument for parameter*" + } + It "Should fail when DisplayName parameter is null" { + { Set-EntraMSAdministrativeUnit -Id 76373ce0-821a-40b5-9aa2-e108e318f62e -DisplayName } | Should -Throw "Missing an argument for parameter*" + } + It "Should fail when Description parameter is null" { + { Set-EntraMSAdministrativeUnit -Id 76373ce0-821a-40b5-9aa2-e108e318f62e -Description } | Should -Throw "Missing an argument for parameter*" + } + It "Should fail when invalid parameter is passed" { + { Set-EntraMSAdministrativeUnit -ObjectId "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'ObjectId'." + } + It "Should contain AdministrativeUnitId in parameters when passed Id to it" { + Mock -CommandName Update-MgDirectoryAdministrativeUnit -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Set-EntraMSAdministrativeUnit -Id 76373ce0-821a-40b5-9aa2-e108e318f62e + $params = Get-Parameters -data $result + $params.AdministrativeUnitId | Should -Be "76373ce0-821a-40b5-9aa2-e108e318f62e" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Update-MgDirectoryAdministrativeUnit -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraMSAdministrativeUnit" + $result = Set-EntraMSAdministrativeUnit -Id 76373ce0-821a-40b5-9aa2-e108e318f62e + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/Entra/Mock-Set-EntraMSApplication.Tests.ps1 b/test/module/Entra/Set-EntraMSApplication.Tests.ps1 similarity index 100% rename from test/module/Entra/Mock-Set-EntraMSApplication.Tests.ps1 rename to test/module/Entra/Set-EntraMSApplication.Tests.ps1 diff --git a/test/module/Entra/Set-EntraMSPermissionGrantConditionSet.Tests.ps1 b/test/module/Entra/Set-EntraMSPermissionGrantConditionSet.Tests.ps1 new file mode 100644 index 000000000..1bb795ed9 --- /dev/null +++ b/test/module/Entra/Set-EntraMSPermissionGrantConditionSet.Tests.ps1 @@ -0,0 +1,51 @@ +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-MgPolicyPermissionGrantPolicyInclude -MockWith {} -ModuleName Microsoft.Graph.Entra + + Mock -CommandName Update-MgPolicyPermissionGrantPolicyExclude -MockWith {} -ModuleName Microsoft.Graph.Entra +} +Describe "Set-EntraMSPermissionGrantConditionSet"{ + It "Should return empty object for condition set 'includes'"{ + $result = Set-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "includes" -Id "665a9903-0398-48ab-b4e9-7a570d468b66" -PermissionClassification "Low" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Update-MgPolicyPermissionGrantPolicyInclude -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should return empty object for condition set 'excludes'"{ + $result = Set-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "excludes" -Id "665a9903-0398-48ab-b4e9-7a570d468b66" -PermissionClassification "Low" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Update-MgPolicyPermissionGrantPolicyExclude -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should fail when parameters are empty" { + { Set-EntraMSPermissionGrantConditionSet -PolicyId "" -ConditionSetType "" -Id ""} | Should -Throw "Cannot bind argument to parameter*" + } + It "Should fail when parameters are null" { + { Set-EntraMSPermissionGrantConditionSet -PolicyId -ConditionSetType -Id } | Should -Throw "Missing an argument for parameter*" + } + It "Should contain parameters for condition set 'includes'" { + Mock -CommandName Update-MgPolicyPermissionGrantPolicyInclude -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Set-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "includes" -Id "665a9903-0398-48ab-b4e9-7a570d468b66" -PermissionClassification "Low" + $params = Get-Parameters -data $result + $params.PermissionGrantPolicyId | Should -Be "policy1" + $params.PermissionGrantConditionSetId | Should -Be "665a9903-0398-48ab-b4e9-7a570d468b66" + Should -Invoke -CommandName Update-MgPolicyPermissionGrantPolicyInclude -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should contain parameters for condition set 'excludes'" { + Mock -CommandName Update-MgPolicyPermissionGrantPolicyExclude -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $result = Set-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "excludes" -Id "665a9903-0398-48ab-b4e9-7a570d468b66" -PermissionClassification "Low" + $params = Get-Parameters -data $result + $params.PermissionGrantPolicyId | Should -Be "policy1" + $params.PermissionGrantConditionSetId | Should -Be "665a9903-0398-48ab-b4e9-7a570d468b66" + Should -Invoke -CommandName Update-MgPolicyPermissionGrantPolicyExclude -ModuleName Microsoft.Graph.Entra -Times 1 + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Update-MgPolicyPermissionGrantPolicyInclude -MockWith {$args} -ModuleName Microsoft.Graph.Entra + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraMSPermissionGrantConditionSet" + $result = Set-EntraMSPermissionGrantConditionSet -PolicyId "policy1" -ConditionSetType "includes" -Id "665a9903-0398-48ab-b4e9-7a570d468b66" + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } +} \ No newline at end of file diff --git a/test/module/Entra/Valid.Tests.ps1 b/test/module/Entra/Valid.Tests.ps1 new file mode 100644 index 000000000..b92249f16 --- /dev/null +++ b/test/module/Entra/Valid.Tests.ps1 @@ -0,0 +1,106 @@ +BeforeAll{ + if($null -eq (Get-Module -Name Microsoft.Graph.Entra)){ + Import-Module Microsoft.Graph.Entra + } + Import-Module (Join-Path $psscriptroot "..\EntraCmdletsMap.ps1") -Force + + $module = Get-Module -Name Microsoft.Graph.Entra +} + +Describe "Valid parameter Tests"{ + Context "Test for valid parameters"{ + It "Should return empty object with Id parameter"{ + Write-Host "--------Start mock remove cmdlets with Id parameter only--------" + $count=0 + $module.ExportedCommands.Keys | ForEach-Object{ + $commandName = $_ + $command = Get-Command $_ + if($command.Name.StartsWith('Remove')){ + $params = ($command.ParameterSets.Parameters | Where-Object {$_.IsMandatory -eq $true} | select -expand Name) + if($params.count -eq 1 -and $params -eq 'Id'){ + $filter = $cmdlets | Where-Object { $_.SourceName -eq $command } + if($null -ne $filter){ + try { + Write-Host "$command" + $commandScriptBlock = [scriptblock]::Create("$commandName -Id 056b2531-005e-4f3e-be78-01a71ea30a04") + if($filter.IsApi){ + Mock -CommandName Invoke-GraphRequest -MockWith {} -ModuleName Microsoft.Graph.Entra + $result = Invoke-Command -ScriptBlock $commandScriptBlock + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 + } + else { + Mock -CommandName $filter.TargetName -MockWith {} -ModuleName Microsoft.Graph.Entra + $result = Invoke-Command -ScriptBlock $commandScriptBlock + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName $filter.TargetName -ModuleName Microsoft.Graph.Entra -Times 1 + } + } + catch { + Write-Host "Exception in cmdlet" $command + } + $count++ + } + } + } + } + Write-Host "Cmdlets count: $count" + Write-Host "---------End mock remove cmdlets with Id parameter only---------" + } + It "Should return empty object with ObjectId param"{ + Write-Host "-----Start mock remove cmdlets with ObjectId parameter only-----" + $count=0 + $module.ExportedCommands.Keys | ForEach-Object{ + $commandName = $_ + $command = Get-Command $_ + if($command.Name.StartsWith('Remove')){ + $params = ($command.ParameterSets.Parameters | Where-Object {$_.IsMandatory -eq $true} | select -expand Name) + if($params.count -eq 1 -and $params -eq 'ObjectId'){ + $filter = $cmdlets | Where-Object { $_.SourceName -eq $command } + if($null -ne $filter){ + try { + Write-Host "$command" + $commandScriptBlock = [scriptblock]::Create("$commandName -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04") + if($filter.IsApi){ + Mock -CommandName Invoke-GraphRequest -MockWith {} -ModuleName Microsoft.Graph.Entra + $result = Invoke-Command -ScriptBlock $commandScriptBlock + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 + } + else { + Mock -CommandName $filter.TargetName -MockWith {} -ModuleName Microsoft.Graph.Entra + $result = Invoke-Command -ScriptBlock $commandScriptBlock + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName $filter.TargetName -ModuleName Microsoft.Graph.Entra -Times 1 + } + } + catch { + Write-Host "Exception in cmdlet" $command + } + $count++ + } + } + } + } + Write-Host "Cmdlets count: $count" + Write-Host "------End mock remove cmdlets with ObjectId parameter only------" + } + # It "Should pass with 'Id' or 'ObjectId' parameter" { + # $count=0 + # $module.ExportedCommands.Keys | ForEach-Object { + + # $command = Get-Command $_ + # if ($command.Name.StartsWith('Remove')) + # { + # $params = ($command.ParameterSets.Parameters | Where-Object {$_.IsMandatory -eq $true} | select -expand Name) + # if($params.count -eq 1 -and ($params -eq 'ObjectId' -or $params-eq 'Id')){ + # $stringParams = $params -join ',' + # Write-Host "$command | $stringParams" + # $count++ + # } + # } + # } + # Write-Host $count + # } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Get-EntraBetaApplication.Tests.ps1 b/test/module/EntraBeta/Get-EntraBetaApplication.Tests.ps1 new file mode 100644 index 000000000..be8c7e37d --- /dev/null +++ b/test/module/EntraBeta/Get-EntraBetaApplication.Tests.ps1 @@ -0,0 +1,125 @@ +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 = { + # Write-Host "Mocking Get-MgBetaApplication with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "AppId" = "5f783237-3457-45d8-93e7-a0edb1cfbfd1" + "AppRoles" = $null + "DeletedDateTime" = $null + "Id" = "111cc9b5-fce9-485e-9566-c68debafac5f" + "DisplayName" = "Mock-App" + "Info" = @{LogoUrl=""; MarketingUrl=""; PrivacyStatementUrl=""; SupportUrl=""; TermsOfServiceUrl=""} + "IsDeviceOnlyAuthSupported" = $True + "IsFallbackPublicClient" = $true + "KeyCredentials" = @{CustomKeyIdentifier = @(211, 174, 247);DisplayName =""; Key="";KeyId="d903c7a3-75ea-4772-8935-5c0cf82068a7";Type="Symmetric";Usage="Sign"} + "OptionalClaims" = @{AccessToken=""; IdToken=""; Saml2Token=""} + "ParentalControlSettings" = @{CountriesBlockedForMinors=$null; LegalAgeGroupRule="Allow"} + "PasswordCredentials" = @{} + "PublicClient" = @{RedirectUris=$null} + "PublisherDomain" = "M365x99297270.onmicrosoft.com" + "SignInAudience" = "AzureADandPersonalMicrosoftAccount" + "Web" = @{HomePageUrl="https://localhost/demoapp"; ImplicitGrantSettings=""; LogoutUrl="";} + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgBetaApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "Get-EntraBetaApplication" { + Context "Test for Get-EntraBetaApplication" { + It "Should return specific application" { + $result = Get-EntraBetaApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be @('111cc9b5-fce9-485e-9566-c68debafac5f') + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraBetaApplication -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should return all applications" { + $result = Get-EntraBetaApplication -All $true + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraBetaApplication -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should fail when invalid parameter is passed" { + { Get-EntraBetaApplication -Power "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'Power'*" + } + It "Should return specific application by searchstring" { + $result = Get-EntraBetaApplication -SearchString 'Mock-App' + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be 'Mock-App' + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should return specific application by filter" { + $result = Get-EntraBetaApplication -Filter "DisplayName -eq 'Mock-App'" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be 'Mock-App' + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should return top application" { + $result = Get-EntraBetaApplication -Top 1 + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraBetaApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $result.ObjectId | should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + $result = Get-EntraBetaApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $params = Get-Parameters -data $result.Parameters + $params.ApplicationId | Should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" + } + It "Should contain Filter in parameters when passed SearchString to it" { + $result = Get-EntraBetaApplication -SearchString 'Mock-App' + $params = Get-Parameters -data $result.Parameters + $params.Filter | Should -Match "Mock-App" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaApplication" + $result = Get-EntraBetaApplication -SearchString 'Mock-App' + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + It "Should support minimum set of parameter sets" { + $GetAzureADApplication = Get-Command Get-EntraBetaApplication + $GetAzureADApplication.ParameterSets.Name | Should -BeIn @("GetQuery", "GetVague", "GetById") + $GetAzureADApplication.Visibility | Should -Be "Public" + $GetAzureADApplication.CommandType | Should -Be "Function" + } + + It "Should return a list of applications by default" { + $GetAzureADApplication = Get-Command Get-EntraBetaApplication + $GetAzureADApplication.ModuleName | Should -Be "Microsoft.Graph.Entra.Beta" + $GetAzureADApplication.DefaultParameterSet | Should -Be "GetQuery" + } + It 'Should have List parameterSet' { + $GetAzureADApplication = Get-Command Get-EntraBetaApplication + $ListParameterSet = $GetAzureADApplication.ParameterSets | Where-Object Name -eq "GetQuery" + $ListParameterSet.Parameters.Name | Should -Contain All + $ListParameterSet.Parameters.Name | Should -Contain Filter + $ListParameterSet.Parameters.Name | Should -Contain Top + } + It 'Should have Get parameterSet' { + $GetAzureADApplication = Get-Command Get-EntraBetaApplication + $GetParameterSet = $GetAzureADApplication.ParameterSets | Where-Object Name -eq "GetById" + $GetParameterSet.Parameters.Name | Should -Contain ObjectId + } + It 'Should have GetViaIdentity parameterSet' { + $GetAzureADApplication = Get-Command Get-EntraBetaApplication + $GetViaIdentityParameterSet = $GetAzureADApplication.ParameterSets | Where-Object Name -eq "GetVague" + $GetViaIdentityParameterSet.Parameters.Name | Should -Contain SearchString + $GetViaIdentityParameterSet.Parameters.Name | Should -Contain All + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Get-EntraBetaMSApplication.Tests.ps1 b/test/module/EntraBeta/Get-EntraBetaMSApplication.Tests.ps1 new file mode 100644 index 000000000..e8d964bd3 --- /dev/null +++ b/test/module/EntraBeta/Get-EntraBetaMSApplication.Tests.ps1 @@ -0,0 +1,103 @@ +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 = { + # Write-Host "Mocking Get-MgBetaApplication with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "AppId" = "5f783237-3457-45d8-93e7-a0edb1cfbfd1" + "DeletedDateTime" = $null + "Id" = "111cc9b5-fce9-485e-9566-c68debafac5f" + "DisplayName" = "Mock-App" + "Info" = @{LogoUrl=""; MarketingUrl=""; PrivacyStatementUrl=""; SupportUrl=""; TermsOfServiceUrl=""} + "IsDeviceOnlyAuthSupported" = $True + "IsFallbackPublicClient" = $true + "KeyCredentials" = @{CustomKeyIdentifier = @(211, 174, 247);DisplayName =""; Key="";KeyId="d903c7a3-75ea-4772-8935-5c0cf82068a7";Type="Symmetric";Usage="Sign"} + "OptionalClaims" = @{AccessToken=""; IdToken=""; Saml2Token=""} + "ParentalControlSettings" = @{CountriesBlockedForMinors=$null; LegalAgeGroupRule="Allow"} + "PasswordCredentials" = @{} + "AddIns" = @{} + "Logo" = $null + "AppRoles" = $null + "GroupMembershipClaims" = $null + "IdentifierUris" = $null + "Oauth2RequirePostResponse" = $null + "Api" = @{AcceptMappedClaims= $null; KnownClientApplications=$null; Oauth2PermissionScopes=$null; + PreAuthorizedApplications=$null; RequestedAccessTokenVersion=2; AdditionalProperties= $null} + "PublicClient" = @{RedirectUris=$null} + "RequiredResourceAccess" = $false + "PublisherDomain" = "M365x99297270.onmicrosoft.com" + "SignInAudience" = "AzureADandPersonalMicrosoftAccount" + "Web" = @{HomePageUrl="https://localhost/demoapp"; ImplicitGrantSettings=""; LogoutUrl="";} + "Parameters" = $args + } + ) + } + + Mock -CommandName Get-MgBetaApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "Get-EntraBetaMSApplication" { + Context "Test for Get-EntraBetaMSApplication" { + It "Should return specific application" { + $result = Get-EntraBetaMSApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $result | Should -Not -BeNullOrEmpty + $result.Id | should -Be @('111cc9b5-fce9-485e-9566-c68debafac5f') + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when ObjectId is empty" { + { Get-EntraBetaMSApplication -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should return all applications" { + $result = Get-EntraBetaMSApplication -All $true + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when All is empty" { + { Get-EntraBetaMSApplication -All } | Should -Throw "Missing an argument for parameter 'All'*" + } + It "Should fail when invalid parameter is passed" { + { Get-EntraBetaMSApplication -Power "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'Power'*" + } + It "Should return specific application by searchstring" { + $result = Get-EntraBetaMSApplication -SearchString 'Mock-App' + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be 'Mock-App' + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should return specific application by filter" { + $result = Get-EntraBetaMSApplication -Filter "DisplayName -eq 'Mock-App'" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be 'Mock-App' + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should return top application" { + $result = Get-EntraBetaMSApplication -Top 1 + $result | Should -Not -BeNullOrEmpty + Should -Invoke -CommandName Get-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Result should Contain ObjectId" { + $result = Get-EntraBetaMSApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $result.ObjectId | should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + $result = Get-EntraBetaMSApplication -ObjectId "111cc9b5-fce9-485e-9566-c68debafac5f" + $params = Get-Parameters -data $result.Parameters + $params.ApplicationId | Should -Be "111cc9b5-fce9-485e-9566-c68debafac5f" + } + It "Should contain Filter in parameters when passed SearchString to it" { + $result = Get-EntraBetaMSApplication -SearchString 'Mock-App' + $params = Get-Parameters -data $result.Parameters + $params.Filter | Should -Match "Mock-App" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraBetaMSApplication" + $result = Get-EntraBetaMSApplication -SearchString 'Mock-App' + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Invalid.Tests.ps1 b/test/module/EntraBeta/Invalid.Tests.ps1 new file mode 100644 index 000000000..cfff18fa3 --- /dev/null +++ b/test/module/EntraBeta/Invalid.Tests.ps1 @@ -0,0 +1,100 @@ +if($null -eq (Get-Module -Name Microsoft.Graph.Entra.Beta)){ + Import-Module Microsoft.Graph.Entra.Beta +} + +Describe "Invalid Tests"{ + It "Should fail when parameters are invalid"{ + $module = Get-Module -Name Microsoft.Graph.Entra.Beta + $module.ExportedCommands.Keys | ForEach-Object{ + $command = Get-Command $_ + { Invoke-Command $command -demo "" } | Should -Throw "A parameter cannot be found that matches parameter name 'demo'." + } + } + It "Should fail with 'TenantId' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra.Beta + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'TenantId'){ + $commandScriptBlock = [scriptblock]::Create("$command -TenantId $objectId") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'TenantId'.*" + } + } + } + It "Should fail with 'Id' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra.Beta + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'Id'){ + $commandScriptBlock = [scriptblock]::Create("$command -Id $objectId") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'Id'.*" + } + } + } + It "Should fail with 'ObjectId' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra.Beta + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'ObjectId'){ + $commandScriptBlock = [scriptblock]::Create("$command -ObjectId $objectId") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'ObjectId'.*" + } + } + } + It "Should fail with 'All' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra.Beta + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'All'){ + $commandScriptBlock = [scriptblock]::Create("$command -All ") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'All'*" + } + } + } + It "Should fail with 'Top' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra.Beta + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'Top'){ + $commandScriptBlock = [scriptblock]::Create("$command -Top ") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'Top'*" + } + } + } + It "Should fail with 'Filter' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra.Beta + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'Filter'){ + $commandScriptBlock = [scriptblock]::Create("$command -Filter ") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'Filter'*" + } + } + } + It "Should fail with 'SearchString' parameter" { + $module = Get-Module -Name Microsoft.Graph.Entra.Beta + $module.ExportedCommands.Keys | ForEach-Object { + $command = Get-Command $_ + if ($command.ParameterSets.Parameters.Name -contains 'SearchString'){ + $commandScriptBlock = [scriptblock]::Create("$command -SearchString ") + { Invoke-Command -ScriptBlock $commandScriptBlock } | Should -Throw "Missing an argument for parameter 'SearchString'*" + } + } + } + It "Should fail with exception when no parameter is passed" { + $cmdlets = @( + @{ CmdletName = 'Enable-EntraBetaDirectoryRole'; Exception = "Could not resolve request to a valid role template." } + @{ CmdletName = 'New-EntraBetaMSConditionalAccessPolicy'; Exception = "1006: 'displayName' cannot be null" }, + @{ CmdletName = 'New-EntraBetaMSNamedLocationPolicy'; Exception = "1042: Unexpected type: namedLocationType for NamedLocations." }, + @{ CmdletName = 'New-EntraBetaMSPermissionGrantPolicy'; Exception = "PermissionGrantPolicy's Id must not be null or empty." } + ) + $cmdlets | ForEach-Object { + $commandName = $_.CmdletName + $Exception = $_.Exception + $commandScriptBlock = [scriptblock]::Create("$commandName -ErrorAction Stop") + try { + Invoke-Command -ScriptBlock $commandScriptBlock + } + catch { $_ -match $Exception | Should -BeTrue } + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/New-EntraBetaApplication.Tests.ps1 b/test/module/EntraBeta/New-EntraBetaApplication.Tests.ps1 new file mode 100644 index 000000000..7165d4e20 --- /dev/null +++ b/test/module/EntraBeta/New-EntraBetaApplication.Tests.ps1 @@ -0,0 +1,58 @@ +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 = { + # Write-Host "Mocking New-MgBetaApplication with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "AppId" = "5f783237-3457-45d8-93e7-a0edb1cfbfd1" + "DeletedDateTime" = $null + "Id" = "111cc9b5-fce9-485e-9566-c68debafac5f" + "DisplayName" = "Mock-App" + "Info" = @{LogoUrl=""; MarketingUrl=""; PrivacyStatementUrl=""; SupportUrl=""; TermsOfServiceUrl=""} + "IsDeviceOnlyAuthSupported" = $True + "IsFallbackPublicClient" = $true + "KeyCredentials" = @{CustomKeyIdentifier = @(211, 174, 247);DisplayName =""; Key="";KeyId="d903c7a3-75ea-4772-8935-5c0cf82068a7";Type="Symmetric";Usage="Sign"} + "OptionalClaims" = @{AccessToken=""; IdToken=""; Saml2Token=""} + "ParentalControlSettings" = @{CountriesBlockedForMinors=$null; LegalAgeGroupRule="Allow"} + "PasswordCredentials" = @{} + "PublicClient" = @{RedirectUris=$null} + "PublisherDomain" = "M365x99297270.onmicrosoft.com" + "SignInAudience" = "AzureADandPersonalMicrosoftAccount" + "Web" = @{HomePageUrl="https://localhost/demoapp"; ImplicitGrantSettings=""; LogoutUrl="";} + "Parameters" = $args + } + ) + } + + Mock -CommandName New-MgBetaApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "New-EntraBetaApplication"{ + Context "Test for New-EntraBetaApplication" { + It "Should return created Application"{ + $result = New-EntraBetaApplication -DisplayName "Mock-App" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be "Mock-App" + $result.IsDeviceOnlyAuthSupported | should -Be "True" + $result.IsFallbackPublicClient | should -Be "True" + $result.SignInAudience | should -Be "AzureADandPersonalMicrosoftAccount" + Should -Invoke -CommandName New-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when DisplayName is empty" { + { New-EntraBetaApplication -DisplayName "" } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should fail when invalid parameter is passed" { + { New-EntraBetaApplication -Power "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'Power'*" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraBetaApplication" + $result = New-EntraBetaApplication -DisplayName "Mock-App" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/New-EntraBetaMSApplication.Tests.ps1 b/test/module/EntraBeta/New-EntraBetaMSApplication.Tests.ps1 new file mode 100644 index 000000000..cab515150 --- /dev/null +++ b/test/module/EntraBeta/New-EntraBetaMSApplication.Tests.ps1 @@ -0,0 +1,68 @@ +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 = { + # Write-Host "Mocking New-MgBetaApplication with parameters: $($args | ConvertTo-Json -Depth 3)" + return @( + [PSCustomObject]@{ + "AppId" = "5f783237-3457-45d8-93e7-a0edb1cfbfd1" + "DeletedDateTime" = $null + "Id" = "111cc9b5-fce9-485e-9566-c68debafac5f" + "DisplayName" = "Mock-App" + "Info" = @{LogoUrl=""; MarketingUrl=""; PrivacyStatementUrl=""; SupportUrl=""; TermsOfServiceUrl=""} + "IsDeviceOnlyAuthSupported" = $True + "IsFallbackPublicClient" = $True + "KeyCredentials" = @{CustomKeyIdentifier = @(211, 174, 247);DisplayName =""; Key="";KeyId="d903c7a3-75ea-4772-8935-5c0cf82068a7";Type="Symmetric";Usage="Sign"} + "OptionalClaims" = @{AccessToken=""; IdToken=""; Saml2Token=""} + "ParentalControlSettings" = @{CountriesBlockedForMinors=$null; LegalAgeGroupRule="Allow"} + "PasswordCredentials" = @{} + "AddIns" = @{} + "Logo" = $null + "AppRoles" = $null + "GroupMembershipClaims" = $null + "IdentifierUris" = $null + "Oauth2RequirePostResponse" = $null + "Api" = @{AcceptMappedClaims= $null; KnownClientApplications=$null; Oauth2PermissionScopes=$null; + PreAuthorizedApplications=$null; RequestedAccessTokenVersion=2; AdditionalProperties= $null} + "PublicClient" = @{RedirectUris=$null} + "RequiredResourceAccess" = $false + "PublisherDomain" = "M365x99297270.onmicrosoft.com" + "SignInAudience" = "AzureADandPersonalMicrosoftAccount" + "Web" = @{HomePageUrl="https://localhost/demoapp"; ImplicitGrantSettings=""; LogoutUrl="";} + "AdditionalProperties" = @{Context="application"} + "Parameters" = $args + } + ) + } + + Mock -CommandName New-MgBetaApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "New-EntraBetaMSApplication"{ + Context "Test for New-EntraBetaMSApplication" { + It "Should return created Application"{ + $result = New-EntraBetaMSApplication -DisplayName "Mock-App" + $result | Should -Not -BeNullOrEmpty + $result.DisplayName | should -Be "Mock-App" + $result.IsDeviceOnlyAuthSupported | should -Be "True" + $result.IsFallbackPublicClient | should -Be "True" + $result.SignInAudience | should -Be "AzureADandPersonalMicrosoftAccount" + Should -Invoke -CommandName New-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when DisplayName is empty" { + { New-EntraBetaMSApplication -DisplayName "" } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should fail when invalid parameter is passed" { + { New-EntraBetaMSApplication -Power "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'Power'*" + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraBetaMSApplication" + $result = New-EntraBetaMSApplication -DisplayName "Mock-App" + $params = Get-Parameters -data $result.Parameters + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Remove-EntraBetaApplication.Tests.ps1 b/test/module/EntraBeta/Remove-EntraBetaApplication.Tests.ps1 new file mode 100644 index 000000000..ce585a8a5 --- /dev/null +++ b/test/module/EntraBeta/Remove-EntraBetaApplication.Tests.ps1 @@ -0,0 +1,37 @@ +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 + + Mock -CommandName Remove-MgBetaApplication -MockWith {} -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "Remove-EntraBetaApplication" { + Context "Test for Remove-EntraBetaApplication" { + It "Should return empty object" { + $result = Remove-EntraBetaApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Remove-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when ObjectId is empty" { + { Remove-EntraBetaApplication -ObjectId "" } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should fail when invalid parameter is passed" { + { Remove-EntraBetaApplication -Power "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'Power'*" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + Mock -CommandName Remove-MgBetaApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra.Beta + $result = Remove-EntraBetaApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "056b2531-005e-4f3e-be78-01a71ea30a04" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgBetaApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra.Beta + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraBetaApplication" + $result = Remove-EntraBetaApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Remove-EntraBetaMSApplication.Tests.ps1 b/test/module/EntraBeta/Remove-EntraBetaMSApplication.Tests.ps1 new file mode 100644 index 000000000..9f65294a6 --- /dev/null +++ b/test/module/EntraBeta/Remove-EntraBetaMSApplication.Tests.ps1 @@ -0,0 +1,37 @@ +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 + + Mock -CommandName Remove-MgBetaApplication -MockWith {} -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "Remove-EntraBetaMSApplication" { + Context "Test for Remove-EntraBetaMSApplication" { + It "Should return empty object" { + $result = Remove-EntraBetaMSApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Remove-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when ObjectId is empty" { + { Remove-EntraBetaMSApplication -ObjectId "" } | Should -Throw "Cannot bind argument to parameter*" + } + It "Should fail when invalid parameter is passed" { + { Remove-EntraBetaApplication -Power "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'Power'*" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + Mock -CommandName Remove-MgBetaApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra.Beta + $result = Remove-EntraBetaMSApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "056b2531-005e-4f3e-be78-01a71ea30a04" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Remove-MgBetaApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra.Beta + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraBetaMSApplication" + $result = Remove-EntraBetaMSApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Set-EntraBetaApplication.Tests.ps1 b/test/module/EntraBeta/Set-EntraBetaApplication.Tests.ps1 new file mode 100644 index 000000000..0ca2a4181 --- /dev/null +++ b/test/module/EntraBeta/Set-EntraBetaApplication.Tests.ps1 @@ -0,0 +1,37 @@ +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 + + Mock -CommandName Update-MgBetaApplication -MockWith {} -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "Set-EntraBetaApplication"{ + Context "Test for Set-EntraBetaApplication" { + It "Should return empty object"{ + $result = Set-EntraBetaApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 -DisplayName "Mock-App" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Update-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when ObjectId is empty" { + { Set-EntraBetaApplication -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should fail when invalid parameter is passed" { + { Set-EntraBetaApplication -Power "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'Power'*" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + Mock -CommandName Update-MgBetaApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra.Beta + $result = Set-EntraBetaApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "056b2531-005e-4f3e-be78-01a71ea30a04" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Update-MgBetaApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra.Beta + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraBetaApplication" + $result = Set-EntraBetaApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Set-EntraBetaMSApplication.Tests.ps1 b/test/module/EntraBeta/Set-EntraBetaMSApplication.Tests.ps1 new file mode 100644 index 000000000..dc7d7f693 --- /dev/null +++ b/test/module/EntraBeta/Set-EntraBetaMSApplication.Tests.ps1 @@ -0,0 +1,37 @@ +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 + + Mock -CommandName Update-MgBetaApplication -MockWith {} -ModuleName Microsoft.Graph.Entra.Beta +} + +Describe "Set-EntraBetaMSApplication"{ + Context "Test for Set-EntraBetaMSApplication" { + It "Should return empty object"{ + $result = Set-EntraBetaMSApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 -DisplayName "Mock-App" + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Update-MgBetaApplication -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + It "Should fail when ObjectId is empty" { + { Set-EntraBetaMSApplication -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." + } + It "Should fail when invalid parameter is passed" { + { Set-EntraBetaMSApplication -Power "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'Power'*" + } + It "Should contain ApplicationId in parameters when passed ObjectId to it" { + Mock -CommandName Update-MgBetaApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra.Beta + $result = Set-EntraBetaMSApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $params = Get-Parameters -data $result + $params.ApplicationId | Should -Be "056b2531-005e-4f3e-be78-01a71ea30a04" + } + It "Should contain 'User-Agent' header" { + Mock -CommandName Update-MgBetaApplication -MockWith {$args} -ModuleName Microsoft.Graph.Entra.Beta + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraBetaMSApplication" + $result = Set-EntraBetaMSApplication -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04 + $params = Get-Parameters -data $result + $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Valid.Tests.ps1 b/test/module/EntraBeta/Valid.Tests.ps1 new file mode 100644 index 000000000..eb61c6b10 --- /dev/null +++ b/test/module/EntraBeta/Valid.Tests.ps1 @@ -0,0 +1,106 @@ +BeforeAll{ + if($null -eq (Get-Module -Name Microsoft.Graph.Entra.Beta)){ + Import-Module Microsoft.Graph.Entra.Beta + } + Import-Module (Join-Path $psscriptroot "..\EntraBetaCmdletsMap.ps1") -Force + + $module = Get-Module -Name Microsoft.Graph.Entra.Beta +} + +Describe "Valid parameter Tests"{ + Context "Test for valid parameters"{ + It "Should return empty object with Id parameter"{ + Write-Host "--------Start mock remove cmdlets with Id parameter only--------" + $count=0 + $module.ExportedCommands.Keys | ForEach-Object{ + $commandName = $_ + $command = Get-Command $_ + if($command.Name.StartsWith('Remove')){ + $params = ($command.ParameterSets.Parameters | Where-Object {$_.IsMandatory -eq $true} | select -expand Name) + if($params.count -eq 1 -and $params -eq 'Id'){ + $filter = $cmdlets | Where-Object { $_.SourceName -eq $command } + if($null -ne $filter){ + try { + Write-Host "$command" + $commandScriptBlock = [scriptblock]::Create("$commandName -Id 056b2531-005e-4f3e-be78-01a71ea30a04") + if($filter.IsApi){ + Mock -CommandName Invoke-GraphRequest -MockWith {} -ModuleName Microsoft.Graph.Entra.Beta + $result = Invoke-Command -ScriptBlock $commandScriptBlock + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + else { + Mock -CommandName $filter.TargetName -MockWith {} -ModuleName Microsoft.Graph.Entra.Beta + $result = Invoke-Command -ScriptBlock $commandScriptBlock + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName $filter.TargetName -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + } + catch { + Write-Host "Exception in cmdlet" $command + } + $count++ + } + } + } + } + Write-Host "Cmdlets count: $count" + Write-Host "---------End mock remove cmdlets with Id parameter only---------" + } + It "Should return empty object with ObjectId param"{ + Write-Host "-----Start mock remove cmdlets with ObjectId parameter only-----" + $count=0 + $module.ExportedCommands.Keys | ForEach-Object{ + $commandName = $_ + $command = Get-Command $_ + if($command.Name.StartsWith('Remove')){ + $params = ($command.ParameterSets.Parameters | Where-Object {$_.IsMandatory -eq $true} | select -expand Name) + if($params.count -eq 1 -and $params -eq 'ObjectId'){ + $filter = $cmdlets | Where-Object { $_.SourceName -eq $command } + if($null -ne $filter){ + try { + Write-Host "$command" + $commandScriptBlock = [scriptblock]::Create("$commandName -ObjectId 056b2531-005e-4f3e-be78-01a71ea30a04") + if($filter.IsApi){ + Mock -CommandName Invoke-GraphRequest -MockWith {} -ModuleName Microsoft.Graph.Entra.Beta + $result = Invoke-Command -ScriptBlock $commandScriptBlock + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + else { + Mock -CommandName $filter.TargetName -MockWith {} -ModuleName Microsoft.Graph.Entra.Beta + $result = Invoke-Command -ScriptBlock $commandScriptBlock + $result | Should -BeNullOrEmpty + Should -Invoke -CommandName $filter.TargetName -ModuleName Microsoft.Graph.Entra.Beta -Times 1 + } + } + catch { + Write-Host "Exception in cmdlet" $command + } + $count++ + } + } + } + } + Write-Host "Cmdlets count: $count" + Write-Host "------End mock remove cmdlets with ObjectId parameter only------" + } + # It "Should pass with 'Id' or 'ObjectId' parameter" { + # $count=0 + # $module.ExportedCommands.Keys | ForEach-Object { + + # $command = Get-Command $_ + # if ($command.Name.StartsWith('Remove')) + # { + # $params = ($command.ParameterSets.Parameters | Where-Object {$_.IsMandatory -eq $true} | select -expand Name) + # if($params.count -eq 1 -and ($params -eq 'ObjectId' -or $params-eq 'Id')){ + # $stringParams = $params -join ',' + # Write-Host "$command | $stringParams" + # $count++ + # } + # } + # } + # Write-Host $count + # } + } +} \ No newline at end of file diff --git a/test/module/EntraBetaCmdletsMap.ps1 b/test/module/EntraBetaCmdletsMap.ps1 new file mode 100644 index 000000000..724dd8dea --- /dev/null +++ b/test/module/EntraBetaCmdletsMap.ps1 @@ -0,0 +1,102 @@ +$cmdlets = @( + @{ + SourceName = "Remove-EntraBetaMSAdministrativeUnit"; + TargetName = "Remove-MgBetaDirectoryAdministrativeUnit"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaMSDeletedDirectoryObject"; + TargetName = ""; + IsApi = $true + }, + @{ + SourceName = "Remove-EntraBetaMSGroup"; + TargetName = "Remove-MgBetaGroup"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaMSGroupLifecyclePolicy"; + TargetName = "Remove-MgBetaGroupLifecyclePolicy"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaMSIdentityProvider"; + TargetName = "Remove-MgBetaIdentityProvider"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaMSPermissionGrantPolicy"; + TargetName = "Remove-MgBetaPolicyPermissionGrantPolicy"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaMSRoleAssignment"; + TargetName = "Remove-MgBetaRoleManagementDirectoryRoleAssignment" + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaMSRoleDefinition"; + TargetName = "Remove-MgBetaRoleManagementDirectoryRoleDefinition"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaApplication"; + TargetName = "Remove-MgBetaApplication"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaContact"; + TargetName = "Remove-MgBetaContact"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaDeletedApplication"; + TargetName = "Remove-MgBetaDirectoryDeletedItem"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaDevice"; + TargetName = "Remove-MgBetaDevice"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaGroup"; + TargetName = "Remove-MgBetaGroup"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaMSApplication"; + TargetName = "Remove-MgBetaApplication"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaMSApplicationKey"; + TargetName = "Remove-MgBetaApplicationKey"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaMSApplicationPassword"; + TargetName = "Remove-MgBetaApplicationPassword"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaOAuth2PermissionGrant"; + TargetName = "Remove-MgBetaOAuth2PermissionGrant"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaServicePrincipal"; + TargetName = "Remove-MgBetaServicePrincipal"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaUser"; + TargetName = "Remove-MgBetaUser"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraBetaUserManager"; + TargetName = "Remove-MgBetaUserManagerByRef"; + IsApi = $false + } +) \ No newline at end of file diff --git a/test/module/EntraCmdletsMap.ps1 b/test/module/EntraCmdletsMap.ps1 new file mode 100644 index 000000000..c9fe7202e --- /dev/null +++ b/test/module/EntraCmdletsMap.ps1 @@ -0,0 +1,102 @@ +$cmdlets = @( + @{ + SourceName = "Remove-EntraMSAdministrativeUnit"; + TargetName = "Remove-MgDirectoryAdministrativeUnit"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraMSDeletedDirectoryObject"; + TargetName = ""; + IsApi = $true + }, + @{ + SourceName = "Remove-EntraMSGroup"; + TargetName = "Remove-MgGroup"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraMSGroupLifecyclePolicy"; + TargetName = "Remove-MgGroupLifecyclePolicy"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraMSIdentityProvider"; + TargetName = "Remove-MgIdentityProvider"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraMSPermissionGrantPolicy"; + TargetName = "Remove-MgPolicyPermissionGrantPolicy"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraMSRoleAssignment"; + TargetName = "Remove-MgRoleManagementDirectoryRoleAssignment" + IsApi = $false + }, + @{ + SourceName = "Remove-EntraMSRoleDefinition"; + TargetName = "Remove-MgRoleManagementDirectoryRoleDefinition"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraApplication"; + TargetName = "Remove-MgApplication"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraContact"; + TargetName = "Remove-MgContact"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraDeletedApplication"; + TargetName = "Remove-MgDirectoryDeletedItem"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraDevice"; + TargetName = "Remove-MgDevice"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraGroup"; + TargetName = "Remove-MgGroup"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraMSApplication"; + TargetName = "Remove-MgApplication"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraMSApplicationKey"; + TargetName = "Remove-MgApplicationKey"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraMSApplicationPassword"; + TargetName = "Remove-MgApplicationPassword"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraOAuth2PermissionGrant"; + TargetName = "Remove-MgOAuth2PermissionGrant"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraServicePrincipal"; + TargetName = "Remove-MgServicePrincipal"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraUser"; + TargetName = "Remove-MgUser"; + IsApi = $false + }, + @{ + SourceName = "Remove-EntraUserManager"; + TargetName = "Remove-MgUserManagerByRef"; + IsApi = $false + } +) \ No newline at end of file