Skip to content

Commit

Permalink
Revamp Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikCharlebois committed Jul 11, 2024
1 parent d4279c7 commit 13bdcc5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 26 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/Scheduled - Generate Permission List.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Unit Tests
on: [push, pull_request]

jobs:
# This workflow contains a single job called "build"
UnitTests:
# The type of runner that the job will run on
runs-on: windows-latest

permissions: write-all

# Only when run from the main repo
if: github.repository == 'microsoft/Microsoft365DSC'

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install Dependencies
shell: pwsh
run: |
Import-Module './Modules/M365DSCUtil.psm1' -Force;
Update-M365DSCModule
- name: Get Permissions List
shell: pwsh
run: |
Import-Module './Tests/TestHarness.psm1' -Force;
$permissions = Get-M365DSCAllGraphPermissionsList
$permission - join ',' | Out-File '.\Tests\QA\Graph.PermissionList.txt'
- name: Commit Permissions List
shell: powershell
run: |
git config --local user.email "nicharl@microsoft.com"
git config --local user.name "NikCharlebois"
git add D:/a/Microsoft365DSC/Microsoft365DSC/Tests/QA/*
git pull
git commit -m "Updated Graph Permissions List"
git push
$SHA = git rev-parse HEAD
echo "commitid=$SHA" >> $env:GITHUB_OUTPUT
27 changes: 1 addition & 26 deletions Tests/QA/Microsoft365DSC.SettingsJson.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,7 @@ Describe -Name 'Successfully import Settings.json files' {

Describe -Name 'Successfully validate all used permissions in Settings.json files ' {
BeforeAll {
$allModules = Get-module Microsoft.graph.* -ListAvailable
$allPermissions = @()
foreach ($module in $allModules)
{
$cmds = Get-Command -Module $module.Name
foreach ($cmd in $cmds)
{
$graphInfo = Find-MgGraphCommand -Command $cmd.Name -ErrorAction SilentlyContinue
if ($null -ne $graphInfo)
{
$permissions = $graphInfo.Permissions | Where-Object -FilterScript {$_.PermissionType -eq 'Application'}
$allPermissions += $permissions.Name
}
}
}

$allPermissions+= @('OrgSettings-Microsoft365Install.Read.All', `
'OrgSettings-Forms.Read.All', `
'OrgSettings-Todo.Read.All', `
'OrgSettings-AppsAndServices.Read.All', `
'OrgSettings-DynamicsVoice.Read.All', `
'ReportSettings.Read.All', `
'RoleManagementPolicy.Read.Directory', `
'RoleEligibilitySchedule.Read.Directory', `
'Agreement.Read.All')
$roles = $allPermissions | Select-Object -Unique | Sort-Object -Descending:$false

}

It "Permissions used in settings.json file for '<ResourceName>' should exist" -TestCases $settingsFiles {
Expand Down
35 changes: 35 additions & 0 deletions Tests/TestHarness.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,41 @@ function Invoke-TestHarness
return $results
}

function Get-M365DSCAllGraphPermissionsList
{
[CmdletBinding()]
[OutputType([System.String[]])]
param()

$allModules = Get-module Microsoft.graph.* -ListAvailable
$allPermissions = @()
foreach ($module in $allModules)
{
$cmds = Get-Command -Module $module.Name
foreach ($cmd in $cmds)
{
$graphInfo = Find-MgGraphCommand -Command $cmd.Name -ErrorAction SilentlyContinue
if ($null -ne $graphInfo)
{
$permissions = $graphInfo.Permissions | Where-Object -FilterScript {$_.PermissionType -eq 'Application'}
$allPermissions += $permissions.Name
}
}
}

$allPermissions+= @('OrgSettings-Microsoft365Install.Read.All', `
'OrgSettings-Forms.Read.All', `
'OrgSettings-Todo.Read.All', `
'OrgSettings-AppsAndServices.Read.All', `
'OrgSettings-DynamicsVoice.Read.All', `
'ReportSettings.Read.All', `
'RoleManagementPolicy.Read.Directory', `
'RoleEligibilitySchedule.Read.Directory', `
'Agreement.Read.All')
$roles = $allPermissions | Select-Object -Unique | Sort-Object -Descending:$false
return $roles
}

function Invoke-QualityChecksHarness
{
[CmdletBinding()]
Expand Down

0 comments on commit 13bdcc5

Please sign in to comment.