using NUnit.Framework; using SVSim.BattleNode.Wire; namespace SVSim.UnitTests.BattleNode.Wire; [TestFixture] public class NodeCryptoTests { [Test] public void EncryptThenDecrypt_RoundTripsArbitraryString() { const string plaintext = "{\"uri\":\"InitNetwork\",\"viewerId\":906243102,\"try\":0,\"cat\":99}"; const string key = "Y2FmZWJhYmU3ZmY3ZmY3ZmY3ZmY3ZmY3"; // 32 chars var encrypted = NodeCrypto.EncryptForNode(plaintext, key); var decrypted = NodeCrypto.DecryptForNode(encrypted); Assert.That(decrypted, Is.EqualTo(plaintext)); } [Test] public void GenerateKey_WithDeterministicSource_ProducesStable32CharOutput() { var seq = 0; string key = NodeCrypto.GenerateKey(() => seq++ % 16); Assert.That(key.Length, Is.EqualTo(32)); // Two calls with the same source produce the same output. seq = 0; Assert.That(NodeCrypto.GenerateKey(() => seq++ % 16), Is.EqualTo(key)); } [Test] public void EncryptForNode_NonStandardKeyLength_Throws() { Assert.Throws(() => NodeCrypto.EncryptForNode("x", "tooshort")); } [Test] public void DecryptForNode_TooShortInput_Throws() { Assert.Throws(() => NodeCrypto.DecryptForNode("tooshort")); } }