Search in sources :

Example 56 with EzyServerContext

use of com.tvd12.ezyfoxserver.context.EzyServerContext 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)

Example 57 with EzyServerContext

use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.

the class EzySimpleDataHandlerTest method checkMaxRequestPerSecondCase.

@SuppressWarnings("rawtypes")
@Test
public void checkMaxRequestPerSecondCase() throws Exception {
    int zoneId = 1;
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyZoneUserManager zoneUserManager = mock(EzyZoneUserManager.class);
    when(zone.getUserManager()).thenReturn(zoneUserManager);
    when(serverContext.getZoneContext(zoneId)).thenReturn(zoneContext);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzyChannel channel = mock(EzyChannel.class);
    when(session.getChannel()).thenReturn(channel);
    EzyServer server = mock(EzyServer.class);
    when(serverContext.getServer()).thenReturn(server);
    EzyServerControllers controllers = mock(EzyServerControllers.class);
    EzyInterceptor streamingInterceptor = mock(EzyInterceptor.class);
    when(controllers.getStreamingInterceptor()).thenReturn(streamingInterceptor);
    EzyStreamingController streamingController = mock(EzyStreamingController.class);
    when(controllers.getStreamingController()).thenReturn(streamingController);
    EzyInterceptor loginInterceptor = mock(EzyInterceptor.class);
    when(controllers.getInterceptor(EzyCommand.LOGIN)).thenReturn(loginInterceptor);
    EzyController loginController = mock(EzyController.class);
    when(controllers.getController(EzyCommand.LOGIN)).thenReturn(loginController);
    when(server.getControllers()).thenReturn(controllers);
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    when(server.getSessionManager()).thenReturn(sessionManager);
    EzyCloseSession closeSession = mock(EzyCloseSession.class);
    when(serverContext.get(EzyCloseSession.class)).thenReturn(closeSession);
    EzySettings settings = mock(EzySettings.class);
    when(settings.isDebug()).thenReturn(true);
    when(server.getSettings()).thenReturn(settings);
    EzySessionManagementSetting sessionManagementSetting = mock(EzySessionManagementSetting.class);
    when(settings.getSessionManagement()).thenReturn(sessionManagementSetting);
    EzyLoggerSetting loggerSetting = mock(EzyLoggerSetting.class);
    when(settings.getLogger()).thenReturn(loggerSetting);
    EzyLoggerSetting.EzyIgnoredCommandsSetting ignoredCommandsSetting = mock(EzyLoggerSetting.EzyIgnoredCommandsSetting.class);
    when(loggerSetting.getIgnoredCommands()).thenReturn(ignoredCommandsSetting);
    when(ignoredCommandsSetting.getCommands()).thenReturn(new HashSet<>());
    EzySessionManagementSetting.EzyMaxRequestPerSecond maxRequestPerSecond = mock(EzySessionManagementSetting.EzyMaxRequestPerSecond.class);
    when(maxRequestPerSecond.getValue()).thenReturn(3);
    when(maxRequestPerSecond.getAction()).thenReturn(EzyMaxRequestPerSecondAction.DISCONNECT_SESSION);
    when(sessionManagementSetting.getSessionMaxRequestPerSecond()).thenReturn(maxRequestPerSecond);
    MyTestDataHandler handler = new MyTestDataHandler(serverContext, session);
    when(session.getDelegate()).thenReturn(handler);
    when(session.isActivated()).thenReturn(true);
    EzyArray loginData = EzyEntityFactory.newArrayBuilder().append("zone").append("username").append("password").append(EzyEntityFactory.newObject()).build();
    EzyArray requestData = EzyEntityFactory.newArrayBuilder().append(EzyCommand.LOGIN.getId()).append(loginData).build();
    handler.dataReceived(EzyCommand.LOGIN, requestData);
    EzySimpleUser user = new EzySimpleUser();
    user.addSession(session);
    user.setZoneId(zoneId);
    handler.onSessionLoggedIn(user);
    handler.streamingReceived(new byte[] { 1, 2, 3 });
    EzyArray accessAppData = EzyEntityFactory.newArrayBuilder().append("app").append(EzyEntityFactory.newObject()).build();
    EzyArray requestData2 = EzyEntityFactory.newArrayBuilder().append(EzyCommand.APP_ACCESS.getId()).append(accessAppData).build();
    handler.dataReceived(EzyCommand.APP_ACCESS, requestData2);
    handler.dataReceived(EzyCommand.LOGIN, requestData);
    Thread.sleep(1200);
    handler.dataReceived(EzyCommand.LOGIN, requestData);
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyChannel(com.tvd12.ezyfoxserver.socket.EzyChannel) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) EzyInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyInterceptor) EzyStreamingController(com.tvd12.ezyfoxserver.controller.EzyStreamingController) EzyLoggerSetting(com.tvd12.ezyfoxserver.setting.EzyLoggerSetting) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzyCloseSession(com.tvd12.ezyfoxserver.command.EzyCloseSession) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySessionManagementSetting) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 58 with EzyServerContext

use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.

the class EzyUserDataHandlerTest method createHandler.

