Skip to content

MQTT 5 CONNECT with password but no username is rejected by MqttEncoder #16828

@shblue21

Description

@shblue21

Expected behavior

Encoding an MQTT 5 CONNECT message with hasUserName=false and hasPassword=true should succeed.

MQTT 5 allows sending a Password with no User Name, while MQTT 3.1.1 did not:
https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901044

This version of the protocol allows the sending of a Password with no User Name, where MQTT v3.1.1 did not.### Actual behavior

Actual behavior

MqttDecoder accepts this CONNECT message for MQTT 5, but encoding the same message fails.

EncoderException: Without a username, the password MUST be not set

Steps to reproduce

Encode an MQTT 5 CONNECT message with a password set and username unset.

Minimal yet complete reproducer code (or URL to code)

MqttConnectMessage message = MqttMessageBuilders.connect()
    .clientId("client")
    .protocolVersion(MqttVersion.MQTT_5)
    .username(null)
    .password("secret".getBytes(CharsetUtil.UTF_8))
    .build();

EmbeddedChannel channel = new EmbeddedChannel(MqttEncoder.INSTANCE);
channel.writeOutbound(message);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions