Skip to content

Commit

Permalink
Draft Intune DSC IOSApps
Browse files Browse the repository at this point in the history
  • Loading branch information
Kajalp1079 committed Oct 5, 2024
1 parent 49230ce commit 59f0429
Show file tree
Hide file tree
Showing 8 changed files with 743 additions and 0 deletions.

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("IntuneMobileAppsIOSLobApp")]
class MSFT_IntuneMobileAppsIOSLobApp : OMI_BaseResource
{
[Key, Description("The name of the app category.")] 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,3 @@
# IntuneMobileAppsIOSLobApp

## Description
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"resourceName": "IntuneMobileAppsIOSLobApp",
"description": "Configures a resource for navigation property for Intune mobile app categories.",
"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,32 @@
<#
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]
$ApplicationId,

[Parameter()]
[System.String]
$TenantId,

[Parameter()]
[System.String]
$CertificateThumbprint
)

Import-DscResource -ModuleName Microsoft365DSC
node localhost
{
IntuneMobileAppsIOSLobApp "IntuneMobileAppsIOSLobApp-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,32 @@
<#
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]
$ApplicationId,

[Parameter()]
[System.String]
$TenantId,

[Parameter()]
[System.String]
$CertificateThumbprint
)

Import-DscResource -ModuleName Microsoft365DSC
node localhost
{
IntuneMobileAppsIOSLobApp "IntuneMobileAppsIOSLobApp-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,32 @@
<#
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]
$ApplicationId,

[Parameter()]
[System.String]
$TenantId,

[Parameter()]
[System.String]
$CertificateThumbprint
)

Import-DscResource -ModuleName Microsoft365DSC
node localhost
{
IntuneMobileAppsIOSLobApp "IntuneMobileAppsIOSLobApp-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

0 comments on commit 59f0429

Please sign in to comment.