Repository navigation
{Tests} Add validation error unit tests for Managed Identity - #1466
Open
MaddyMicrosoft wants to merge 3 commits into
Open
MaddyMicrosoft wants to merge 3 commits into
MaddyMicrosoft wants to merge 3 commits into
Conversation
Add test classes for the shared validators (ManagedIdentityResolver, IdentityCliArgumentParser, FederatedCredentialValidator) covering every input case with exact messages, and one test per validator call in each Managed Identity orchestrator test file, plus the --force-string checks. The fake pipeline throws on any unexpected request, so each test keeps a single message assert while proving validation runs first. The old loose error tests in IdentityExtensionTests are replaced by these. Add InternalsVisibleTo for Cli.Tests (same pattern as other extensions) so the internal validators can be tested directly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The resource-ID rejection tests combine invalid fields and lack independent segment cases, allowing skipped validation checks to go undetected.
1 open issue
What changed in this PR
Adds offline unit tests for Managed Identity validation, locking in extension-defined error messages and checking that invalid inputs fail before unexpected HTTP requests. No product behavior changes are introduced.
Changes:
- Adds validator and orchestrator tests for identity addressing, tags, resource restrictions, claims expressions, and
--force-string. - Replaces five existing error tests with focused tests and shared HTTP test helpers.
- Enables internal validator access for
Cli.Testsin Debug and Release.
| File | Description |
|---|---|
| tests/Cli.Tests/UpdateIdentityProcessor_OrchestratorTests.cs | Tests identity update validation errors. |
| tests/Cli.Tests/UpdateFederatedCredentialProcessor_OrchestratorTests.cs | Tests claims-expression and force-string update errors. |
| tests/Cli.Tests/ShowIdentityProcessor_OrchestratorTests.cs | Tests missing addresses and invalid identity IDs. |
| tests/Cli.Tests/ManagedIdentityResolverTests.cs | Tests address validation and resource-ID parsing. |
| tests/Cli.Tests/IdentityProcessorTestHelpers.cs | Provides shared processor setup and restrictive HTTP fakes. |
| tests/Cli.Tests/IdentityExtensionTests.cs | Removes five superseded error tests. |
| tests/Cli.Tests/IdentityCliArgumentParserTests.cs | Tests tag and resource-restriction parsing. |
| tests/Cli.Tests/FederatedCredentialValidatorTests.cs | Tests paired claims-expression inputs. |
| tests/Cli.Tests/DeleteIdentityProcessor_OrchestratorTests.cs | Tests identity deletion address errors. |
| tests/Cli.Tests/CreateIdentityProcessor_OrchestratorTests.cs | Tests invalid creation tags and restriction JSON. |
| tests/Cli.Tests/CreateFederatedCredentialProcessor_OrchestratorTests.cs | Tests incomplete claims-expression input during creation. |
| src/Extensions/ManagedServiceIdentity/Extensions.ManagedServiceIdentity.csproj | Grants internal access to the test assembly. |
Review effort: Balanced
… wrong segment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
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.

Related command
az identity create,az identity show,az identity update,az identity delete,az identity federated-credential create,az identity federated-credential update(and the matching PowerShell cmdlets)Description
Adds unit tests that lock in the exact user-facing error messages produced by input validation in the Managed Identity extension. If the core argument parser, the engine, or the Managed Identity orchestrators change in a way that alters or skips one of these errors (for example during the upcoming parameter-set work), a test will now fail.
Validator classes, each with its own test class covering every input case (blank, null, each rejection reason, and inputs that are accepted):
ManagedIdentityResolverTests: missing or blank--name/--resource-group, empty--ids, malformed or wrong-provider resource IDs, and valid IDs including mixed casing and surrounding whitespace or slashes.IdentityCliArgumentParserTests: invalid tags (missing=, empty key, empty JSON key),KEY=VALUEand JSON tags, and resource restrictions as JSON, a comma list, or invalid JSON.FederatedCredentialValidatorTests: claims matching expression version and value supplied without each other, and both or neither supplied.Orchestrators, each with one test per validator it calls plus its own rules:
Show/Delete/UpdateIdentityProcessor_OrchestratorTests: missing name and resource group, invalid resource ID. Update also covers invalid tags, invalid resource-restriction JSON, and--force-string.CreateIdentityProcessor_OrchestratorTests: invalid tags, invalid resource-restriction JSON.Create/UpdateFederatedCredentialProcessor_OrchestratorTests: claims matching expression version without a value. Update also covers--force-string.How the tests work:
--force-string, which is only checked after the existing resource is fetched, the pipeline allows GET and fails on any write.Method_Scenario_ExpectedResult.IdentityExtensionTestsare replaced by these. Every case they covered is still covered, now with exact messages.Other changes:
InternalsVisibleToforCli.TestsinExtensions.ManagedServiceIdentity.csproj, using the same keyed Release / unkeyed Debug pattern as the other extensions, so the internal validators can be tested directly. No product behaviour change.Testing Guide
Results: 155/155 in both Debug and Release.
[Component Name]for customer-facing changes or{Component Name}for non-customer-facing changes, and does not end with trailing punctuation or spaces.