Skip to content

Refuse a null non-nullable property in the in-memory store too [patch] - #212

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/208-inmemory-null-property
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/208-inmemory-null-property

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #208

What changed

InMemoryCredentialStore.Save and CredentialCache.AddOrReplace only checked for an unregistered type. A credential like new CredentialWithToken { Token = null! } therefore saved fine in memory, and TryGet handed it back. Every platform store throws ArgumentException for that same credential since #204.

  • New CredentialSerialization.ThrowIfNotSerializable(credential) runs Serialize and zeroes the bytes it gets back. It throws whatever a platform store's save would throw: CredentialStoreException for an unknown type, ArgumentException for a null non-nullable property.
  • AddOrReplace calls it in place of ThrowIfUnknownType, so no store sees the credential before the check. InMemoryCredentialStore.Save calls it too, which covers direct calls to the store.
  • Updated the ArgumentException doc on AddOrReplace: the exception is now thrown whichever store is configured.

Tests

  • AddOrReplaceRejectsANullNonNullablePropertyAndLeavesTheStoreAndCacheUnchanged now runs against both the serializing stub and InMemoryCredentialStore.
  • New: InMemoryStoreSaveRejectsANullNonNullablePropertyAsAPlatformStoreWould, plus a check that a complete credential still saves and round-trips.
  • With the library change reverted, both in-memory cases fail. With it, the full suite passes: 111 tests, 106 passed and 5 skipped. The skipped ones are native-store tests, and this Linux container has no libsecret.

Generated by Claude Code

InMemoryCredentialStore.Save and CredentialCache.AddOrReplace only checked
for an unregistered type, so a credential such as `Token = null!` saved
fine in memory and TryGet handed it back, while every platform store throws
ArgumentException for it. Both now run the same serialization the platform
stores do (zeroing the bytes) before storing anything.

Fixes #208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4nQyg9qMFhK6fYVqQ
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants