Test fixes, keep logic for auth for mqtt v3
This commit is contained in:
parent
885c1c3d88
commit
dfbf3a9cd8
@ -121,7 +121,7 @@ public class MqttTestClient {
|
||||
}
|
||||
|
||||
private MqttAsyncClient createClient(String clientId) throws MqttException {
|
||||
if (clientId == null) {
|
||||
if (StringUtils.isEmpty(clientId)) {
|
||||
clientId = MqttAsyncClient.generateClientId();
|
||||
}
|
||||
return new MqttAsyncClient(MQTT_URL, clientId, new MemoryPersistence());
|
||||
|
||||
@ -15,11 +15,9 @@
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.mqttv5.client.publish;
|
||||
|
||||
import io.netty.handler.codec.mqtt.MqttQoS;
|
||||
import org.eclipse.paho.mqttv5.client.IMqttToken;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttPubAck;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttSubAck;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage;
|
||||
import org.junit.Assert;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
@ -27,7 +25,6 @@ import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest;
|
||||
import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient;
|
||||
|
||||
import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_PUBACK;
|
||||
import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_SUBACK;
|
||||
|
||||
public abstract class AbstractMqttV5ClientPublishTest extends AbstractMqttIntegrationTest {
|
||||
|
||||
|
||||
@ -16,25 +16,16 @@
|
||||
package org.thingsboard.server.transport.mqtt.mqttv5.client.subscribe;
|
||||
|
||||
import io.netty.handler.codec.mqtt.MqttQoS;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.paho.mqttv5.client.IMqttToken;
|
||||
import org.eclipse.paho.mqttv5.client.MqttConnectionOptions;
|
||||
import org.eclipse.paho.mqttv5.common.MqttException;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttConnAck;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttSubAck;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage;
|
||||
import org.junit.Assert;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest;
|
||||
import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestCallback;
|
||||
import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_CONNACK;
|
||||
import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_SUBACK;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
public abstract class AbstractMqttV5ClientSubscriptionTest extends AbstractMqttIntegrationTest {
|
||||
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
package org.thingsboard.server.transport.mqtt.mqttv5.client.subscribe;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
@ -17,7 +17,6 @@ package org.thingsboard.server.transport.mqtt.mqttv5.client.unsubscribe;
|
||||
|
||||
import io.netty.handler.codec.mqtt.MqttQoS;
|
||||
import org.eclipse.paho.mqttv5.client.IMqttToken;
|
||||
import org.eclipse.paho.mqttv5.client.MqttConnectionOptions;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttUnsubAck;
|
||||
import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage;
|
||||
|
||||
@ -42,7 +42,7 @@ import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVIC
|
||||
|
||||
@Slf4j
|
||||
@DaoSqlTest
|
||||
public class MqttProvisionJsonDeviceTest extends AbstractMqttV5Test {
|
||||
public class MqttV5ProvisionDeviceTest extends AbstractMqttV5Test {
|
||||
|
||||
@Autowired
|
||||
DeviceCredentialsService deviceCredentialsService;
|
||||
@ -17,8 +17,10 @@ package org.thingsboard.server.transport.mqtt.mqttv5.timeseries;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttV5TimeseriesTest extends AbstractMqttV5TimeseriesTest {
|
||||
|
||||
@Before
|
||||
|
||||
@ -1010,6 +1010,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
||||
private void onValidateDeviceResponse(ValidateDeviceCredentialsResponse msg, ChannelHandlerContext ctx, MqttConnectMessage connectMessage) {
|
||||
if (!msg.hasDeviceInfo()) {
|
||||
context.onAuthFailure(address);
|
||||
if (MqttVersion.MQTT_5.equals(deviceSessionCtx.getMqttVersion())) {
|
||||
ReturnCode returnCode = ReturnCode.NOT_AUTHORIZED_5;
|
||||
if (sslHandler == null || getX509Certificate() == null) {
|
||||
if (connectMessage.payload().userName() == null ^ connectMessage.payload().passwordInBytes() == null) {
|
||||
@ -1019,6 +1020,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
||||
}
|
||||
}
|
||||
ctx.writeAndFlush(createMqttConnAckMsg(returnCode, connectMessage));
|
||||
}
|
||||
ctx.close();
|
||||
} else {
|
||||
context.onAuthSuccess(address);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user