Skip to content

Fix mismatched Microsoft.Graph modules by pinning module versions #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion linux/powershell/setupPowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ try {
PowerShellGet\Install-Module -Name Microsoft.Graph.Identity.DirectoryManagement @prodAllUsers
PowerShellGet\Install-Module -Name Microsoft.Graph.Identity.Governance @prodAllUsers
PowerShellGet\Install-Module -Name Microsoft.Graph.Identity.SignIns @prodAllUsers
PowerShellGet\Install-Module -Name Microsoft.Graph.Applications @prodAllUsers
PowerShellGet\Install-Module -Name Microsoft.Graph.Applications -RequiredVersion 2.28.0 @prodAllUsers

}
else {
Expand Down
21 changes: 21 additions & 0 deletions test_graph_modules.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Import-Module Microsoft.Graph.Applications -Force -ErrorAction Stop
Import-Module Microsoft.Graph.Groups -Force -ErrorAction Stop

# Verify modules were loaded successfully
$appsModule = Get-Module Microsoft.Graph.Applications
$groupsModule = Get-Module Microsoft.Graph.Groups
$authModule = Get-Module Microsoft.Graph.Authentication

Write-Host "Microsoft.Graph.Authentication version: $($authModule.Version.ToString())"
Write-Host "Microsoft.Graph.Applications version: $($appsModule.Version.ToString())"
Write-Host "Microsoft.Graph.Groups version: $($groupsModule.Version.ToString())"

# This is what we want to check in our test
if ($appsModule.Version.ToString() -eq $authModule.Version.ToString() -and
$groupsModule.Version.ToString() -eq $authModule.Version.ToString()) {
Write-Host "Test passed - all modules have the same version"
exit 0
} else {
Write-Host "Test failed - module versions don't match"
exit 1
}
52 changes: 49 additions & 3 deletions tests/PSinLinuxCloudShellImage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,39 @@ Describe "PowerShell Modules" {

}

It "Microsoft.Graph modules can be imported in any order" {
# This test verifies that Microsoft.Graph.Applications and Microsoft.Graph.Groups
# can be imported in any order without version conflicts
try {
Import-Module Microsoft.Graph.Applications -Force -ErrorAction Stop
Import-Module Microsoft.Graph.Groups -Force -ErrorAction Stop

# Verify modules were loaded successfully
$appsModule = Get-Module Microsoft.Graph.Applications
$groupsModule = Get-Module Microsoft.Graph.Groups
$authModule = Get-Module Microsoft.Graph.Authentication

$appsModule | Should -Not -BeNullOrEmpty
$groupsModule | Should -Not -BeNullOrEmpty
$authModule | Should -Not -BeNullOrEmpty

# Verify all modules are using the same version of Microsoft.Graph.Authentication
$authVersion = $authModule.Version.ToString()
$appsVersion = $appsModule.Version.ToString()
$groupsVersion = $groupsModule.Version.ToString()

Write-Host "Microsoft.Graph.Authentication version: $authVersion"
Write-Host "Microsoft.Graph.Applications version: $appsVersion"
Write-Host "Microsoft.Graph.Groups version: $groupsVersion"

$appsVersion | Should -Be $authVersion -Because "All Microsoft.Graph modules should use the same version"
$groupsVersion | Should -Be $authVersion -Because "All Microsoft.Graph modules should use the same version"
}
catch {
$_.Exception.Message | Should -BeNullOrEmpty -Because "No exceptions should be thrown when importing Microsoft.Graph modules"
}
}

$importModuleTestCases = @(
@{ ModuleName = "Microsoft.PowerShell.Management" }
@{ ModuleName = "PSCloudShellUtility" }
Expand All @@ -214,17 +247,30 @@ Describe "PowerShell Modules" {
@{ ModuleName = "MicrosoftTeams" }
@{ ModuleName = "Microsoft.PowerShell.SecretManagement" }
@{ ModuleName = "Microsoft.PowerShell.SecretStore" }
@{ ModuleName = "Microsoft.Graph.Authentication" }
@{ ModuleName = "Microsoft.Graph.Applications" }
@{ ModuleName = "Microsoft.Graph.Groups" }
)

It "Import-Module test for <ModuleName>" -TestCases $importModuleTestCases {

param($ModuleName)
try {
Import-Module $ModuleName -Force -ErrorAction Stop -ErrorVariable ev
$ev | Should -BeNullOrEmpty
Import-Module $ModuleName -Force -ErrorAction Stop
$module = Get-Module $ModuleName
$module | Should -Not -BeNullOrEmpty

# Verify Microsoft.Graph modules have the correct version
if ($ModuleName -like "Microsoft.Graph*") {
$authModule = Get-Module "Microsoft.Graph.Authentication"
if ($authModule) {
$authVersion = $authModule.Version.ToString()
$module.Version.ToString() | Should -Be $authVersion -Because "All Microsoft.Graph modules should use the same version"
}
}
}
catch {
"Unexpected exception thrown: $_" | Should -BeNullOrEmpty
$_.Exception.Message | Should -BeNullOrEmpty -Because "No exceptions should be thrown when importing $ModuleName"
}

}
Expand Down