Skip to content

{Tests} Add validation error unit tests for Managed Identity - #1466

Open
MaddyMicrosoft wants to merge 3 commits into
mainfrom
test/managed-identity-error-unit-tests
Open

MaddyMicrosoft wants to merge 3 commits into
mainfrom
test/managed-identity-error-unit-tests

Conversation

@MaddyMicrosoft

Copy link
Copy Markdown
Member

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=VALUE and 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:

  • They are unit tests only: no CLI parsing, no scenario host, no network.
  • Each error test has one assert, on the exact message. The fake HTTP pipeline throws on any unexpected request, so a passing test also proves the validation ran before any network call. For --force-string, which is only checked after the existing resource is fetched, the pipeline allows GET and fails on any write.
  • Test names follow Method_Scenario_ExpectedResult.
  • The five loose error tests in IdentityExtensionTests are replaced by these. Every case they covered is still covered, now with exact messages.

Other changes:

  • Adds InternalsVisibleTo for Cli.Tests in Extensions.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

dotnet test tests/Cli.Tests/Cli.Tests.csproj --filter "FullyQualifiedName\~Identity|FullyQualifiedName\~FederatedCredential"
dotnet test tests/Cli.Tests/Cli.Tests.csproj -c Release --filter "FullyQualifiedName\~Identity|FullyQualifiedName\~FederatedCredential"

Results: 155/155 in both Debug and Release.


  • The PR title starts with [Component Name] for customer-facing changes or {Component Name} for non-customer-facing changes, and does not end with trailing punctuation or spaces.
  • Customer-facing changes include a useful release note in the PR title or the History Notes section.
  • I added or updated tests for behavior changes.
  • I updated documentation when behavior, setup, support, or security guidance changed.

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>
@MaddyMicrosoft
MaddyMicrosoft marked this pull request as ready for review November 16, 2026 00:25
Copilot AI balanced review requested due to automatic review settings November 16, 2026 00:25

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.

🟡 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.Tests in 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

MaddyMicrosoft and others added 2 commits November 16, 2026 03:27
… wrong segment

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 03:32

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.

🟢 Approval recommended

No active review issues were identified in the Managed Identity validation test changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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