Repository navigation
Let consumers register their own Credential subclasses [minor] - #194
Merged
Merged
Conversation
Credential's polymorphic type set was closed: only the three subclasses declared on the base could be serialized, so a subclass defined in a consuming assembly failed on every platform store with a raw NotSupportedException, while InMemoryCredentialStore, which never serializes, accepted it and hid the failure in tests. CredentialSerialization.RegisterDerivedType<T>(discriminator) adds a subclass to the set through a DefaultJsonTypeInfoResolver modifier, rebuilding the options so registrations made after first use still take effect. AddOrReplace now refuses an unregistered subclass with a CredentialStoreException naming the type, for every store, and leaves the cache and the store unchanged. Fixes #171 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017UuQscGFrjteUf9Ui3jWdd
…vedType throws S3928: T is a type argument, not a parameter, so it is not a valid paramName. Also switch the message assertion to Assert.Contains (MSTEST0046). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017UuQscGFrjteUf9Ui3jWdd
|
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.



Fixes #171
What was wrong
Credential's polymorphic type set was closed: only the three[JsonDerivedType]subclasses on the base could be serialized.NotSupportedException.InMemoryCredentialStorenever serializes, so it accepted the same subclass and hid the failure in consumers' tests.Credential.csin this repository.Change
This takes the "open the type set" option from the issue and triage.
CredentialSerialization.RegisterDerivedType<T>(string typeDiscriminator)(new public API) adds a subclass to the set through aDefaultJsonTypeInfoResolvermodifier.ArgumentExceptionfor:AddOrReplacenow refuses an unregistered subclass with aCredentialStoreExceptionnaming the type, before touching the store. The cache and the store are left unchanged. The check sits inCredentialCacherather than in each store, so every store behaves the same,InMemoryCredentialStoreincluded.This is a behaviour change for anyone who relied on the in-memory store accepting unregistered subclasses. That behaviour was the bug, but it is why this is a
[minor]and not a patch. One existing test (RegisterMultipleCredentialFactoriesCreatesCredentialsCorrectly) did exactly that, so it now registers itsAnotherCredentialtype first.Tests
New tests in
CustomCredentialTypeTests:Serialize/Deserializeand throughNativeSecretBuffer.OfCredential/ReadCredential;AddOrReplacewith aCredentialStoreExceptionnaming it, with the cache and store unchanged;Proof that the tests depend on the fix:
AddOrReplaceguard reverted,AddOrReplaceRefusesAnUnregisteredSubclassAndLeavesTheCacheUnchangedandADiscriminatorThatAlreadyNamesAnotherTypeIsRefusedfail.Full suite on Linux/net10.0: 80 passed, 5 skipped (native-store tests, since libsecret is not available in this container), 0 failed.
Generated by Claude Code