Skip to content

Commit

Permalink
fixed retain of CONNECT message in ClientConnection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian-Limpoeck committed Oct 24, 2024
1 parent f625520 commit 62baf07
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ public void connectSuccessfulUndecided(
}

clientConnectionContext.proposeClientState(ClientState.AUTHENTICATED);
connectAuthenticated(ctx, clientConnectionContext, connect, clientSettings);
cleanChannelAttributesAfterAuth(clientConnectionContext);
connectAuthenticated(ctx, clientConnectionContext, connect, clientSettings);
}

public void connectSuccessfulAuthenticated(
Expand All @@ -236,8 +236,8 @@ public void connectSuccessfulAuthenticated(
final @Nullable ModifiableClientSettingsImpl clientSettings) {

clientConnectionContext.proposeClientState(ClientState.AUTHENTICATED);
connectAuthenticated(ctx, clientConnectionContext, connect, clientSettings);
cleanChannelAttributesAfterAuth(clientConnectionContext);
connectAuthenticated(ctx, clientConnectionContext, connect, clientSettings);
}

private static void cleanChannelAttributesAfterAuth(final @NotNull ClientConnectionContext clientConnectionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,36 @@ public void test_set_client_settings() {
assertEquals(123, connect.getReceiveMaximum());
}

@Test(timeout = 5000)
public void test_connectAuthenticated_connectMessageCleared() {
createHandler();
final CONNECT connect =
new CONNECT.Mqtt5Builder().withClientIdentifier("client").withAuthMethod("someMethod").build();
final ModifiableClientSettingsImpl clientSettings = new ModifiableClientSettingsImpl(65535, null);
clientConnectionContext.setAuthConnect(connect);

handler.connectSuccessfulAuthenticated(ctx, clientConnectionContext, connect, clientSettings);

final ClientConnection clientConnection = ClientConnection.of(channel);
assertEquals(ClientState.AUTHENTICATED, clientConnection.getClientState());
assertNull(clientConnection.getAuthConnect());
}

@Test(timeout = 5000)
public void test_connectUnauthenticated_connectMessageCleared() {
createHandler();
final CONNECT connect =
new CONNECT.Mqtt5Builder().withClientIdentifier("client").withAuthMethod("someMethod").build();
final ModifiableClientSettingsImpl clientSettings = new ModifiableClientSettingsImpl(65535, null);
clientConnectionContext.setAuthConnect(connect);

handler.connectSuccessfulUndecided(ctx, clientConnectionContext, connect, clientSettings);

final ClientConnection clientConnection = ClientConnection.of(channel);
assertEquals(ClientState.AUTHENTICATED, clientConnection.getClientState());
assertNull(clientConnection.getAuthConnect());
}

@Test
public void test_start_connection_persistent() throws Exception {
final CONNECT connect = new CONNECT.Mqtt3Builder().withClientIdentifier("client")
Expand Down

0 comments on commit 62baf07

Please sign in to comment.