Skip to content

Add test coverage for -FollowRelLink authorization - #27863

Open
Chris Peterson (chris-peterson) wants to merge 2 commits into
PowerShell:masterfrom
chris-peterson:test-followrellink-authorization
Open

Add test coverage for -FollowRelLink authorization#27863
Chris Peterson (chris-peterson) wants to merge 2 commits into
PowerShell:masterfrom
chris-peterson:test-followrellink-authorization

Conversation

@chris-peterson

@chris-peterson Chris Peterson (chris-peterson) commented Aug 18, 2026

Copy link
Copy Markdown

PR Summary

No test pins what -FollowRelLink does with the caller's Authorization header.

-FollowRelLink exists so the web cmdlets can page an API that advertises its next page in a Link header. GitHub's and GitLab's paginated endpoints are the canonical case, and those APIs want the caller's credentials on every page, not just the first. Nothing asserts that today, so a change at the rel-link call site can alter it with the suite still green.

This adds one Pester case: a three-page same-origin walk checking the header reaches every page. Test-only, no product change.

PR Context

Per #27861, on the 7.4.19, 7.5.10 and 7.6.5 servicing releases each followed link goes through the redirect path, which strips the header, so -FollowRelLink cannot page an authenticated API. Against a server that permits anonymous reads the follows still return HTTP 200, and the caller gets a visibility-filtered result set with no error, no warning, and no non-zero status. It reached us as a GitLab group of 43 projects reporting 39.

master reaches that call site through GetRequest(uri), which takes no isRedirect argument, so the header survives and this case passes as written.

Verified in both directions on macOS arm64:

Build WebCmdlets.Tests.ps1
master as-is 591 passed, 0 failed, 17 skipped, 36 pending
master with the servicing strip applied locally 590 passed, 1 failed, and the failure is this case

Review guide

WebCmdlets.Tests.ps1 L3038 is the whole change: one It block beside the existing -FollowRelLink cases, driving the WebListener Link endpoint the neighbouring cases already use. No test-tool support was added.

PR Checklist

No test pins what -FollowRelLink does with the caller's Authorization
header, so a change at the rel-link call site can alter it unnoticed.

On the 7.4.19, 7.5.10 and 7.6.5 servicing releases each followed link
goes through the redirect path, which strips the header, leaving
-FollowRelLink unable to page an authenticated API. Against a server
that permits anonymous reads the follows still return 200, so the
caller gets a visibility-filtered result set and no error (PowerShell#27861).

master reaches that call site through GetRequest(uri) and keeps the
header, so this passes as written and fails if the strip arrives here.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@chris-peterson
Chris Peterson (chris-peterson) marked this pull request as ready for review August 18, 2026 19:26
Copilot AI lite review requested due to automatic review settings August 18, 2026 19:26
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a regression test to ensure Invoke-RestMethod -FollowRelLink preserves the Authorization header when following relation links within the same origin, preventing silent authentication loss during paging.

Changes:

  • Added a new Invoke-RestMethod test covering header retention across rel-link pagination.
  • Validates no errors, expected page count, and consistent Authorization header on all followed requests.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 Outdated
Comment thread test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 Outdated
Addresses review feedback on WebCmdlets.Tests.ps1:3049. The four other
per-page assertions in the rel-link tests iterate with ForEach-Object;
three indexed assertions were the only ones of their kind in the file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants