Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft]: Microsoft365 DSC for Intune MobileApps Win32 Lob Apps. #5148

Merged
merged 3 commits into from
Oct 14, 2024
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

Large diffs are not rendered by default.

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[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# IntuneMobileAppsWin32LobApp

## Description

Configures a resource for navigation property for Intune mobile app. Default app cannot be renamed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"resourceName": "IntuneMobileAppsWin32LobApp",
"description": "Configures a resource for navigation property for Intune mobile app.",
"permissions": {
"graph": {
"delegated": {
"read": [
{
"name": "DeviceManagementApps.Read.All"
}
],
"update": [
{
"name": "DeviceManagementApps.ReadWrite.All"
}
]
},
"application": {
"read": [
{
"name": "DeviceManagementApps.Read.All"
}
],
"update": [
{
"name": "DeviceManagementApps.ReadWrite.All"
}
]
}
}
}
}
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";
}
}
}
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";
}
}
}
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";
}
}
}
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
Loading