Skip to content

Commit

Permalink
Added AADOnPremisePublishingProfileConnectorGroup resource
Browse files Browse the repository at this point in the history
  • Loading branch information
ritikmit committed Oct 4, 2024
1 parent 41ef158 commit aef70c1
Show file tree
Hide file tree
Showing 9 changed files with 1,144 additions and 0 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

[ClassVersion("1.0.0.0"), FriendlyName("AADConnectorGroupApplicationProxy")]
class MSFT_AADConnectorGroupApplicationProxy : OMI_BaseResource
{
[Write, Description("The name associated with the connectorGroup.")] String Name;
[Write, Description("The region the connectorGroup is assigned to and will optimize traffic for. This region can only be set if no connectors or applications are assigned to the connectorGroup. The possible values are: nam (for North America), eur (for Europe), aus (for Australia), asia (for Asia), ind (for India), and unknownFutureValue."), ValueMap{"nam","eur","aus","asia","ind","unknownFutureValue"}, Values{"nam","eur","aus","asia","ind","unknownFutureValue"}] String Region;
[Key, Description("The unique identifier for an entity. Read-only.")] String Id;
[Write, Description("Present ensures the policy exists, absent ensures it is removed."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
[Write, Description("Credentials of the 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("Secret of the Azure Active Directory tenant used for authentication."), EmbeddedInstance("MSFT_Credential")] String ApplicationSecret;
[Write, Description("Thumbprint of the Azure Active Directory application's authentication certificate to use for authentication.")] String CertificateThumbprint;
[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,6 @@

# AADConnectorGroupApplicationProxy

## Description

Azure AD Connector Group Application Proxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"resourceName": "AADConnectorGroupApplicationProxy",
"description": "This resource configures an Azure AD Connector Group Application Proxy.",
"permissions": {
"graph": {
"delegated": {
"read": [
{
"name": "Directory.ReadWrite.All"
}
],
"update": [
{
"name": "Directory.ReadWrite.All"
}
]
},
"application": {
"read": [
{
"name": "Directory.ReadWrite.All"
}
],
"update": [
{
"name": "Directory.ReadWrite.All"
}
]
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<#
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
{
AADConnectorGroupApplicationProxy "AADConnectorGroupApplicationProxy-testgroup"
{
ApplicationId = $ApplicationId
TenantId = $TenantId
CertificateThumbprint = $CertificateThumbprint
Ensure = "Present";
Id = "4984dcf7-d9e9-4663-90b4-5db09f92a669";
Name = "testgroup";
Region = "nam";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<#
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
{
AADConnectorGroupApplicationProxy "AADConnectorGroupApplicationProxy-testgroup"
{
ApplicationId = $ApplicationId
TenantId = $TenantId
CertificateThumbprint = $CertificateThumbprint
Ensure = "Present";
Id = "4984dcf7-d9e9-4663-90b4-5db09f92a669";
Name = "testgroup-new";
Region = "nam";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<#
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
{
AADConnectorGroupApplicationProxy "AADConnectorGroupApplicationProxy-testgroup"
{
ApplicationId = $ApplicationId
TenantId = $TenantId
CertificateThumbprint = $CertificateThumbprint
Ensure = "Absent";
Id = "4984dcf7-d9e9-4663-90b4-5db09f92a669";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
[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)

$Global:DscHelper = New-M365DscUnitTestHelper -StubModule $CmdletModule `
-DscResource "AADConnectorGroupApplicationProxy" -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 Get-PSSession -MockWith {
}

Mock -CommandName Remove-PSSession -MockWith {
}

Mock -CommandName Update-MgBetaOnPremisePublishingProfileConnectorGroup -MockWith {
}

Mock -CommandName New-MgBetaOnPremisePublishingProfileConnectorGroup -MockWith {
}

Mock -CommandName Remove-MgBetaOnPremisePublishingProfileConnectorGroup -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
return "Credentials"
}

# Mock Write-Host to hide output during the tests
Mock -CommandName Write-Host -MockWith {
}
$Script:exportedInstances =$null
$Script:ExportMode = $false
}
# Test contexts
Context -Name "The AADConnectorGroupApplicationProxy should exist but it DOES NOT" -Fixture {
BeforeAll {
$testParams = @{
Id = "FakeStringValue"
Name = "FakeStringValue"
Region = "nam"
Ensure = "Present"
Credential = $Credential;
}

Mock -CommandName Get-MgBetaOnPremisePublishingProfileConnectorGroup -MockWith {
return $null
}
}
It 'Should return Values from the Get method' {
(Get-TargetResource @testParams).Ensure | Should -Be 'Absent'
}
It 'Should return false from the Test method' {
Test-TargetResource @testParams | Should -Be $false
}
It 'Should Create the group from the Set method' {
Set-TargetResource @testParams
Should -Invoke -CommandName New-MgBetaOnPremisePublishingProfileConnectorGroup -Exactly 1
}
}

Context -Name "The AADConnectorGroupApplicationProxy exists but it SHOULD NOT" -Fixture {
BeforeAll {
$testParams = @{
Id = "FakeStringValue"
Name = "FakeStringValue"
Region = "nam"
Ensure = "Absent"
Credential = $Credential;
}

Mock -CommandName Get-MgBetaOnPremisePublishingProfileConnectorGroup -MockWith {
return @{
Id = "FakeStringValue"
Name = "FakeStringValue"
Region = "nam"
}
}
}

It 'Should return Values from the Get method' {
(Get-TargetResource @testParams).Ensure | Should -Be 'Present'
}

It 'Should return true from the Test method' {
Test-TargetResource @testParams | Should -Be $false
}

It 'Should Remove the group from the Set method' {
Set-TargetResource @testParams
Should -Invoke -CommandName Remove-MgBetaOnPremisePublishingProfileConnectorGroup -Exactly 1
}
}
Context -Name "The AADConnectorGroupApplicationProxy Exists and Values are already in the desired state" -Fixture {
BeforeAll {
$testParams = @{
Id = "FakeStringValue"
Name = "FakeStringValue"
Region = "nam"
Ensure = "Present"
Credential = $Credential;
}

Mock -CommandName Get-MgBetaOnPremisePublishingProfileConnectorGroup -MockWith {
return @{
Id = "FakeStringValue"
Name = "FakeStringValue"
Region = "nam"

}
}
}


It 'Should return true from the Test method' {
Test-TargetResource @testParams | Should -Be $true
}
}

Context -Name "The AADConnectorGroupApplicationProxy exists and values are NOT in the desired state" -Fixture {
BeforeAll {
$testParams = @{
Id = "FakeStringValue"
Name = "FakeStringValue"
Region = "nam"
Ensure = 'Present'
Credential = $Credential;
}

Mock -CommandName Get-MgBetaOnPremisePublishingProfileConnectorGroup -MockWith {
return @{
Id = "FakeStringValue"
Name = "NewFakeStringValue"
Region = "nam"
}
}
}

It 'Should return Values from the Get method' {
(Get-TargetResource @testParams).Ensure | Should -Be 'Present'
}

It 'Should return false from the Test method' {
Test-TargetResource @testParams | Should -Be $false
}

It 'Should call the Set method' {
Set-TargetResource @testParams
Should -Invoke -CommandName Update-MgBetaOnPremisePublishingProfileConnectorGroup -Exactly 1
}
}

Context -Name 'ReverseDSC Tests' -Fixture {
BeforeAll {
$Global:CurrentModeIsExport = $true
$Global:PartialExportFileName = "$(New-Guid).partial.ps1"
$testParams = @{
Credential = $Credential
}

Mock -CommandName Get-MgBetaOnPremisePublishingProfileConnectorGroup -MockWith {
return @{
Id = "FakeStringValue"
Name = "FakeStringValue"
Region = "nam"

}
}
}
It 'Should Reverse Engineer resource from the Export method' {
$result = Export-TargetResource @testParams
$result | Should -Not -BeNullOrEmpty
}
}
}
}

Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope
Loading

0 comments on commit aef70c1

Please sign in to comment.