Skip to content

Commit 69f727b

Browse files
authored
Merge branch 'dev' into auth-documentation
2 parents 7336586 + 6836d78 commit 69f727b

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/Authentication/Authentication/custom/Find-MgGraphCommand.ps1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,33 @@ Function Find-MgGraphCommand {
9898

9999
$Result = @()
100100
Write-Debug "Received URI: $Uri."
101+
101102
$Uri = GraphUri_RemoveNamespaceFromActionFunction $Uri
102103
$GraphUri = GraphUri_ConvertStringToUri $Uri
103104

104105
# Use API version in URI if -ApiVersion is not provided.
105106
if ([System.String]::IsNullOrWhiteSpace($ApiVersion) -and ($GraphUri.OriginalString -match "(v1.0|beta)\/")) {
106107
$ApiVersion = $Matches[1]
107108
}
109+
110+
108111

109112
if (!$GraphUri.IsAbsoluteUri) {
110113
$GraphUri = GraphUri_ConvertRelativeUriToAbsoluteUri -Uri $GraphUri -ApiVersion $ApiVersion
111114
}
115+
116+
$ContainsMeSegment = $False
117+
$Segment = $GraphUri.Segments
118+
foreach ($s in $Segment) {
119+
if ($s.StartsWith("me")) {
120+
$ContainsMeSegment = $True
121+
break
122+
}
123+
}
124+
if ($ContainsMeSegment) {
125+
$GraphUri = $GraphUri.AbsoluteUri.Replace("/me/", "/users/{id}/")
126+
}
112127
Write-Debug "Resolved URI: $GraphUri."
113-
114128
return $GraphUri
115129
}
116130

@@ -119,7 +133,6 @@ Function Find-MgGraphCommand {
119133
[Parameter(Mandatory = $true, Position = 0)]
120134
[System.Uri]$Uri
121135
)
122-
123136
$Result = @()
124137
$TokenizedUri = GraphUri_TokenizeIds $Uri
125138
Write-Debug "Tokenized URI: $TokenizedUri."

src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ Describe "Find-MgGraphCommand Command" {
138138
$MgCommand.Command | Should -Be @("Get-MgReportSharePointActivityUserCount", "Get-MgBetaReportSharePointActivityUserCount")
139139
} | Should -Not -Throw
140140
}
141+
It 'Should find commands for uri woth /me segments' {
142+
{
143+
$MgCommand = Find-MgGraphCommand -Uri "/me/events/"
144+
$MgCommand | Should -HaveCount 4
145+
$MgCommand.Command | Select-Object -Unique | should -HaveCount 4
146+
$MgCommand.Method | Select-Object -Unique | should -HaveCount 2
147+
$MgCommand.APIVersion | Select-Object -Unique | should -HaveCount 2
148+
$MgCommand.Variants | Select-Object -Unique | should -HaveCount 5
149+
$MgCommand.URI | Select-Object -Unique | Should -Be "/users/{user-id}/events"
150+
$MgCommand.Command | Select-Object -Unique | Should -BeIn @("New-MgUserEvent", "Get-MgUserEvent", "New-MgBetaUserEvent", "Get-MgBetaUserEvent")
151+
} | Should -Not -Throw
152+
}
153+
It 'Should find commands for uri woth /me segments' {
154+
{
155+
$MgCommand = Find-MgGraphCommand -Uri "https://graph.microsoft.com/v1.0/me/events/"
156+
$MgCommand | Should -HaveCount 4
157+
$MgCommand.Command | Select-Object -Unique | should -HaveCount 4
158+
$MgCommand.Method | Select-Object -Unique | should -HaveCount 2
159+
$MgCommand.APIVersion | Select-Object -Unique | should -HaveCount 2
160+
$MgCommand.Variants | Select-Object -Unique | should -HaveCount 5
161+
$MgCommand.URI | Select-Object -Unique | Should -Be "/users/{user-id}/events"
162+
$MgCommand.Command | Select-Object -Unique | Should -BeIn @("New-MgUserEvent", "Get-MgUserEvent", "New-MgBetaUserEvent", "Get-MgBetaUserEvent")
163+
} | Should -Not -Throw
164+
}
141165
}
142166

143167
Context "FindByCommand" {

0 commit comments

Comments
 (0)