Browse Source

Merge branch 'master'

release/3.x.x
Volker Milbrandt 3 years ago
parent
commit
e342a51d50
1 changed files with 50 additions and 0 deletions
  1. +50
    -0
      Tests/MQTTnet.Core.Tests/Server_Tests.cs

+ 50
- 0
Tests/MQTTnet.Core.Tests/Server_Tests.cs View File

@@ -6,6 +6,7 @@ using MQTTnet.Client.Disconnecting;
using MQTTnet.Client.Options;
using MQTTnet.Client.Receiving;
using MQTTnet.Client.Subscribing;
using MQTTnet.Exceptions;
using MQTTnet.Protocol;
using MQTTnet.Server;
using MQTTnet.Tests.Mockups;
@@ -25,6 +26,55 @@ namespace MQTTnet.Tests
{
public TestContext TestContext { get; set; }

[TestMethod]
[DataRow("", null)]
[DataRow("", "")]
[DataRow(null, null)]
public async Task Use_Admissible_Credentials(string username, string password)
{
using (var testEnvironment = new TestEnvironment())
{
await testEnvironment.StartServerAsync();

var client = testEnvironment.CreateClient();

var clientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("localhost", testEnvironment.ServerPort)
.WithCredentials(username, password)
.Build();

var connectResult = await client.ConnectAsync(clientOptions);

Assert.IsFalse(connectResult.IsSessionPresent);
Assert.IsTrue(client.IsConnected);
}
}

[TestMethod]
public async Task Use_Username_Null_Password_Empty()
{
string username = null;
string password = string.Empty;

using (var testEnvironment = new TestEnvironment())
{
testEnvironment.IgnoreClientLogErrors = true;

await testEnvironment.StartServerAsync();

var client = testEnvironment.CreateClient();

var clientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("localhost", testEnvironment.ServerPort)
.WithCredentials(username, password)
.Build();

var ex = await Assert.ThrowsExceptionAsync<MqttCommunicationException>(async () => await client.ConnectAsync(clientOptions));
Assert.IsInstanceOfType(ex.InnerException, typeof(MqttProtocolViolationException));
Assert.AreEqual("If the User Name Flag is set to 0, the Password Flag MUST be set to 0 [MQTT-3.1.2-22].", ex.Message, false);
}
}

[TestMethod]
public async Task Use_Empty_Client_ID()
{


Loading…
Cancel
Save