Skip to content

Commit e0a17f4

Browse files
committed
Add validation tests for Contoso users' allowed cities, states, and titles; update documentation for email and postal code formats
1 parent 7afd15f commit e0a17f4

53 files changed

Lines changed: 1008 additions & 49 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.

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Custom Maester Test Collection
22

3-
A collection of customs tests that can be quickly dropped into [Maester](https://www.maester.dev) and customized to your enviroment where needed.
3+
A collection of customs tests that can be quickly dropped into [Maester](https://www.maester.dev) and customized to your enviroment where needed.
44

55
This repository is still in it's beginning stages and I plan to add many more tests to this repository that just aren't 365 focused as well. I welcome any contributions, please make sure you create all 3 files per test so that it works smoothly for everyone - [Creating Tests](https://devclate.github.io/Custom-Maester-Tests/docs/Getting-Started/create-a-test/)
66

@@ -9,6 +9,7 @@ There is also a webversion at [Custom Maester Tests](https://devclate.github.io/
99
## Introduction
1010

1111
### What are custom Maester tests?
12+
1213
Custom Maester tests are tests that fully integrate into Maester's framework to test your Microsoft 365 tenant and anything else you want to using Pester tests. Also providing PowerShell scripts to resolve any issues where possible.
1314

1415
### Why custom Maester tests?
@@ -37,3 +38,20 @@ Now when you run your custom tests folder these tests should show
3738

3839
For all files, run the Find and Replace in VSCode for "Contoso" with your company name. I have this as the last step to ensure the test works correctly in your enviroment before changing the name.
3940

41+
## Using your own company standards
42+
43+
### Step 1: Locate validation.json
44+
45+
By default, the validation.json is location in the `tests/Entra/Validating` folder
46+
47+
### Step 2: Update config file
48+
49+
Update and or remove any fields that aren't necessary, or you can add more as well.
50+
51+
### Step 3: Save config file
52+
53+
Save the config file
54+
55+
### Step 4: Run tests
56+
57+
Run your tests again and see how the results change.

tests/Entra/Formatting/Test-ContosoUsersFormattingCapitolInitialEmail.md renamed to tests/Entra/Formatting/Test-ContosoUsersFormattingCapitalInitialEmail.md

File renamed without changes.

tests/Entra/Formatting/Test-ContosoUsersFormattingCapitolInitialEmail.ps1 renamed to tests/Entra/Formatting/Test-ContosoUsersFormattingCapitalInitialEmail.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Test-ContosoUsersFormattingCapitolInitialEmail {
1+
function Test-ContosoUsersFormattingCapitalInitialEmail {
22
$result = $true
33
try {
44
$users = Invoke-MtGraphRequest -RelativeUri "users" -Filter "userType eq 'Member'" -Select "displayName","givenName","surname","mail"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
BeforeAll {
3-
. "$PSScriptRoot\Test-ContosoUsersFormattingCapitolInitialEmail.ps1"
3+
. "$PSScriptRoot\Test-ContosoUsersFormattingCapitalInitialEmail.ps1"
44
}
55

66
Describe "Contoso" -Tag "ENTRA.UF.1003.T01.Email", "Entra", "CustomTests", "Formatting", "Users" {
77
It "ENTRA.UF.1003.T01.Email: Must be Capital First Initial and Last Name with First Letter Capitalized" {
8-
$result = Test-ContosoUsersFormattingCapitolInitialEmail
8+
$result = Test-ContosoUsersFormattingCapitalInitialEmail
99
$result | Should -Be $true -Because "All user emails must follow the capital-initial format."
1010
}
1111
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
BeforeAll {
2+
. "$PSScriptRoot/Test-ContosoUsersAllowedBusinessNumbers.ps1"
3+
}
4+
5+
Describe "Contoso" -Tag "ENTRA.UV.1007", "Entra", "CustomTests", "Validation", "Users", "BusinessNumber" {
6+
It "ENTRA.UV.1007: Business Number - All users should have an allowed business number" {
7+
$result = Test-ContosoUsersAllowedBusinessNumbers
8+
$result | Should -Be $true -Because "All users must have a business number from the valid list."
9+
}
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
This test checks if there are any users missing or using an invalid business phone number from the valid list.
2+
3+
Contoso's company policy requires that all users have a valid business phone number. This is crucial for operational needs.
4+
5+
**To remediate this issue:**
6+
7+
- Identify any user with a missing or invalid business phone number.
8+
- Submit a correction request through [Form: Invalid or Missing Business Number](https://contoso.service-now.com/busnumbermissing).
9+
- 🔺 If no action occurs within three days, escalate to HR.
10+
11+
**Learn more:**
12+
13+
- [Invalid or Missing Business Number](https://contoso.service-now.com/busnumbermissing)
14+
- [HR Escalation Process](https://contoso.service-now.com/hrescalation)
15+
16+
<!--- Results --->
17+
18+
%TestResult%
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function Test-ContosoUsersAllowedBusinessNumbers {
2+
param(
3+
[string] $ValidatingPath = ("$PSScriptRoot/validation.json")
4+
)
5+
$result = $true
6+
try {
7+
# Log the ValidatingPath for debugging
8+
Write-Output "Using ValidatingPath: $ValidatingPath"
9+
10+
# Load valid business numbers from validation.json
11+
$validation = Get-Content -Path $ValidatingPath -Raw | ConvertFrom-Json -Depth 10
12+
$validNumbers = $validation.validLocations.businessPhones
13+
14+
# Retrieve all member users from Graph, selecting businessPhones
15+
$users = Invoke-MtGraphRequest -RelativeUri "users" -Filter "userType eq 'Member'" -Select "displayName","businessPhones"
16+
$invalidUsers = @()
17+
18+
foreach ($user in $users) {
19+
# Skip certain accounts you do not want to evaluate
20+
if ($user.displayName -eq "On-Premises Directory Synchronization Service Account") {
21+
continue
22+
}
23+
24+
# Check if the user’s business number is missing OR not in the list of valid business numbers
25+
$phone = $user.businessPhones[0]
26+
if ($null -eq $phone -or -not ($validNumbers -contains $phone)) {
27+
$result = $false
28+
$invalidUsers += $user
29+
}
30+
}
31+
32+
if ($result) {
33+
$TestResults = "All users have a valid business number."
34+
} else {
35+
$TestResults = "These users have invalid or missing business numbers:`n%TestResult%"
36+
}
37+
38+
Add-MtTestResultDetail -Result $TestResults -GraphObjects $invalidUsers -GraphObjectType Users
39+
}
40+
catch {
41+
$result = $false
42+
Write-Error $_.Exception.Message
43+
}
44+
45+
return $result
46+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
BeforeAll {
2+
. "$PSScriptRoot/Test-ContosoUsersAllowedCities.ps1"
3+
}
4+
5+
Describe "Contoso" -Tag "ENTRA.UV.1003", "Entra", "CustomTests", "Validation", "Users", "City" {
6+
It "ENTRA.UV.1003: Cities - All users should have a valid city" {
7+
$result = Test-ContosoUsersAllowedCities
8+
$result | Should -Be $true -Because "All users must have a city from the valid list."
9+
}
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
This test checks if there are any users missing or using an invalid city from the valid list.
2+
3+
Contoso's company policy requires that all users have a valid city on record. This is crucial for ensuring correct contact information.
4+
5+
**To remediate this issue:**
6+
7+
- Identify any user with an invalid or missing city.
8+
- Submit a correction request through [Form: Invalid or Missing City - HR Ticket](https://contoso.service-now.com/invalidcity).
9+
- 🔺 If no action occurs within three days, escalate to HR.
10+
11+
**Learn more:**
12+
13+
- [Invalid or Missing City - HR Ticket](https://contoso.service-now.com/invalidcity)
14+
- [HR Escalation Process](https://contoso.service-now.com/hrescalation)
15+
16+
<!--- Results --->
17+
18+
%TestResult%
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function Test-ContosoUsersAllowedCities {
2+
param(
3+
[string] $ValidatingPath = ("$PSScriptRoot/validation.json")
4+
)
5+
$result = $true
6+
try {
7+
# Log the ValidatingPath for debugging
8+
Write-Output "Using ValidatingPath: $ValidatingPath"
9+
10+
# Load valid cities from validation.json
11+
$validation = Get-Content -Path $ValidatingPath -Raw | ConvertFrom-Json
12+
$validCities = $validation.validLocations.city
13+
14+
# Retrieve all member users from Graph
15+
$users = Invoke-MtGraphRequest -RelativeUri "users" -Filter "userType eq 'Member'" -Select "displayName","city"
16+
$invalidUsers = @()
17+
18+
foreach ($user in $users) {
19+
if ($user.displayName -eq "On-Premises Directory Synchronization Service Account") {
20+
continue
21+
}
22+
# Check if city is missing or invalid (case-sensitive)
23+
if ($null -eq $user.city -or -not ($validCities | Where-Object { $_ -ceq $user.city })) {
24+
$result = $false
25+
$invalidUsers += $user
26+
}
27+
}
28+
29+
if ($result) {
30+
$TestResults = "All users have a valid city."
31+
} else {
32+
$TestResults = "These users have invalid or missing cities:`n%TestResult%"
33+
}
34+
35+
Add-MtTestResultDetail -Result $TestResults -GraphObjects $invalidUsers -GraphObjectType Users
36+
}
37+
catch {
38+
$result = $false
39+
Write-Error $_.Exception.Message
40+
}
41+
return $result
42+
}

0 commit comments

Comments
 (0)