use of com.tvd12.ezyfoxserver.entity.EzySession 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));
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyHandShakeControllerTest method newSession.
@Override
protected EzySession newSession() {
KeyPair keyPair = newRSAKeys();
EzySession session = super.newSession();
session.setToken("reconnectToken#1");
session.setPublicKey(keyPair.getPublic().getEncoded());
return session;
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyRequestHandleExceptionTest method test2.
@Test
public void test2() {
EzySession session = Mockito.mock(EzySession.class);
Mockito.when(session.getName()).thenReturn("hello world");
EzyRequestHandleException exception = EzyRequestHandleException.requestHandleException(session, EzyCommand.LOGIN, new Object(), new Exception());
assert exception.getSession() == session;
assert exception.getCommand() == EzyCommand.LOGIN;
assert exception.getData() != null;
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyRequestHandleExceptionTest method test.
@Test(expectedExceptions = { EzyRequestHandleException.class })
public void test() {
EzySession session = Mockito.mock(EzySession.class);
Mockito.when(session.getName()).thenReturn("hello world");
throw EzyRequestHandleException.requestHandleException(session, EzyCommand.LOGIN, new Object(), new Exception());
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyPluginSendResponseImpl method execute.
@Override
public void execute(EzyData data, Collection<EzySession> recipients, boolean encrypted, EzyTransportType transportType) {
EzyResponse response = newResponse(data);
serverContext.send(response, recipients, encrypted, transportType);
}
Aggregations