Search in sources :

Example 6 with EzyHandshakeParams

use of com.tvd12.ezyfoxserver.request.EzyHandshakeParams in project ezyfox-server by youngmonkeys.

the class EzyHandShakeControllerTest method handleSocketSSLButInvalidClientKeyEmptyTest.

@Test
public void handleSocketSSLButInvalidClientKeyEmptyTest() {
    // given
    EzyHandshakeController sut = new EzyHandshakeController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyHandShakeRequest request = mock(EzyHandShakeRequest.class);
    EzyHandshakeParams params = mock(EzyHandshakeParams.class);
    when(request.getParams()).thenReturn(params);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
    when(request.getSession()).thenReturn(session);
    EzyServer server = mock(EzyServer.class);
    EzySettings settings = mock(EzySettings.class);
    EzySocketSetting socketSetting = mock(EzySocketSetting.class);
    when(settings.getSocket()).thenReturn(socketSetting);
    when(socketSetting.isSslActive()).thenReturn(true);
    when(serverContext.getServer()).thenReturn(server);
    when(server.getSettings()).thenReturn(settings);
    String clientId = RandomUtil.randomShortHexString();
    String clientType = RandomUtil.randomShortAlphabetString();
    String clientVersion = RandomUtil.randomShortAlphabetString();
    String reconnectToken = RandomUtil.randomShortHexString();
    byte[] clientKey = new byte[] { 1, 2, 3 };
    when(params.getClientId()).thenReturn(clientId);
    when(params.getClientKey()).thenReturn(clientKey);
    when(params.getClientType()).thenReturn(clientType);
    when(params.getClientVersion()).thenReturn(clientVersion);
    when(params.getReconnectToken()).thenReturn(reconnectToken);
    when(params.isEnableEncryption()).thenReturn(true);
    // when
    sut.handle(serverContext, request);
    // then
    verify(session, times(1)).setClientId(clientId);
    verify(session, times(1)).setClientKey(clientKey);
    verify(session, times(1)).setClientType(clientType);
    verify(session, times(1)).setClientVersion(clientVersion);
    verify(session, times(1)).setSessionKey(any(byte[].class));
}
Also used : EzyHandShakeRequest(com.tvd12.ezyfoxserver.request.EzyHandShakeRequest) EzyHandshakeParams(com.tvd12.ezyfoxserver.request.EzyHandshakeParams) EzySocketSetting(com.tvd12.ezyfoxserver.setting.EzySocketSetting) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyHandshakeController(com.tvd12.ezyfoxserver.controller.EzyHandshakeController) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) Test(org.testng.annotations.Test)

Example 7 with EzyHandshakeParams

use of com.tvd12.ezyfoxserver.request.EzyHandshakeParams in project ezyfox-server by youngmonkeys.

the class EzyHandShakeControllerTest method handleSocketSSLTest.

@Test
public void handleSocketSSLTest() {
    // given
    EzyHandshakeController sut = new EzyHandshakeController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyHandShakeRequest request = mock(EzyHandShakeRequest.class);
    EzyHandshakeParams params = mock(EzyHandshakeParams.class);
    when(request.getParams()).thenReturn(params);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
    when(request.getSession()).thenReturn(session);
    EzyServer server = mock(EzyServer.class);
    EzySettings settings = mock(EzySettings.class);
    EzySocketSetting socketSetting = mock(EzySocketSetting.class);
    when(settings.getSocket()).thenReturn(socketSetting);
    when(socketSetting.isSslActive()).thenReturn(true);
    when(serverContext.getServer()).thenReturn(server);
    when(server.getSettings()).thenReturn(settings);
    String clientId = RandomUtil.randomShortHexString();
    String clientType = RandomUtil.randomShortAlphabetString();
    String clientVersion = RandomUtil.randomShortAlphabetString();
    String reconnectToken = RandomUtil.randomShortHexString();
    KeyPair keyPair = EzyKeysGenerator.builder().build().generate();
    byte[] clientKey = keyPair.getPublic().getEncoded();
    when(params.getClientId()).thenReturn(clientId);
    when(params.getClientKey()).thenReturn(clientKey);
    when(params.getClientType()).thenReturn(clientType);
    when(params.getClientVersion()).thenReturn(clientVersion);
    when(params.getReconnectToken()).thenReturn(reconnectToken);
    when(params.isEnableEncryption()).thenReturn(true);
    // when
    sut.handle(serverContext, request);
    // then
    verify(session, times(1)).setClientId(clientId);
    verify(session, times(1)).setClientKey(clientKey);
    verify(session, times(1)).setClientType(clientType);
    verify(session, times(1)).setClientVersion(clientVersion);
    verify(session, times(1)).setSessionKey(any(byte[].class));
    Asserts.assertNotNull(session.getSessionKey());
}
Also used : EzyHandShakeRequest(com.tvd12.ezyfoxserver.request.EzyHandShakeRequest) EzyHandshakeParams(com.tvd12.ezyfoxserver.request.EzyHandshakeParams) KeyPair(java.security.KeyPair) EzySocketSetting(com.tvd12.ezyfoxserver.setting.EzySocketSetting) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyHandshakeController(com.tvd12.ezyfoxserver.controller.EzyHandshakeController) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) Test(org.testng.annotations.Test)

Example 8 with EzyHandshakeParams

use of com.tvd12.ezyfoxserver.request.EzyHandshakeParams in project ezyfox-server by youngmonkeys.

the class EzyHandShakeResponseTest method test.

