Search in sources :

Example 6 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.

the class EzyLoginProcessor method newUser.

protected EzyUser newUser(EzyZoneSetting zoneSetting, EzyUserManagementSetting userManagementSetting, String newUserName, String password, Map<Object, Object> properties) {
    EzySimpleUser user = new EzySimpleUser();
    user.setName(newUserName);
    user.setPassword(password);
    user.setZoneId(zoneSetting.getId());
    user.setMaxIdleTime(userManagementSetting.getUserMaxIdleTime());
    user.setMaxSessions(userManagementSetting.getMaxSessionPerUser());
    user.setProperties(properties);
    return user;
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser)

Example 7 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.

the class EzyRawBytesInterceptorTest method test.

@Test
public void test() throws Exception {
    EzyRawBytesInterceptor interceptor = new EzyRawBytesInterceptor();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzySimpleStreamingRequest request = new EzySimpleStreamingRequest();
    request.setUser(new EzySimpleUser());
    interceptor.intercept(serverContext, request);
}
Also used : EzySimpleStreamingRequest(com.tvd12.ezyfoxserver.request.EzySimpleStreamingRequest) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyRawBytesInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyRawBytesInterceptor) Test(org.testng.annotations.Test)

Example 8 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.

the class EzyAccessAppControllerTest method newRequest.

protected EzySimpleAccessAppRequest newRequest(int index) {
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user" + index);
    user.setZoneId(1);
    EzyArray params = EzyEntityFactory.newArrayBuilder().append("test").build();
    EzySimpleAccessAppRequest request = new EzySimpleAccessAppRequest();
    request.setUser(user);
    request.setSession(session);
    request.deserializeParams(params);
    return request;
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleAccessAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleAccessAppRequest)

Example 9 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.

the class EzySimpleDataHandlerTest method handleReceivedStreaming0ExceptionCase.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void handleReceivedStreaming0ExceptionCase() 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);
    doThrow(new IllegalArgumentException("server maintain")).when(streamingInterceptor).intercept(any(), any());
    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);
    EzySimpleUser user = new EzySimpleUser();
    user.addSession(session);
    user.setZoneId(zoneId);
    handler.onSessionLoggedIn(user);
    handler.streamingReceived(new byte[] { 1, 2, 3 });
}
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) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 10 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.

the class EzySimpleDataHandlerTest method normalCase.

@SuppressWarnings("rawtypes")
@Test
public void normalCase() {
    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);
    handler.dataReceived(EzyCommand.LOGIN, requestData);
    handler.exceptionCaught(new EzyMaxRequestSizeException(1024, 512));
    handler.channelInactive(EzyDisconnectReason.ADMIN_BAN);
    handler.channelInactive(EzyDisconnectReason.ADMIN_BAN);
    handler.destroy();
    System.out.println(handler);
}
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) EzyMaxRequestSizeException(com.tvd12.ezyfox.exception.EzyMaxRequestSizeException) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Aggregations

EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)39 Test (org.testng.annotations.Test)29 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)17 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)17 BaseTest (com.tvd12.test.base.BaseTest)13 EzyArray (com.tvd12.ezyfox.entity.EzyArray)11 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)10 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)9 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)6 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)6 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)6 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)6 EzyZone (com.tvd12.ezyfoxserver.EzyZone)5 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)5 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)5 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)5 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)4 EzyPluginRequestController (com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController)4 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)4 EzyServer (com.tvd12.ezyfoxserver.EzyServer)3