Repository navigation
Disable fetch delegate on $ref feature so external references are not allowed in Test-Json schema - #28214
Closed
Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
Closed
Disable fetch delegate on $ref feature so external references are not allowed in Test-Json schema#28214Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
Test-Json schema#28214Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
Conversation
… allowed in Test-Json schema (#201)
Aditya Patwardhan (adityapatwardhan)
requested a review
from a team
as a code owner
October 14, 2026 23:01
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
HTTP tests need controlled endpoints, and reference validation needs negative-instance coverage.
2 open findings
What changed in this PR
Makes external schema fetching opt-in for Test-Json, while preserving internal references and isolating settings per invocation.
Changes:
- Adds
-FetchExternalReferenceand invocation-specific evaluation options. - Adds unresolved-reference diagnostics.
- Expands reference tests and schema fixtures.
| File | Description |
|---|---|
| test/powershell/Modules/Microsoft.PowerShell.Utility/Test-Json.Tests.ps1 | Tests reference handling and invocation isolation. |
| test/powershell/Modules/Microsoft.PowerShell.Utility/assets/valid_schema.json | Adds a reference-free schema. |
| test/powershell/Modules/Microsoft.PowerShell.Utility/assets/valid_schema_uri_references_external.json | Adds an HTTP reference fixture. |
| test/powershell/Modules/Microsoft.PowerShell.Utility/assets/valid_schema_references_internal.json | Adds internal reference coverage. |
| test/powershell/Modules/Microsoft.PowerShell.Utility/assets/valid_schema_references_external.json | Adds external file references. |
| test/powershell/Modules/Microsoft.PowerShell.Utility/assets/valid_schema_definitions_external.json | Supplies external schema definitions. |
| test/powershell/Modules/Microsoft.PowerShell.Utility/assets/invalid_schema.json | Makes schema invalidity independent of references. |
| src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx | Adds unresolved-reference guidance. |
| src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs | Implements opt-in fetching and error handling. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+273
to
+275
| It "Json is valid, with FetchExternalReference parameter, against a schema from file with external file reference" { | ||
| Test-Json -Json $validJson -SchemaFile $validSchemaWithExternalFileRefJsonPath -FetchExternalReference | Should -BeTrue | ||
| } |
| } | ||
|
|
||
| It "Json is valid but unresolvable, with FetchExternalReference parameter, against a schema with external URI reference" { | ||
| Test-Json -Json $validJson -SchemaFile $validSchemaWithExternalUriRefJsonPath -FetchExternalReference -ErrorVariable ErrorVar -ErrorAction SilentlyContinue | Should -BeFalse |
Collaborator
|
Dup #28205 |
5 tasks done
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR Summary
This pull request enhances the
Test-JsonPowerShell cmdlet by adding support for resolving external JSON schema references, improving error handling, and expanding test coverage. The main changes introduce a new parameter to control external reference fetching, ensure per-invocation isolation of this behavior, and provide clearer error messages and robust tests for various schema reference scenarios.New functionality and parameterization:
-FetchExternalReferenceswitch parameter toTest-Json, allowing users to opt-in to automatically resolve external (file or URI) references in JSON schemas. By default, external references are not resolved, improving security and predictability.EvaluationOptions, ensuring that the external reference fetching behavior is isolated to each cmdlet invocation and does not affect subsequent calls. [1] [2] [3]Error handling improvements:
UnresolvedJsonSchemaRef) when external references cannot be resolved and the new parameter is not set. [1] [2]Testing and validation:
Test-Json, including scenarios for schemas with local references, external file references, and external URI references, both with and without the new parameter. Tests also verify that setting-FetchExternalReferencedoes not persist across invocations. [1] [2]PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header