Skip to content

Add 63 unit tests for parsing/logic edge cases in IdToken, WsTrust, AuthorizationResult, ThrottlingCache, Base64Url#5907

Open
gladjohn wants to merge 7 commits intomainfrom
gladjohn/code_coverage
Open

Add 63 unit tests for parsing/logic edge cases in IdToken, WsTrust, AuthorizationResult, ThrottlingCache, Base64Url#5907
gladjohn wants to merge 7 commits intomainfrom
gladjohn/code_coverage

Conversation

@gladjohn
Copy link
Copy Markdown
Contributor

@gladjohn gladjohn commented Apr 3, 2026

Summary

Adds 63 unit tests across 5 test files targeting real parsing and logic edge cases in Microsoft.Identity.Client. Each test validates specific behavioral contracts that would catch actual regressions.

Also marks ConcurrentHashSet<T> (copied from i3arnon/ConcurrentHashSet) as [ExcludeFromCodeCoverage] since it's external code that shouldn't affect MSAL coverage metrics.

Test Files

File Tests Target Key Scenarios
WsTrustResponseExtendedTests 13 WsTrustResponse SOAP fault parsing, missing body/fault fallback, WsTrust13 vs 2005, SAML1 preference, skipped responses
AuthorizationResultExtendedTests 18 AuthorizationResult Null/empty URI, error subcodes, msauth:// scheme, FromPostData, FromStatus factory
IdTokenExtendedTests 11 IdToken Null/empty/malformed JWT, claim mapping, GetUniqueId fallback (oid→sub), missing issuer, ClaimsPrincipal
Base64UrlHelpersExtendedTests 13 Base64UrlHelpers Null handling, URL-safe char validation, padding variants, invalid input, padded base64 decoding
ThrottlingCacheExtendedTests 8 ThrottlingCache Clear/IsEmpty, newer entry replacement, older-doesn't-replace-newer, cleanup of expired entries

Production Code Change

  • ConcurrentHashSet.cs: Added [ExcludeFromCodeCoverage] attribute (class is copied from external OSS repo)

Validation

  • ✅ Build: 0 errors, 0 warnings
  • ✅ Tests: All 63 new tests pass on both net48 and net8.0

@gladjohn gladjohn requested a review from a team as a code owner April 3, 2026 20:18
Copilot AI review requested due to automatic review settings April 3, 2026 20:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new set of unit tests to increase coverage for key MSAL.NET utility and parsing components in Microsoft.Identity.Client, without changing production code.

Changes:

  • Added extended unit tests for AuthorizationResult, IdToken, WsTrustResponse, ThrottlingCache, TokenCacheNotificationArgs, TraceTelemetryConfig, Base64UrlHelpers, and ConcurrentHashSet<T>.
  • Expanded edge-case coverage (null/empty inputs, parsing fallbacks, constructor overloads, cache cleanup/expiry behavior, and concurrency basics).
  • Introduced new test files across WebUI, Core, Util, Throttling, Cache, and Telemetry test areas.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/Microsoft.Identity.Test.Unit/WebUITests/AuthorizationResultExtendedTests.cs Adds coverage for AuthorizationResult creation from URI/post body/status paths.
tests/Microsoft.Identity.Test.Unit/UtilTests/ConcurrentHashSetTests.cs Adds functional and basic concurrency tests for ConcurrentHashSet<T>.
tests/Microsoft.Identity.Test.Unit/UtilTests/Base64UrlHelpersExtendedTests.cs Adds coverage for Base64Url encode/decode edge cases and round trips.
tests/Microsoft.Identity.Test.Unit/Throttling/ThrottlingCacheExtendedTests.cs Adds coverage for ThrottlingCache clear/empty/update/cleanup behavior.
tests/Microsoft.Identity.Test.Unit/TelemetryTests/TraceTelemetryConfigTests.cs Adds coverage for default TraceTelemetryConfig values (obsolete API).
tests/Microsoft.Identity.Test.Unit/CoreTests/WsTrustTests/WsTrustResponseExtendedTests.cs Adds coverage for SOAP fault parsing and WsTrust response parsing behavior.
tests/Microsoft.Identity.Test.Unit/CoreTests/IdTokenExtendedTests.cs Adds coverage for IdToken.Parse error paths and claim mapping/fallbacks.
tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheNotificationArgsExtendedTests.cs Adds coverage for TokenCacheNotificationArgs constructor overloads and defaults.

