Skip to content

Commit c199bed

Browse files
givinalisGivinalis Omachar
andauthored
356 - Added Authentication checks for cmdlets under DirectoryManagement submodule for Entra Beta (#1539)
* feat: added auth checks * test: mocked Get-EntraContext on all tests * test: added scenario checks on all tests * tests: updated failing tests --------- Co-authored-by: Givinalis Omachar <giomachar@microsoft.com>
1 parent 852555a commit c199bed

133 files changed

Lines changed: 1287 additions & 8 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Add-EntraBetaAdministrativeUnitMember.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ function Add-EntraBetaAdministrativeUnitMember {
1313
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Unique ID of the administrative unit.")]
1414
[System.String] $AdministrativeUnitId
1515
)
16+
17+
begin {
18+
# Ensure connection to Microsoft Entra
19+
if (-not (Get-EntraContext)) {
20+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes AdministrativeUnit.ReadWrite.All' to authenticate."
21+
Write-Error -Message $errorMessage -ErrorAction Stop
22+
return
23+
}
24+
}
25+
1626
PROCESS {
1727
$params = @{}
1828
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Add-EntraBetaCustomSecurityAttributeDefinitionAllowedValue.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ function Add-EntraBetaCustomSecurityAttributeDefinitionAllowedValue {
1616
[System.String] $CustomSecurityAttributeDefinitionId
1717
)
1818

19+
begin {
20+
# Ensure connection to Microsoft Entra
21+
if (-not (Get-EntraContext)) {
22+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes CustomSecAttributeDefinition.ReadWrite.All' to authenticate."
23+
Write-Error -Message $errorMessage -ErrorAction Stop
24+
return
25+
}
26+
}
27+
1928
PROCESS {
2029
$params = @{}
2130
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Add-EntraBetaDeviceRegisteredOwner.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ function Add-EntraBetaDeviceRegisteredOwner {
1414
[System.String] $OwnerId
1515
)
1616

17+
begin {
18+
# Ensure connection to Microsoft Entra
19+
if (-not (Get-EntraContext)) {
20+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Directory.AccessAsUser.All' to authenticate."
21+
Write-Error -Message $errorMessage -ErrorAction Stop
22+
return
23+
}
24+
}
25+
1726
PROCESS {
1827
$params = @{}
1928
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Add-EntraBetaDeviceRegisteredUser.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ function Add-EntraBetaDeviceRegisteredUser {
1414
[System.String] $UserId
1515
)
1616

17+
begin {
18+
# Ensure connection to Microsoft Entra
19+
if (-not (Get-EntraContext)) {
20+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Device.ReadWrite.All' to authenticate."
21+
Write-Error -Message $errorMessage -ErrorAction Stop
22+
return
23+
}
24+
}
25+
1726
PROCESS {
1827
$params = @{}
1928
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Add-EntraBetaScopedRoleMembership.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ function Add-EntraBetaScopedRoleMembership {
1818
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
1919
[System.String] $AdministrativeUnitId
2020
)
21+
22+
begin {
23+
# Ensure connection to Microsoft Entra
24+
if (-not (Get-EntraContext)) {
25+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.ReadWrite.Directory' to authenticate."
26+
Write-Error -Message $errorMessage -ErrorAction Stop
27+
return
28+
}
29+
}
30+
2131
PROCESS {
2232
$params = @{}
2333
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Confirm-EntraBetaDomain.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ function Confirm-EntraBetaDomain {
1111
[Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $false, HelpMessage = "Allows external admin takeover of an unmanaged domain. Default is false.")]
1212
[System.Boolean] $ForceTakeover
1313
)
14+
15+
begin {
16+
# Ensure connection to Microsoft Entra
17+
if (-not (Get-EntraContext)) {
18+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Domain.ReadWrite.Directory' to authenticate."
19+
Write-Error -Message $errorMessage -ErrorAction Stop
20+
return
21+
}
22+
}
23+
1424
PROCESS {
1525
$params = @{}
1626
$body = @{}

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Enable-EntraBetaDirectoryRole.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ function Enable-EntraBetaDirectoryRole {
1010
[System.String] $RoleTemplateId
1111
)
1212

13+
begin {
14+
# Ensure connection to Microsoft Entra
15+
if (-not (Get-EntraContext)) {
16+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.ReadWrite.Directory' to authenticate."
17+
Write-Error -Message $errorMessage -ErrorAction Stop
18+
return
19+
}
20+
}
21+
1322
PROCESS {
1423
$params = @{}
1524
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Get-EntraBetaAccountSku.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ function Get-EntraBetaAccountSku {
1010
[System.Guid] $TenantId
1111
)
1212

13+
begin {
14+
# Ensure connection to Microsoft Entra
15+
if (-not (Get-EntraContext)) {
16+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Organization.Read.All, LicenseAssignment.Read.All' to authenticate."
17+
Write-Error -Message $errorMessage -ErrorAction Stop
18+
return
19+
}
20+
}
21+
1322
PROCESS {
1423
$params = @{}
1524
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Get-EntraBetaAdministrativeUnit.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ function Get-EntraBetaAdministrativeUnit {
2323
[System.String[]] $Property
2424
)
2525

26+
begin {
27+
# Ensure connection to Microsoft Entra
28+
if (-not (Get-EntraContext)) {
29+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes AdministrativeUnit.Read.All' to authenticate."
30+
Write-Error -Message $errorMessage -ErrorAction Stop
31+
return
32+
}
33+
}
34+
2635
PROCESS {
2736
$params = @{}
2837
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand

module/EntraBeta/Microsoft.Entra.Beta/DirectoryManagement/Get-EntraBetaAdministrativeUnitMember.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ function Get-EntraBetaAdministrativeUnitMember {
2020
[System.String[]] $Property
2121
)
2222

23+
begin {
24+
# Ensure connection to Microsoft Entra
25+
if (-not (Get-EntraContext)) {
26+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes AdministrativeUnit.ReadWrite.All' to authenticate."
27+
Write-Error -Message $errorMessage -ErrorAction Stop
28+
return
29+
}
30+
}
31+
2332
PROCESS {
2433
$params = @{}
2534
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand

0 commit comments

Comments
 (0)