@Test
public void test() {
    EzyHandShakeParams params = new EzyHandShakeParams();
    params.setReconnectToken("123");
    params.setServerPublicKey(new byte[0]);
    params.setSessionId(1L);
    params.setSessionKey(EzyAesCrypt.randomKey());
    assert params.getSessionId() == 1L;
    assert params.getReconnectToken().equals("123");
    assert params.getServerPublicKey().length == 0;
    assert params.getSessionKey() != null;
    EzyHandShakeResponse response = new EzyHandShakeResponse(params);
    response.serialize();
    params.setServerPublicKey(null);
    response.serialize();
    response.release();
}
Also used : EzyHandShakeResponse(com.tvd12.ezyfoxserver.response.EzyHandShakeResponse) EzyHandShakeParams(com.tvd12.ezyfoxserver.response.EzyHandShakeParams) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 9 with EzyHandshakeParams

use of com.tvd12.ezyfoxserver.request.EzyHandshakeParams in project ezyfox-server by youngmonkeys.

the class EzyHandShakeControllerTest method handleSocketSSLButWebsocketTest.

@Test
public void handleSocketSSLButWebsocketTest() {
    // given
    EzyHandshakeController sut = new EzyHandshakeController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyHandShakeRequest request = mock(EzyHandShakeRequest.class);
    EzyHandshakeParams params = mock(EzyHandshakeParams.class);
    when(request.getParams()).thenReturn(params);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.getConnectionType()).thenReturn(EzyConnectionType.WEBSOCKET);
    when(request.getSession()).thenReturn(session);
    // when
    sut.handle(serverContext, request);
    // then
    Asserts.assertNull(session.getSessionKey());
}
Also used : EzyHandShakeRequest(com.tvd12.ezyfoxserver.request.EzyHandShakeRequest) EzyHandshakeParams(com.tvd12.ezyfoxserver.request.EzyHandshakeParams) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyHandshakeController(com.tvd12.ezyfoxserver.controller.EzyHandshakeController) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 10 with EzyHandshakeParams

use of com.tvd12.ezyfoxserver.request.EzyHandshakeParams in project ezyfox-server by youngmonkeys.

the class EzyHandShakeControllerTest method handleSocketSSLButClientKeyEmptyTest.

@Test
public void handleSocketSSLButClientKeyEmptyTest() {
    // given
    EzyHandshakeController sut = new EzyHandshakeController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyHandShakeRequest request = mock(EzyHandShakeRequest.class);
    EzyHandshakeParams params = mock(EzyHandshakeParams.class);
    when(request.getParams()).thenReturn(params);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
    when(request.getSession()).thenReturn(session);
    EzyServer server = mock(EzyServer.class);
    EzySettings settings = mock(EzySettings.class);
    EzySocketSetting socketSetting = mock(EzySocketSetting.class);
    when(settings.getSocket()).thenReturn(socketSetting);
    when(socketSetting.isSslActive()).thenReturn(true);
    when(serverContext.getServer()).thenReturn(server);
    when(server.getSettings()).thenReturn(settings);
    String clientId = RandomUtil.randomShortHexString();
    String clientType = RandomUtil.randomShortAlphabetString();
    String clientVersion = RandomUtil.randomShortAlphabetString();
    String reconnectToken = RandomUtil.randomShortHexString();
    byte[] clientKey = new byte[0];
    when(params.getClientId()).thenReturn(clientId);
    when(params.getClientKey()).thenReturn(clientKey);
    when(params.getClientType()).thenReturn(clientType);
    when(params.getClientVersion()).thenReturn(clientVersion);
    when(params.getReconnectToken()).thenReturn(reconnectToken);
    when(params.isEnableEncryption()).thenReturn(true);
    // when
    sut.handle(serverContext, request);
    // then
    verify(session, times(1)).setClientId(clientId);
    verify(session, times(1)).setClientKey(clientKey);
    verify(session, times(1)).setClientType(clientType);
    verify(session, times(1)).setClientVersion(clientVersion);
    verify(session, times(1)).setSessionKey(any(byte[].class));
}
Also used : EzyHandShakeRequest(com.tvd12.ezyfoxserver.request.EzyHandShakeRequest) EzyHandshakeParams(com.tvd12.ezyfoxserver.request.EzyHandshakeParams) EzySocketSetting(com.tvd12.ezyfoxserver.setting.EzySocketSetting) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyHandshakeController(com.tvd12.ezyfoxserver.controller.EzyHandshakeController) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) Test(org.testng.annotations.Test)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)8 EzyHandshakeParams (com.tvd12.ezyfoxserver.request.EzyHandshakeParams)8 Test (org.testng.annotations.Test)8 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)7 EzyHandshakeController (com.tvd12.ezyfoxserver.controller.EzyHandshakeController)7 EzyHandShakeRequest (com.tvd12.ezyfoxserver.request.EzyHandShakeRequest)6 EzyServer (com.tvd12.ezyfoxserver.EzyServer)5 EzySettings (com.tvd12.ezyfoxserver.setting.EzySettings)5 EzySocketSetting (com.tvd12.ezyfoxserver.setting.EzySocketSetting)5 EzyHandshakeEvent (com.tvd12.ezyfoxserver.event.EzyHandshakeEvent)2 EzyHandShakeParams (com.tvd12.ezyfoxserver.response.EzyHandShakeParams)2 EzyHandShakeResponse (com.tvd12.ezyfoxserver.response.EzyHandShakeResponse)2 KeyPair (java.security.KeyPair)2 EzyArray (com.tvd12.ezyfox.entity.EzyArray)1 EzyEventType (com.tvd12.ezyfoxserver.constant.EzyEventType)1 EzySimpleHandshakeRequest (com.tvd12.ezyfoxserver.request.EzySimpleHandshakeRequest)1 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)1 BaseTest (com.tvd12.test.base.BaseTest)1