Comment thread tests/Microsoft.Identity.Test.Unit/UtilTests/Base64UrlHelpersExtendedTests.cs Outdated
Comment thread tests/Microsoft.Identity.Test.Unit/UtilTests/Base64UrlHelpersExtendedTests.cs Outdated
Comment thread tests/Microsoft.Identity.Test.Unit/Throttling/ThrottlingCacheExtendedTests.cs Outdated
Comment thread tests/Microsoft.Identity.Test.Unit/CoreTests/IdTokenExtendedTests.cs Outdated
Comment thread tests/Microsoft.Identity.Test.Unit/CoreTests/IdTokenExtendedTests.cs Outdated
Copilot AI review requested due to automatic review settings April 22, 2026 12:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread tests/Microsoft.Identity.Test.Unit/UtilTests/Base64UrlHelpersExtendedTests.cs Outdated
Comment thread tests/Microsoft.Identity.Test.Unit/Throttling/ThrottlingCacheExtendedTests.cs Outdated
Comment thread tests/Microsoft.Identity.Test.Unit/UtilTests/Base64UrlHelpersExtendedTests.cs Outdated
Copy link
Copy Markdown
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

I don't think this is a good idea. It artificially increases code coverage, but do you know they capture the correct behavior?

Comment thread tests/Microsoft.Identity.Test.Unit/UtilTests/ConcurrentHashSetTests.cs Outdated
Copilot AI review requested due to automatic review settings April 26, 2026 13:34
@gladjohn
Copy link
Copy Markdown
Contributor Author

I don't think this is a good idea. It artificially increases code coverage, but do you know they capture the correct behavior?

Fair point. Dropped ~55 tests that artificially inflated coverage (ConcurrentHashSet, TokenCacheNotificationArgs constructors, TraceTelemetryConfig constants, redundant Base64Url round-trips). The remaining ~63 tests all validate real parsing/logic: JWT claim mapping and fallback, SOAP fault parsing, authorization URI handling, and throttling cache semantics. Also added [ExcludeFromCodeCoverage] to ConcurrentHashSet since it's copied from i3arnon/ConcurrentHashSet.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Comment thread tests/Microsoft.Identity.Test.Unit/WebUITests/AuthorizationResultExtendedTests.cs Outdated
Comment thread tests/Microsoft.Identity.Test.Unit/UtilTests/Base64UrlHelpersExtendedTests.cs Outdated
Comment thread src/client/Microsoft.Identity.Client/Utils/ConcurrentHashSet.cs
@gladjohn gladjohn changed the title Adds 119 unit tests to improve code coverage (+1.62% line, +2.18% branch) Add 63 unit tests for parsing/logic edge cases in IdToken, WsTrust, AuthorizationResult, ThrottlingCache, Base64Url Apr 28, 2026
gladjohn and others added 6 commits April 28, 2026 21:58
Coverage improvements for Microsoft.Identity.Client:
- Line coverage: 82.58% -> 84.20% (+1.62%, +387 lines)
- Branch coverage: 72.91% -> 75.09% (+2.18%, +128 branches)

New test files:
- ConcurrentHashSetTests: comprehensive tests for thread-safe collection
- Base64UrlHelpersExtendedTests: edge cases for encoding/decoding
- IdTokenExtendedTests: null/empty/malformed JWT, claim mapping
- WsTrustResponseExtendedTests: SOAP fault parsing, SAML selection
- AuthorizationResultExtendedTests: URI/PostData parsing edge cases
- ThrottlingCacheExtendedTests: cleanup, clear, miss paths
- TokenCacheNotificationArgsExtendedTests: constructor overloads
- TraceTelemetryConfigTests: basic config properties

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix Assert.DoesNotContain parameter order in Base64UrlHelpersExtendedTests
- Replace Thread.Sleep with deterministic ThrottlingCacheEntry 3-arg ctor
- Fix AddAndCleanup_SameKey_KeepsOlderIfNewer to actually test the scenario
- Use cleanup interval of 0ms instead of Thread.Sleep for cleanup test

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ption assertion

- Merge Parse_SingleSegment_ThrowsMsalClientException and
  Parse_SingleSegment_HasCorrectErrorCode into a single test that
  verifies both the exception type and error code via Assert.Throws
- Replace weak Parse_InvalidBase64Payload_Throws (caught both
  MsalClientException and FormatException) with
  Parse_InvalidBase64Payload_ThrowsFormatException that asserts the
  specific exception type

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drop ~55 tests that artificially inflate coverage without validating behavior:
- Remove ConcurrentHashSetTests.cs (tests for copied OSS class)
- Remove TokenCacheNotificationArgsExtendedTests.cs (constructor/property tests)
- Remove TraceTelemetryConfigTests.cs (constants on obsolete class)
- Remove 9 redundant Base64Url round-trip tests

Fix remaining ~63 tests that verify real parsing/logic:
- ThrottlingCache: use negative cleanup interval for deterministic test
- Base64Url: remove unnecessary IEnumerable cast in Assert.HasCount
- Base64Url: test actual padded base64 input instead of re-encoding

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Class is copied from i3arnon/ConcurrentHashSet and should not
contribute to MSAL coverage metrics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 28, 2026 20:58
@bgavrilMS bgavrilMS force-pushed the gladjohn/code_coverage branch from 4312219 to fbca87b Compare April 28, 2026 20:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

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.

4 participants