forked from microsoft/Microsoft365DSC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bb79eb
commit b17cbd9
Showing
8 changed files
with
698 additions
and
0 deletions.
There are no files selected for viewing
408 changes: 408 additions & 0 deletions
408
...65DSC/DSCResources/MSFT_IntuneMobileAppsWin32LobApp/MSFT_IntuneMobileAppsWin32LobApp.psm1
Large diffs are not rendered by default.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
...DSCResources/MSFT_IntuneMobileAppsWin32LobApp/MSFT_IntuneMobileAppsWin32LobApp.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("IntuneMobileAppsWin32LobApp")] | ||
class MSFT_IntuneMobileAppsWin32LobApp : OMI_BaseResource | ||
{ | ||
[Key, Description("The name of the app.")] String DisplayName; | ||
[Write, Description("The unique identifier for an entity. Read-only.")] String Id; | ||
|
||
[Write, Description("Present ensures the instance exists, absent ensures it is removed."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] string Ensure; | ||
[Write, Description("Credentials of the workload's Admin"), EmbeddedInstance("MSFT_Credential")] string Credential; | ||
[Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId; | ||
[Write, Description("Id of the Azure Active Directory tenant used for authentication.")] String TenantId; | ||
[Write, Description("Thumbprint of the Azure Active Directory application's authentication certificate to use for authentication.")] String CertificateThumbprint; | ||
[Write, Description("Secret of the Azure Active Directory tenant used for authentication."), EmbeddedInstance("MSFT_Credential")] String ApplicationSecret; | ||
[Write, Description("Managed ID being used for authentication.")] Boolean ManagedIdentity; | ||
[Write, Description("Access token used for authentication.")] String AccessTokens[]; | ||
}; |
Empty file.
Empty file.
29 changes: 29 additions & 0 deletions
29
Modules/Microsoft365DSC/Examples/Resources/IntuneMobileAppsWin32LobApp/1-Create.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<# | ||
This example is used to test new resources and showcase the usage of new resources being worked on. | ||
It is not meant to use as a production baseline. | ||
#> | ||
|
||
Configuration Example | ||
{ | ||
param( | ||
[Parameter()] | ||
[System.String] | ||
$Id, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$DisplayName | ||
|
||
) | ||
|
||
Import-DscResource -ModuleName Microsoft365DSC | ||
node localhost | ||
{ | ||
IntuneMobileAppsWin32LobApp "IntuneMobileAppsWin32LobApp-Data Management" | ||
{ | ||
Id = "a1fc9fe2-728d-4867-9a72-a61e18f8c606"; | ||
DisplayName = "Custom Data Management"; | ||
Ensure = "Present"; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Modules/Microsoft365DSC/Examples/Resources/IntuneMobileAppsWin32LobApp/2-Update.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<# | ||
This example is used to test new resources and showcase the usage of new resources being worked on. | ||
It is not meant to use as a production baseline. | ||
#> | ||
|
||
Configuration Example | ||
{ | ||
param( | ||
[Parameter()] | ||
[System.String] | ||
$Id, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$DisplayName | ||
|
||
) | ||
|
||
Import-DscResource -ModuleName Microsoft365DSC | ||
node localhost | ||
{ | ||
IntuneMobileAppsWin32LobApp "IntuneMobileAppsWin32LobApp-Data Management" | ||
{ | ||
Id = "a1fc9fe2-728d-4867-9a72-a61e18f8c606"; | ||
DisplayName = "Custom Data Management updated"; | ||
Ensure = "Present"; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Modules/Microsoft365DSC/Examples/Resources/IntuneMobileAppsWin32LobApp/3-Remove.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<# | ||
This example is used to test new resources and showcase the usage of new resources being worked on. | ||
It is not meant to use as a production baseline. | ||
#> | ||
|
||
Configuration Example | ||
{ | ||
param( | ||
[Parameter()] | ||
[System.String] | ||
$Id, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$DisplayName | ||
) | ||
|
||
Import-DscResource -ModuleName Microsoft365DSC | ||
node localhost | ||
{ | ||
IntuneMobileAppsWin32LobApp "IntuneMobileAppsWin32LobApp-Data Management" | ||
{ | ||
Id = "a1fc9fe2-728d-4867-9a72-a61e18f8c606"; | ||
DisplayName = "Custom Data Management"; | ||
Ensure = "Absent"; | ||
} | ||
} | ||
} |
189 changes: 189 additions & 0 deletions
189
Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneMobileAppWin32LOBApp.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
[CmdletBinding()] | ||
param( | ||
) | ||
$M365DSCTestFolder = Join-Path -Path $PSScriptRoot ` | ||
-ChildPath '..\..\Unit' ` | ||
-Resolve | ||
$CmdletModule = (Join-Path -Path $M365DSCTestFolder ` | ||
-ChildPath '\Stubs\Microsoft365.psm1' ` | ||
-Resolve) | ||
$GenericStubPath = (Join-Path -Path $M365DSCTestFolder ` | ||
-ChildPath '\Stubs\Generic.psm1' ` | ||
-Resolve) | ||
Import-Module -Name (Join-Path -Path $M365DSCTestFolder ` | ||
-ChildPath '\UnitTestHelper.psm1' ` | ||
-Resolve) | ||
|
||
$CurrentScriptPath = $PSCommandPath.Split('\') | ||
$CurrentScriptName = $CurrentScriptPath[$CurrentScriptPath.Length -1] | ||
$ResourceName = $CurrentScriptName.Split('.')[1] | ||
$Global:DscHelper = New-M365DscUnitTestHelper -StubModule $CmdletModule ` | ||
-DscResource $ResourceName -GenericStubModule $GenericStubPath | ||
|
||
Describe -Name $Global:DscHelper.DescribeHeader -Fixture { | ||
InModuleScope -ModuleName $Global:DscHelper.ModuleName -ScriptBlock { | ||
Invoke-Command -ScriptBlock $Global:DscHelper.InitializeScript -NoNewScope | ||
BeforeAll { | ||
|
||
$secpasswd = ConvertTo-SecureString (New-Guid | Out-String) -AsPlainText -Force | ||
$Credential = New-Object System.Management.Automation.PSCredential ('[email protected]', $secpasswd) | ||
|
||
Mock -CommandName Confirm-M365DSCDependencies -MockWith { | ||
} | ||
|
||
Mock -CommandName New-M365DSCConnection -MockWith { | ||
return "Credentials" | ||
} | ||
|
||
# Mock Write-Host to hide output during the tests | ||
Mock -CommandName Write-Host -MockWith { | ||
} | ||
|
||
Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { | ||
} | ||
Mock -CommandName New-MgBetaDeviceAppManagementMobileApp -MockWith { | ||
} | ||
Mock -CommandName Update-MgBetaDeviceAppManagementMobileApp -MockWith { | ||
} | ||
Mock -CommandName Remove-MgBetaDeviceAppManagementMobileApp -MockWith { | ||
} | ||
|
||
$Script:exportedInstances =$null | ||
$Script:ExportMode = $false | ||
} | ||
|
||
#Test contexts | ||
|
||
Context -Name '1. The instance should exist but it DOES NOT' -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
Id = '046e0b16-76ce-4b49-bf1b-1cc5bd94fb47' | ||
DisplayName = 'Data Management' | ||
Ensure = 'Present' | ||
Credential = $Credential | ||
} | ||
|
||
Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { | ||
return $null | ||
} | ||
} | ||
|
||
It '1.1 Should return Values from the Get method' { | ||
(Get-TargetResource @testParams).Ensure | Should -Be 'Absent' | ||
} | ||
It '1.2 Should return false from the Test method' { | ||
Test-TargetResource @testParams | Should -Be $false | ||
} | ||
It '1.3 Should create a new instance from the Set method' { | ||
Set-TargetResource @testParams | ||
Should -Invoke -CommandName New-MgBetaDeviceAppManagementMobileApp -Exactly 1 | ||
} | ||
} | ||
|
||
Context -Name '2. The instance exists but it SHOULD NOT' -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
Id = '046e0b16-76ce-4b49-bf1b-1cc5bd94fb47' | ||
DisplayName = 'Data Management' | ||
Ensure = 'Absent' | ||
Credential = $Credential | ||
} | ||
|
||
Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { | ||
return @{ | ||
Id = '046e0b16-76ce-4b49-bf1b-1cc5bd94fb47' | ||
DisplayName = 'Data Management' | ||
} | ||
} | ||
} | ||
|
||
It '2.1 Should return values from the Get method' { | ||
(Get-TargetResource @testParams).Ensure | Should -Be 'Present' | ||
} | ||
It '2.2 Should return false from the Test method' { | ||
Test-TargetResource @testParams | Should -Be $false | ||
} | ||
It '2.3 Should remove the instance from the Set method' { | ||
Set-TargetResource @testParams | ||
Should -Invoke -CommandName Remove-MgBetaDeviceAppManagementMobileApp -Exactly 1 | ||
} | ||
} | ||
|
||
Context -Name '3. The instance exists and values are already in the desired state' -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
Id = '046e0b16-76ce-4b49-bf1b-1cc5bd94fb47' | ||
DisplayName = 'Data Management' | ||
Ensure = 'Present' | ||
Credential = $Credential | ||
} | ||
|
||
Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { | ||
return @{ | ||
Id = '046e0b16-76ce-4b49-bf1b-1cc5bd94fb47' | ||
DisplayName = 'Data Management' | ||
} | ||
} | ||
} | ||
|
||
It '3.0 Should return true from the Test method' { | ||
Test-TargetResource @testParams | Should -Be $true | ||
} | ||
} | ||
|
||
Context -Name '4. The instance exists and values are NOT in the desired state' -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
Id = "046e0b16-76ce-4b49-bf1b-1cc5bd94fb47" | ||
DisplayName = "Data Management" | ||
Ensure = 'Present' | ||
Credential = $Credential | ||
} | ||
|
||
Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { | ||
return @{ | ||
Id = "046e0b16-76ce-4b49-bf1b-1cc5bd94fb47" | ||
DisplayName = "Data Management 1" #drift | ||
} | ||
} | ||
} | ||
|
||
It '4.1 Should return Values from the Get method' { | ||
(Get-TargetResource @testParams).Ensure | Should -Be 'Present' | ||
} | ||
|
||
It '4.2 Should return false from the Test method' { | ||
Test-TargetResource @testParams | Should -Be $false | ||
} | ||
|
||
It '4.3 Should call the Set method' { | ||
Set-TargetResource @testParams | ||
Should -Invoke -CommandName Update-MgBetaDeviceAppManagementMobileApp -Exactly 1 | ||
} | ||
} | ||
|
||
Context -Name '5. ReverseDSC Tests' -Fixture { | ||
BeforeAll { | ||
$Global:CurrentModeIsExport = $true | ||
$Global:PartialExportFileName = "$(New-Guid).partial.ps1" | ||
$testParams = @{ | ||
Credential = $Credential | ||
} | ||
|
||
Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { | ||
return @{ | ||
Id = "046e0b16-76ce-4b49-bf1b-1cc5bd94fb47" | ||
DisplayName = "Data Management" | ||
} | ||
} | ||
} | ||
|
||
It '5.1 Should Reverse Engineer resource from the Export method' { | ||
$result = Export-TargetResource @testParams | ||
$result | Should -Not -BeNullOrEmpty | ||
} | ||
} | ||
} | ||
} | ||
|
||
Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope |