mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-18 10:26:11 +08:00
Add interface for server options. Add context class for connection validator (hide internal packets).
This commit is contained in:
@@ -62,7 +62,7 @@ namespace MQTTnet.Core.Tests
|
||||
ClientAccepted?.Invoke(this, new MqttServerAdapterClientAcceptedEventArgs(adapter));
|
||||
}
|
||||
|
||||
public Task StartAsync(MqttServerOptions options)
|
||||
public Task StartAsync(IMqttServerOptions options)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
@@ -23,11 +23,9 @@ namespace MQTTnet.TestApp.NetCore
|
||||
{
|
||||
if (p.Username != "USER" || p.Password != "PASS")
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
p.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
}
|
||||
}
|
||||
|
||||
return MqttConnectReturnCode.ConnectionAccepted;
|
||||
},
|
||||
|
||||
Storage = new RetainedMessageHandler(),
|
||||
|
||||
@@ -354,20 +354,23 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
{
|
||||
if (c.ClientId.Length < 10)
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedIdentifierRejected;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedIdentifierRejected;
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.Username != "mySecretUser")
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.Password != "mySecretPassword")
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
return;
|
||||
}
|
||||
|
||||
return MqttConnectReturnCode.ConnectionAccepted;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionAccepted;
|
||||
};
|
||||
|
||||
var factory = new MqttFactory();
|
||||
@@ -410,14 +413,15 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
};
|
||||
|
||||
options.DefaultEndpointOptions.Port = 1884;
|
||||
options.ConnectionValidator = packet =>
|
||||
options.ConnectionValidator = c =>
|
||||
{
|
||||
if (packet.ClientId != "Highlander")
|
||||
if (c.ClientId != "Highlander")
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedIdentifierRejected;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedIdentifierRejected;
|
||||
return;
|
||||
}
|
||||
|
||||
return MqttConnectReturnCode.ConnectionAccepted;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionAccepted;
|
||||
};
|
||||
|
||||
var mqttServer = new MqttFactory().CreateMqttServer();
|
||||
@@ -432,20 +436,23 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
{
|
||||
if (c.ClientId.Length < 10)
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedIdentifierRejected;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedIdentifierRejected;
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.Username != "mySecretUser")
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.Password != "mySecretPassword")
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
return;
|
||||
}
|
||||
|
||||
return MqttConnectReturnCode.ConnectionAccepted;
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionAccepted;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user