// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using MQTTnet.Extensions.Socks5; namespace MQTTnet.Tests.Extensions.Socks5; [TestClass] public sealed class Socks5ProxyOptionsValidation_Tests { [TestMethod] public void Builder_Build_Without_Host_Throws() { var builder = new Socks5ProxyOptionsBuilder(); Assert.ThrowsExactly(() => builder.Build()); } [TestMethod] public void Builder_Build_With_Invalid_Port_Throws() { var builder = new Socks5ProxyOptionsBuilder() .WithHost("127.0.0.1") .WithPort(0); Assert.ThrowsExactly(() => builder.Build()); } [TestMethod] public void Builder_Build_With_NonPositive_HandshakeTimeout_Throws() { var builder = new Socks5ProxyOptionsBuilder() .WithHost("127.0.0.1") .WithHandshakeTimeout(TimeSpan.Zero); Assert.ThrowsExactly(() => builder.Build()); } [TestMethod] public void Builder_Build_With_Password_But_Without_Username_Throws() { var builder = new Socks5ProxyOptionsBuilder() .WithHost("127.0.0.1") .WithCredentials(null, new byte[] { 0x01, 0x02 }); Assert.ThrowsExactly(() => builder.Build()); } [TestMethod] public void Builder_Build_With_Username_But_Without_Password_Throws() { var builder = new Socks5ProxyOptionsBuilder() .WithHost("127.0.0.1") .WithCredentials("alice", Array.Empty()); Assert.ThrowsExactly(() => builder.Build()); } [TestMethod] public void StreamProvider_Ctor_With_Invalid_Port_Throws() { var options = new Socks5ProxyOptions { Host = "127.0.0.1", Port = 70000 }; Assert.ThrowsExactly(() => _ = new Socks5StreamProvider(options)); } [TestMethod] public void StreamProvider_Ctor_With_NonPositive_HandshakeTimeout_Throws() { var options = new Socks5ProxyOptions { Host = "127.0.0.1", Port = 1080, HandshakeTimeout = TimeSpan.Zero }; Assert.ThrowsExactly(() => _ = new Socks5StreamProvider(options)); } [TestMethod] public void StreamProvider_Ctor_With_Password_But_Without_Username_Throws() { var options = new Socks5ProxyOptions { Host = "127.0.0.1", Port = 1080, Password = new byte[] { 0x01 } }; Assert.ThrowsExactly(() => _ = new Socks5StreamProvider(options)); } [TestMethod] public void StreamProvider_Ctor_With_Username_But_Without_Password_Throws() { var options = new Socks5ProxyOptions { Host = "127.0.0.1", Port = 1080, Username = "alice", Password = Array.Empty() }; Assert.ThrowsExactly(() => _ = new Socks5StreamProvider(options)); } }