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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
'PublisherDomain','Web','RequiredResourceAccess')

foreach ($prop in $propsToConvert) {
$value = $_.$prop | ConvertTo-Json -Depth 10 | ConvertFrom-Json
$value = $_.$prop | ConvertTo-Json -Depth 5 | ConvertFrom-Json
$_ | Add-Member -MemberType NoteProperty -Name $prop -Value ($value) -Force
}

Expand Down
64 changes: 64 additions & 0 deletions test/module/Entra/Get-EntraApplicationKeyCredential.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
BeforeAll {
if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){
Import-Module Microsoft.Graph.Entra
}
Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force

$scriptblock = {
@{
"KeyCredentials" = @(
@{
"CustomKeyIdentifier" = ""
"EndDate" = "10/23/2024 11:36:56 AM"
"KeyId" = "aaaaaaaa-0b0b-1c1c-2d2d-333333333333"
"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 "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
$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 "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
$result | Should -Not -BeNullOrEmpty
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationKeyCredential"
Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter {
$Headers.'User-Agent' | Should -Be $userAgentHeaderValue
$true
}
}
It "Should execute successfully without throwing an error " {
# Disable confirmation prompts
$originalDebugPreference = $DebugPreference
$DebugPreference = 'Continue'

try {
# Act & Assert: Ensure the function doesn't throw an exception
{ Get-EntraApplicationKeyCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw
} finally {
# Restore original confirmation preference
$DebugPreference = $originalDebugPreference
}
}
}
}
86 changes: 86 additions & 0 deletions test/module/Entra/Get-EntraApplicationOwner.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
BeforeAll {
if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){
Import-Module Microsoft.Graph.Entra
}
Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force

$mockResponse = {
return @{
value = @(
@{
Id = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
ageGroup = $null
onPremisesLastSyncDateTime = $null
creationType = $null
preferredLanguage = $null
mail = "admin@contonso.com"
securityIdentifier = "S-1-12-1-1093396945-1080104032-2731339150-364051459"
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 "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
Write-Host $result
$result | Should -Not -BeNullOrEmpty
$result.Id | should -Be @('aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb')

Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1
}
It "Should fail when ObjectId is empty" {
{ Get-EntraApplicationOwner -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string."
}
It "Should fail when ObjectId is null" {
{ Get-EntraApplicationOwner -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*"
}
It "Should fail when All has an argument" {
{ Get-EntraApplicationOwner -All $true } | Should -Throw "A positional parameter cannot be found that accepts argument 'True'.*"
}
It "Should fail when Top is empty" {
{ Get-EntraApplicationOwner -Top } | Should -Throw "Missing an argument for parameter 'Top'*"
}
It "Should fail when Top is invalid" {
{ Get-EntraApplicationOwner -Top XY } | Should -Throw "Cannot process argument transformation on parameter 'Top'*"
}
It "Property parameter should work" {
$result = Get-EntraApplicationOwner -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property Id
$result | Should -Not -BeNullOrEmpty
$result.Id | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
}
It "Should contain 'User-Agent' header" {
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationOwner"
$result = Get-EntraApplicationOwner -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
$result | Should -Not -BeNullOrEmpty
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationOwner"
Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter {
$Headers.'User-Agent' | Should -Be $userAgentHeaderValue
$true
}
}
It "Should execute successfully without throwing an error " {
# Disable confirmation prompts
$originalDebugPreference = $DebugPreference
$DebugPreference = 'Continue'

try {
# Act & Assert: Ensure the function doesn't throw an exception
{ Get-EntraApplicationOwner -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw
} finally {
# Restore original confirmation preference
$DebugPreference = $originalDebugPreference
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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 = {
@{
"PasswordCredentials" = @(
@{
"CustomKeyIdentifier" = {116, 101, 115, 116}
"DisplayName" = "Test"
"EndDateTime" = "10/23/2024 11:36:56 AM"
"KeyId" = "aaaaaaaa-0b0b-1c1c-2d2d-333333333333"
"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 "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
$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 "Property parameter should work" {
$result = Get-EntraApplicationPasswordCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property DisplayName
$result | Should -Not -BeNullOrEmpty
$result.DisplayName | Should -Be "Test"

Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1
}

It "Should fail when Property is empty" {
{ Get-EntraApplicationPasswordCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*"
}

It "Should contain 'User-Agent' header" {
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationPasswordCredential"
$result = Get-EntraApplicationPasswordCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
$result | Should -Not -BeNullOrEmpty
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationPasswordCredential"
Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter {
$Headers.'User-Agent' | Should -Be $userAgentHeaderValue
$true
}
}
It "Should execute successfully without throwing an error " {
# Disable confirmation prompts
$originalDebugPreference = $DebugPreference
$DebugPreference = 'Continue'

try {
# Act & Assert: Ensure the function doesn't throw an exception
{ Get-EntraApplicationPasswordCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw
} finally {
# Restore original confirmation preference
$DebugPreference = $originalDebugPreference
}
}
}
}
131 changes: 131 additions & 0 deletions test/module/Entra/Get-EntraDeletedApplication.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
BeforeAll {
if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){
Import-Module Microsoft.Graph.Entra
}
Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force

$scriptblock = {
return @(
[PSCustomObject]@{
"AddIns" = {}
"AppRoles" = {}
"GroupMembershipClaims" = {}
"IdentifierUris" = {}
"Info" = @{
LogoUrl="";
}
"IsDeviceOnlyAuthSupported" = $null
"KeyCredentials" = {}
"OptionalClaims" = {}
"ParentalControlSettings" = @{
CountriesBlockedForMinors=@{};
LegalAgeGroupRule="Allow";
}
"PasswordCredentials" = {}
"Api" = @{
KnownClientApplications=@{};
PreAuthorizedApplications=@{};
}
"PublicClient" = @{
RedirectUris=@{};
}
"PublisherDomain" = "contoso.com"
"Web" = @{
HomePageUrl="";
LogoutUrl="";
RedirectUris=@{};
Oauth2AllowImplicitFlow=""
}
"RequiredResourceAccess" = $null
"DisplayName" = "Mock-test-App"
"Id" = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
"Logo" = $null
"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 -Depth 10 | 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 $true} | Should -Throw "A positional parameter cannot be found that accepts argument 'True'.*"
}
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 -Depth 10 | 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 -Depth 10 | 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 -Depth 10 | 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 -Depth 10 | ConvertFrom-Json
$result.ObjectId | should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb"
}
It "Should contain Filter in parameters when passed SearchString to it" {
$result = Get-EntraDeletedApplication -SearchString 'Mock-test-App' | ConvertTo-Json -Depth 10| ConvertFrom-Json
$params = Get-Parameters -data $result.Parameters
$params.Filter | Should -Match "Mock-test-App"
}
It "Property parameter should work" {
$result = Get-EntraDeletedApplication -Property "DisplayName" | 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 fail when Property is empty" {
{ Get-EntraDeletedApplication -Property } | Should -Throw "Missing an argument for parameter 'Property'*"
}
It "Should contain 'User-Agent' header" {
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDeletedApplication"
$result = Get-EntraDeletedApplication -Filter "DisplayName -eq 'Mock-test-App'" | ConvertTo-Json -Depth 10 | ConvertFrom-Json
$result | Should -Not -BeNullOrEmpty
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDeletedApplication"
Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter {
$Headers.'User-Agent' | Should -Be $userAgentHeaderValue
$true
}
}
It "Should execute successfully without throwing an error " {
# Disable confirmation prompts
$originalDebugPreference = $DebugPreference
$DebugPreference = 'Continue'

try {
# Act & Assert: Ensure the function doesn't throw an exception
{ Get-EntraDeletedApplication -Debug } | Should -Not -Throw
} finally {
# Restore original confirmation preference
$DebugPreference = $originalDebugPreference
}
}
}
}
Loading