Repository: microsoft/garnet
File: test/Garnet.test/RespTests.cs (C#)

Code before:
            ClassicAssert.AreEqual(ResultType.Array, result.Resp3Type);
            var resultDict = result.ToDictionary();
            ClassicAssert.IsNotNull(resultDict);
            ClassicAssert.AreEqual(2, (int)resultDict["proto"]);
            ClassicAssert.AreEqual("master", (string)resultDict["role"]);

            // Test "HELLO 3"
            result = db.Execute("HELLO", "3");

            ClassicAssert.IsNotNull(result);
            ClassicAssert.AreEqual(ResultType.Array, result.Resp2Type);
            ClassicAssert.AreEqual(ResultType.Map, result.Resp3Type);
            resultDict = result.ToDictionary();
            ClassicAssert.IsNotNull(resultDict);
            ClassicAssert.AreEqual(3, (int)resultDict["proto"]);
            ClassicAssert.AreEqual("master", (string)resultDict["role"]);
        }

        [Test]
        public void HelloTest2()
        {
            using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(protocol: RedisProtocol.Resp2));
            var db = redis.GetDatabase(0);

            // Failed HELLO should not change current protocol
            try
            {
                db.Execute("HELLO", "3", "AUTH", "NX", "NX");
                ClassicAssert.Fail("Should never reach this line, user does not exist");
            }
            catch
            {
                // Passthrough
            }
            var result = db.Execute("HELLO");

            ClassicAssert.IsNotNull(result);
            ClassicAssert.AreEqual(ResultType.Array, result.Resp2Type);
            ClassicAssert.AreEqual(ResultType.Array, result.Resp3Type);
            var resultDict = result.ToDictionary();
            ClassicAssert.IsNotNull(resultDict);

            // Should remain 2 since protocol change failed
            ClassicAssert.AreEqual(2, (int)resultDict["proto"]);
        }

        [Test]
        [TestCase([2, "$-1\r\n", "$1\r\n", "*4", '*'], Description = "RESP2 output")]
        [TestCase([3, "_\r\n", ",", "%2", '~'], Description = "RESP3 output")]
        public async Task RespOutputTests(byte respVersion, string expectedResponse, string doublePrefix, string mapPrefix, char setPrefix)
        {

Review comment (security):
Cleaner way to do this is with ```Assert.Throws<RedisServerException>(() => db.Execute("HELLO", "3", "AUTH", "NX", "NX"), <expected-error>)```

Code after:
            ClassicAssert.AreEqual(ResultType.Array, result.Resp3Type);
            var resultDict = result.ToDictionary();
            ClassicAssert.IsNotNull(resultDict);
            ClassicAssert.AreEqual(2, (int)resultDict["proto"]);
            ClassicAssert.AreEqual("master", (string)resultDict["role"]);

            // Test "HELLO 3"
            result = db.Execute("HELLO", "3");

            ClassicAssert.IsNotNull(result);
            ClassicAssert.AreEqual(ResultType.Array, result.Resp2Type);
            ClassicAssert.AreEqual(ResultType.Map, result.Resp3Type);
            resultDict = result.ToDictionary();
            ClassicAssert.IsNotNull(resultDict);
            ClassicAssert.AreEqual(3, (int)resultDict["proto"]);
            ClassicAssert.AreEqual("master", (string)resultDict["role"]);
        }

        [Test]
        public void HelloAuthErrorTest()
        {
            using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(protocol: RedisProtocol.Resp2));
            var db = redis.GetDatabase(0);

            // Failed HELLO should not change current protocol
            Assert.Throws<RedisServerException>(() => db.Execute("HELLO", "3", "AUTH", "NX", "NX"),
                           Encoding.ASCII.GetString(CmdStrings.RESP_WRONGPASS_INVALID_USERNAME_PASSWORD));
            var result = db.Execute("HELLO");

            ClassicAssert.IsNotNull(result);
            ClassicAssert.AreEqual(ResultType.Array, result.Resp2Type);
            ClassicAssert.AreEqual(ResultType.Array, result.Resp3Type);
            var resultDict = result.ToDictionary();
            ClassicAssert.IsNotNull(resultDict);

            // Should remain 2 since protocol change failed
            ClassicAssert.AreEqual(2, (int)resultDict["proto"]);
        }

        [Test]
        [TestCase([2, "$-1\r\n", "$1\r\n", "*4", '*'], Description = "RESP2 output")]
        [TestCase([3, "_\r\n", ",", "%2", '~'], Description = "RESP3 output")]
        public async Task RespOutputTests(byte respVersion, string expectedResponse, string doublePrefix, string mapPrefix, char setPrefix)
        {
            using var c = TestUtils.GetGarnetClientSession(raw: true);
            c.Connect();

            var response = await c.ExecuteAsync("HELLO", respVersion.ToString());

            response = await c.ExecuteAsync("GET", "nx");
            ClassicAssert.AreEqual(expectedResponse, response);