Skip to content

Commit

Permalink
This closes #3949
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram committed Feb 10, 2022
2 parents 7a34194 + 27d0183 commit d2e31a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ void handleConnect(MqttConnectMessage connect) throws Exception {
} catch (ActiveMQSecurityException e) {
if (session.is5()) {
session.getProtocolHandler().sendConnack(MQTTReasonCodes.BAD_USER_NAME_OR_PASSWORD);
} else {
session.getProtocolHandler().sendConnack(MQTTReasonCodes.NOT_AUTHORIZED_3);
}
disconnect(true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
*/
package org.apache.activemq.artemis.tests.integration.mqtt;

import java.io.EOFException;
import java.util.Arrays;

import org.apache.activemq.artemis.tests.util.Wait;
import org.fusesource.mqtt.client.BlockingConnection;
import org.fusesource.mqtt.client.MQTT;
import org.fusesource.mqtt.client.MQTTException;
import org.fusesource.mqtt.codec.CONNACK;
import org.junit.Test;

public class MQTTSecurityTest extends MQTTTestSupport {
Expand Down Expand Up @@ -52,7 +53,7 @@ public void testConnection() throws Exception {
}
}

@Test(timeout = 30000, expected = EOFException.class)
@Test(timeout = 30000)
public void testConnectionWithNullPassword() throws Exception {
for (String version : Arrays.asList("3.1", "3.1.1")) {

Expand All @@ -66,8 +67,13 @@ public void testConnectionWithNullPassword() throws Exception {
connection = mqtt.blockingConnection();
connection.connect();
fail("Connect should fail");
} catch (MQTTException e) {
assertEquals(CONNACK.Code.CONNECTION_REFUSED_NOT_AUTHORIZED, e.connack.code());
} catch (Exception e) {
fail("Should have caught an MQTTException");
} finally {
if (connection != null && connection.isConnected()) connection.disconnect();
if (connection != null && connection.isConnected())
connection.disconnect();
}
}
}
Expand Down

0 comments on commit d2e31a6

Please sign in to comment.