@Test public void getUniqueIdFromMessage() throws Exception { assertThat(messageIdExtractor.getUniqueIdFromMessage(requestMessage, encryptor, connectionId)) .isEqualTo(uniqueId); }
public long getUniqueIdFromMessage(Message requestMessage, Encryptor handshake, long connectionId) throws AuthenticationRequiredException { AuthIds aIds = getAuthIdsFromMessage(requestMessage, handshake); if (connectionId != aIds.getConnectionId()) { throw new AuthenticationRequiredException( "No security credentials are provided"); } return aIds.getUniqueId(); }
@Before public void before() throws Exception { this.messageIdExtractor = new MessageIdExtractor(); decryptedBytes = byteArrayFromIds(connectionId, uniqueId); MockitoAnnotations.initMocks(this); when(encryptor.decryptBytes(any())).thenReturn(decryptedBytes); }
@Test public void throwsWhenConnectionIdsDoNotMatch() throws Exception { long otherConnectionId = 789L; assertThatThrownBy(() -> messageIdExtractor.getUniqueIdFromMessage(requestMessage, encryptor, otherConnectionId)).isInstanceOf(AuthenticationRequiredException.class); }
@Test public void post65SecureShouldUseUniqueIdFromMessage() { long uniqueIdFromMessage = 23456L; when(handshake.getVersion()).thenReturn(Version.GFE_82); serverConnection.setRequestMessage(requestMsg); assertThat(serverConnection.getRequestMessage()).isSameAs(requestMsg); when(requestMsg.isSecureMode()).thenReturn(true); when(messageIdExtractor.getUniqueIdFromMessage(any(Message.class), any(Encryptor.class), anyLong())).thenReturn(uniqueIdFromMessage); serverConnection.setMessageIdExtractor(messageIdExtractor); assertThat(serverConnection.getUniqueId()).isEqualTo(uniqueIdFromMessage); }
public long getUniqueId() { long uniqueId; if (this.handshake.getVersion().isPre65() || communicationMode.isWAN()) { uniqueId = this.userAuthId; } else if (this.requestMessage.isSecureMode()) { uniqueId = messageIdExtractor.getUniqueIdFromMessage(this.requestMessage, this.handshake.getEncryptor(), this.connectionId); } else { throw new AuthenticationRequiredException( "No security credentials are provided"); } return uniqueId; }