@SuppressWarnings("rawtypes")
private MyTestDataHandler createHandler() {
    int zoneId = 1;
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyZoneUserManager zoneUserManager = mock(EzyZoneUserManager.class);
    when(zone.getUserManager()).thenReturn(zoneUserManager);
    when(serverContext.getZoneContext(zoneId)).thenReturn(zoneContext);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzyChannel channel = mock(EzyChannel.class);
    when(session.getChannel()).thenReturn(channel);
    EzyServer server = mock(EzyServer.class);
    when(serverContext.getServer()).thenReturn(server);
    EzyServerControllers controllers = mock(EzyServerControllers.class);
    EzyInterceptor streamingInteceptor = mock(EzyInterceptor.class);
    when(controllers.getStreamingInterceptor()).thenReturn(streamingInteceptor);
    EzyStreamingController streamingController = mock(EzyStreamingController.class);
    when(controllers.getStreamingController()).thenReturn(streamingController);
    EzyInterceptor loginInteceptor = mock(EzyInterceptor.class);
    when(controllers.getInterceptor(EzyCommand.LOGIN)).thenReturn(loginInteceptor);
    EzyController loginController = mock(EzyController.class);
    when(controllers.getController(EzyCommand.LOGIN)).thenReturn(loginController);
    when(server.getControllers()).thenReturn(controllers);
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    when(server.getSessionManager()).thenReturn(sessionManager);
    EzyCloseSession closeSession = mock(EzyCloseSession.class);
    when(serverContext.get(EzyCloseSession.class)).thenReturn(closeSession);
    EzySettings settings = mock(EzySettings.class);
    when(settings.isDebug()).thenReturn(true);
    when(server.getSettings()).thenReturn(settings);
    EzySessionManagementSetting sessionManagementSetting = mock(EzySessionManagementSetting.class);
    when(settings.getSessionManagement()).thenReturn(sessionManagementSetting);
    EzyLoggerSetting loggerSetting = mock(EzyLoggerSetting.class);
    when(settings.getLogger()).thenReturn(loggerSetting);
    EzyLoggerSetting.EzyIgnoredCommandsSetting ignoredCommandsSetting = mock(EzyLoggerSetting.EzyIgnoredCommandsSetting.class);
    when(loggerSetting.getIgnoredCommands()).thenReturn(ignoredCommandsSetting);
    when(ignoredCommandsSetting.getCommands()).thenReturn(Sets.newHashSet(EzyCommand.PING));
    EzySessionManagementSetting.EzyMaxRequestPerSecond maxRequestPerSecond = mock(EzySessionManagementSetting.EzyMaxRequestPerSecond.class);
    when(maxRequestPerSecond.getValue()).thenReturn(3);
    when(maxRequestPerSecond.getAction()).thenReturn(EzyMaxRequestPerSecondAction.DISCONNECT_SESSION);
    when(sessionManagementSetting.getSessionMaxRequestPerSecond()).thenReturn(maxRequestPerSecond);
    return new MyTestDataHandler(serverContext, session);
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyChannel(com.tvd12.ezyfoxserver.socket.EzyChannel) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) EzyInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyInterceptor) EzyStreamingController(com.tvd12.ezyfoxserver.controller.EzyStreamingController) EzyLoggerSetting(com.tvd12.ezyfoxserver.setting.EzyLoggerSetting) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzyCloseSession(com.tvd12.ezyfoxserver.command.EzyCloseSession) EzySessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySessionManagementSetting) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings)

Example 59 with EzyServerContext

use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.

the class EzyServerUserInterceptorTest method test.

@Test(expectedExceptions = { EzyNotAuthorizedException.class })
public void test() throws Exception {
    EzyServerContext context = newServerContext();
    EzyServerUserInterceptor interceptor = new EzyServerUserInterceptor();
    EzyRequestAppRequest request = new EzySimpleRequestAppRequest();
    interceptor.intercept(context, request);
}
Also used : EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleRequestAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequestAppRequest) EzyRequestAppRequest(com.tvd12.ezyfoxserver.request.EzyRequestAppRequest) EzyServerUserInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyServerUserInterceptor) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 60 with EzyServerContext

use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.

the class EzyServerUserInterceptorTest method test1.

@Test
public void test1() throws Exception {
    EzyServerContext context = newServerContext();
    EzyServerUserInterceptor interceptor = new EzyServerUserInterceptor();
    EzySimpleRequestAppRequest request = new EzySimpleRequestAppRequest();
    request.setUser(new MyTestUser());
    interceptor.intercept(context, request);
}
Also used : EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) MyTestUser(com.tvd12.ezyfoxserver.testing.MyTestUser) EzySimpleRequestAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequestAppRequest) EzyServerUserInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyServerUserInterceptor) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Aggregations

EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)72 Test (org.testng.annotations.Test)67 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)46 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)25 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)25 BaseTest (com.tvd12.test.base.BaseTest)23 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)22 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)21 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)20 EzyServer (com.tvd12.ezyfoxserver.EzyServer)17 EzySettings (com.tvd12.ezyfoxserver.setting.EzySettings)16 EzyArray (com.tvd12.ezyfox.entity.EzyArray)14 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)14 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)13 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)13 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)12 EzyChannel (com.tvd12.ezyfoxserver.socket.EzyChannel)12 EzyZone (com.tvd12.ezyfoxserver.EzyZone)11 EzyController (com.tvd12.ezyfoxserver.controller.EzyController)11 EzyLoggerSetting (com.tvd12.ezyfoxserver.setting.EzyLoggerSetting)11