Files
natsnet/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/Auth/TpmKeyProviderTests.cs
Joseph Doherty 88b1391ef0 feat: port session 07 — Protocol Parser, Auth extras (TPM/certidp/certstore), Internal utilities & data structures
Session 07 scope (5 features, 17 tests, ~1165 Go LOC):
- Protocol/ParserTypes.cs: ParserState enum (79 states), PublishArgument, ParseContext
- Protocol/IProtocolHandler.cs: handler interface decoupling parser from client
- Protocol/ProtocolParser.cs: Parse(), ProtoSnippet(), OverMaxControlLineLimit(),
  ProcessPub/HeaderPub/RoutedMsgArgs/RoutedHeaderMsgArgs, ClonePubArg(), GetHeader()
- tests/Protocol/ProtocolParserTests.cs: 17 tests via TestProtocolHandler stub

Auth extras from session 06 (committed separately):
- Auth/TpmKeyProvider.cs, Auth/CertificateIdentityProvider/, Auth/CertificateStore/

Internal utilities & data structures (session 06 overflow):
- Internal/AccessTimeService.cs, ElasticPointer.cs, SystemMemory.cs, ProcessStatsProvider.cs
- Internal/DataStructures/GenericSublist.cs, HashWheel.cs
- Internal/DataStructures/SubjectTree.cs, SubjectTreeNode.cs, SubjectTreeParts.cs

All 461 tests pass (460 unit + 1 integration). DB updated for features 2588-2592 and tests 2598-2614.
2026-02-26 13:16:56 -05:00

43 lines
1.3 KiB
C#

using System.Runtime.InteropServices;
using Shouldly;
using ZB.MOM.NatsNet.Server.Auth;
namespace ZB.MOM.NatsNet.Server.Tests.Auth;
public sealed class TpmKeyProviderTests
{
private static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
[Fact]
public void LoadJetStreamEncryptionKeyFromTpm_NonWindows_ThrowsPlatformNotSupportedException()
{
if (IsWindows)
return; // This test is for non-Windows only
var ex = Should.Throw<PlatformNotSupportedException>(() =>
TpmKeyProvider.LoadJetStreamEncryptionKeyFromTpm("", "keys.json", "password", 22));
ex.Message.ShouldContain("TPM");
}
[Fact]
public void LoadJetStreamEncryptionKeyFromTpm_Create_ShouldSucceed()
{
if (!IsWindows)
return; // Requires real TPM hardware on Windows
var tempFile = Path.Combine(Path.GetTempPath(), $"jskeys_{Guid.NewGuid():N}.json");
try
{
if (File.Exists(tempFile)) File.Delete(tempFile);
var key = TpmKeyProvider.LoadJetStreamEncryptionKeyFromTpm("", tempFile, "password", 22);
key.ShouldNotBeNullOrEmpty();
}
finally
{
if (File.Exists(tempFile)) File.Delete(tempFile);
}
}
}