Webatrice: fix saved password (#4563)

* fix saved label, and fix using hashedPassword when Save is unchecked

* update host only after successful login

* cleanup

* fix ability to deselect saved password on successful login

* cleanup

* clear options after connection

* fix registration saved username

* cleanup

* change label

* fix tests

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
Jeremy Letto 2022-02-27 10:12:38 -06:00 committed by GitHub
parent 9577ada171
commit 2a54e9d7d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 170 additions and 169 deletions

View file

@ -11,8 +11,9 @@ export class WebClient {
public protocolVersion = 14;
public clientConfig = {
'clientver': 'webclient-1.0 (2019-10-31)',
'clientfeatures': [
clientid: 'webatrice',
clientver: 'webclient-1.0 (2019-10-31)',
clientfeatures: [
'client_id',
'client_ver',
'feature_set',
@ -30,22 +31,13 @@ export class WebClient {
]
};
public options: WebSocketConnectOptions = {
host: '',
port: '',
userName: '',
password: '',
hashedPassword: '',
newPassword: '',
email: '',
realName: '',
country: '',
clientid: null,
reason: null,
public clientOptions = {
autojoinrooms: true,
keepalive: 5000
};
public options: WebSocketConnectOptions;
public connectionAttemptMade = false;
constructor() {
@ -64,7 +56,7 @@ export class WebClient {
public connect(options: WebSocketConnectOptions) {
this.connectionAttemptMade = true;
this.options = { ...this.options, ...options };
this.options = options;
this.socket.connect(this.options);
}

View file

@ -1,4 +1,4 @@
import { StatusEnum, WebSocketConnectReason } from 'types';
import { StatusEnum, WebSocketConnectOptions, WebSocketConnectReason } from 'types';
import { SessionCommands } from './SessionCommands';
@ -81,22 +81,25 @@ describe('SessionCommands', () => {
});
describe('login', () => {
let options: WebSocketConnectOptions;
beforeEach(() => {
webClient.protobuf.controller.Command_Login = { create: args => args };
webClient.options.userName = 'user';
webClient.options.password = 'pass';
options = {
userName: 'userName',
password: 'password',
};
});
it('should call protobuf controller methods and sendCommand', () => {
SessionCommands.login();
SessionCommands.login(options);
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
'.Command_Login.ext': {
...webClient.clientConfig,
userName: webClient.options.userName,
password: webClient.options.password,
clientid: expect.any(String)
userName: options.userName,
password: options.password
}
}, expect.any(Function));
});
@ -128,7 +131,7 @@ describe('SessionCommands', () => {
jest.spyOn(SessionCommands, 'listUsers').mockImplementation(() => {});
jest.spyOn(SessionCommands, 'listRooms').mockImplementation(() => {});
SessionCommands.login();
SessionCommands.login(options);
expect(SessionPersistence.updateBuddyList).toHaveBeenCalledWith(response[respKey].buddyList);
expect(SessionPersistence.updateIgnoreList).toHaveBeenCalledWith(response[respKey].ignoreList);
@ -144,7 +147,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespClientUpdateRequired = RespClientUpdateRequired;
response.responseCode = RespClientUpdateRequired;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: missing features');
});
@ -154,7 +157,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword = RespWrongPassword;
response.responseCode = RespWrongPassword;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: incorrect username or password');
});
@ -164,7 +167,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespUsernameInvalid = RespUsernameInvalid;
response.responseCode = RespUsernameInvalid;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: incorrect username or password');
});
@ -174,7 +177,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespWouldOverwriteOldSession = RespWouldOverwriteOldSession;
response.responseCode = RespWouldOverwriteOldSession;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: duplicated user session');
});
@ -184,7 +187,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespUserIsBanned = RespUserIsBanned;
response.responseCode = RespUserIsBanned;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: banned user');
});
@ -194,7 +197,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationRequired = RespRegistrationRequired;
response.responseCode = RespRegistrationRequired;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: registration required');
});
@ -204,7 +207,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespClientIdRequired = RespClientIdRequired;
response.responseCode = RespClientIdRequired;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: missing client ID');
});
@ -214,7 +217,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespContextError = RespContextError;
response.responseCode = RespContextError;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: server error');
});
@ -224,7 +227,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespAccountNotActivated = RespAccountNotActivated;
response.responseCode = RespAccountNotActivated;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(
StatusEnum.DISCONNECTED,
@ -237,7 +240,7 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.UnknownCode = UnknownCode;
response.responseCode = UnknownCode;
SessionCommands.login();
SessionCommands.login(options);
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(
StatusEnum.DISCONNECTED,
@ -248,23 +251,24 @@ describe('SessionCommands', () => {
});
describe('register', () => {
let options: WebSocketConnectOptions;
beforeEach(() => {
webClient.protobuf.controller.Command_Register = { create: args => args };
webClient.options = {
options = {
...webClient.options,
user: 'user',
pass: 'pass',
userName: 'userName',
password: 'password',
email: 'email@example.com',
country: 'us',
realName: 'realName',
clientid: 'abcdefg'
} as any;
};
});
it('should call protobuf controller methods and sendCommand', () => {
SessionCommands.register();
SessionCommands.register(options);
const options = webClient.options as unknown as ServerRegisterParams;
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
@ -275,7 +279,6 @@ describe('SessionCommands', () => {
email: options.email,
country: options.country,
realName: options.realName,
clientid: expect.any(String)
}
}, expect.any(Function));
});
@ -302,7 +305,7 @@ describe('SessionCommands', () => {
describe('RespRegistrationAccepted', () => {
it('should call SessionCommands.login()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).toHaveBeenCalled();
@ -321,7 +324,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.accountAwaitingActivation()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'accountAwaitingActivation').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.accountAwaitingActivation).toHaveBeenCalled();
@ -329,7 +332,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -347,7 +350,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationUserNameError()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationUserNameError').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationUserNameError).toHaveBeenCalledWith(expect.any(String));
@ -355,7 +358,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -373,7 +376,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationUserNameError()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationUserNameError').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationUserNameError).toHaveBeenCalledWith(expect.any(String));
@ -381,7 +384,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -399,7 +402,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationPasswordError()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationPasswordError').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationPasswordError).toHaveBeenCalledWith(expect.any(String));
@ -407,7 +410,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -425,7 +428,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationRequiresEmail()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationRequiresEmail').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationRequiresEmail).toHaveBeenCalled();
@ -433,7 +436,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -451,7 +454,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationEmailError()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationEmailError').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationEmailError).toHaveBeenCalledWith(expect.any(String));
@ -459,7 +462,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -477,7 +480,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationEmailError()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationEmailError').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationEmailError).toHaveBeenCalledWith(expect.any(String));
@ -485,7 +488,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -503,7 +506,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationFailed()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationFailed').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationFailed).toHaveBeenCalledWith(expect.any(String));
@ -511,7 +514,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -529,7 +532,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationFailed()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationFailed').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationFailed).toHaveBeenCalledWith(expect.any(String));
@ -537,7 +540,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -555,7 +558,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationFailed()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationFailed').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationFailed).toHaveBeenCalledWith(expect.any(String));
@ -563,7 +566,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -581,7 +584,7 @@ describe('SessionCommands', () => {
it('should call SessionPersistence.registrationFailed()', () => {
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
jest.spyOn(SessionPersistence, 'registrationFailed').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.registrationFailed).toHaveBeenCalledWith(expect.any(String));
@ -589,7 +592,7 @@ describe('SessionCommands', () => {
it('should disconnect', () => {
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
SessionCommands.register();
SessionCommands.register(options);
expect(SessionCommands.disconnect).toHaveBeenCalled();
});
@ -598,27 +601,25 @@ describe('SessionCommands', () => {
});
describe('activateAccount', () => {
let options: WebSocketConnectOptions;
beforeEach(() => {
webClient.protobuf.controller.Command_Activate = { create: args => args };
webClient.options = {
...webClient.options,
user: 'user',
activationCode: 'token',
clientid: 'abcdefg'
} as any;
options = {
userName: 'userName',
token: 'token',
};
});
it('should call protobuf controller methods and sendCommand', () => {
SessionCommands.activateAccount();
SessionCommands.activateAccount(options);
const options = webClient.options as unknown as AccountActivationParams;
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
'.Command_Activate.ext': {
...webClient.clientConfig,
userName: options.userName,
token: options.token,
clientid: expect.any(String)
}
}, expect.any(Function));
});
@ -644,7 +645,7 @@ describe('SessionCommands', () => {
});
it('should activate user and login if correct activation token used', () => {
SessionCommands.activateAccount();
SessionCommands.activateAccount(options);
expect(SessionCommands.login).toHaveBeenCalled();
expect(SessionPersistence.accountActivationFailed).not.toHaveBeenCalled();
@ -655,7 +656,7 @@ describe('SessionCommands', () => {
response.responseCode = RespActivationFailed;
webClient.protobuf.controller.Response.ResponseCode.RespActivationFailed = RespActivationFailed;
SessionCommands.activateAccount();
SessionCommands.activateAccount(options);
expect(SessionCommands.login).not.toHaveBeenCalled();
expect(SessionPersistence.accountActivationFailed).toHaveBeenCalled();

View file

@ -37,8 +37,8 @@ export class SessionCommands {
webClient.disconnect();
}
static login(passwordSalt?: string): void {
const { userName, password, hashedPassword } = webClient.options;
static login(options: WebSocketConnectOptions, passwordSalt?: string): void {
const { userName, password, hashedPassword } = options;
const loginConfig: any = {
...webClient.clientConfig,
@ -109,7 +109,7 @@ export class SessionCommands {
case webClient.protobuf.controller.Response.ResponseCode.RespAccountNotActivated:
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Login failed: account not activated');
SessionPersistence.accountAwaitingActivation();
SessionPersistence.accountAwaitingActivation(options);
break;
default:
@ -121,8 +121,8 @@ export class SessionCommands {
});
}
static requestPasswordSalt(): void {
const { userName } = webClient.options as unknown as RequestPasswordSaltParams;
static requestPasswordSalt(options: WebSocketConnectOptions): void {
const { userName } = options as RequestPasswordSaltParams;
const registerConfig = {
...webClient.clientConfig,
@ -140,20 +140,20 @@ export class SessionCommands {
case webClient.protobuf.controller.Response.ResponseCode.RespOk: {
const passwordSalt = raw['.Response_PasswordSalt.ext']?.passwordSalt;
switch (webClient.options.reason) {
switch (options.reason) {
case WebSocketConnectReason.ACTIVATE_ACCOUNT: {
SessionCommands.activateAccount(passwordSalt);
SessionCommands.activateAccount(options, passwordSalt);
break;
}
case WebSocketConnectReason.PASSWORD_RESET: {
SessionCommands.resetPassword(passwordSalt);
SessionCommands.resetPassword(options, passwordSalt);
break;
}
case WebSocketConnectReason.LOGIN:
default: {
SessionCommands.login(passwordSalt);
SessionCommands.login(options, passwordSalt);
}
}
@ -168,7 +168,7 @@ export class SessionCommands {
}
}
switch (webClient.options.reason) {
switch (options.reason) {
case WebSocketConnectReason.ACTIVATE_ACCOUNT: {
SessionPersistence.accountActivationFailed();
break;
@ -189,12 +189,11 @@ export class SessionCommands {
});
}
static register(passwordSalt?: string): void {
const { userName, password, email, country, realName } = webClient.options as unknown as ServerRegisterParams;
static register(options: WebSocketConnectOptions, passwordSalt?: string): void {
const { userName, password, email, country, realName } = options as ServerRegisterParams;
const registerConfig: any = {
...webClient.clientConfig,
clientid: 'webatrice',
userName,
email,
country,
@ -215,14 +214,14 @@ export class SessionCommands {
webClient.protobuf.sendSessionCommand(sc, raw => {
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAccepted) {
SessionCommands.login(passwordSalt);
SessionCommands.login(options, passwordSalt);
SessionPersistence.registrationSuccess()
return;
}
switch (raw.responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation:
SessionPersistence.accountAwaitingActivation();
SessionPersistence.accountAwaitingActivation(options);
break;
case webClient.protobuf.controller.Response.ResponseCode.RespUserAlreadyExists:
SessionPersistence.registrationUserNameError('Username is taken');
@ -259,12 +258,11 @@ export class SessionCommands {
});
};
static activateAccount(passwordSalt?: string): void {
const { userName, token } = webClient.options as unknown as AccountActivationParams;
static activateAccount(options: WebSocketConnectOptions, passwordSalt?: string): void {
const { userName, token } = options as unknown as AccountActivationParams;
const accountActivationConfig = {
...webClient.clientConfig,
clientid: 'webatrice',
userName,
token,
};
@ -278,7 +276,7 @@ export class SessionCommands {
webClient.protobuf.sendSessionCommand(sc, raw => {
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespActivationAccepted) {
SessionPersistence.accountActivationSuccess();
SessionCommands.login(passwordSalt);
SessionCommands.login(options, passwordSalt);
} else {
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Account Activation Failed');
SessionCommands.disconnect();
@ -287,12 +285,11 @@ export class SessionCommands {
});
}
static resetPasswordRequest(): void {
const { userName } = webClient.options as unknown as ForgotPasswordParams;
static resetPasswordRequest(options: WebSocketConnectOptions): void {
const { userName } = options as unknown as ForgotPasswordParams;
const forgotPasswordConfig = {
...webClient.clientConfig,
clientid: 'webatrice',
userName,
};
@ -322,12 +319,11 @@ export class SessionCommands {
});
}
static resetPasswordChallenge(): void {
const { userName, email } = webClient.options as unknown as ForgotPasswordChallengeParams;
static resetPasswordChallenge(options: WebSocketConnectOptions): void {
const { userName, email } = options as unknown as ForgotPasswordChallengeParams;
const forgotPasswordChallengeConfig = {
...webClient.clientConfig,
clientid: 'webatrice',
userName,
email,
};
@ -351,12 +347,11 @@ export class SessionCommands {
});
}
static resetPassword(passwordSalt?: string): void {
const { userName, token, newPassword } = webClient.options as unknown as ForgotPasswordResetParams;
static resetPassword(options: WebSocketConnectOptions, passwordSalt?: string): void {
const { userName, token, newPassword } = options as unknown as ForgotPasswordResetParams;
const forgotPasswordResetConfig: any = {
...webClient.clientConfig,
clientid: 'webatrice',
userName,
token,
};

View file

@ -216,7 +216,7 @@ describe('SessionEvents', () => {
describe('.Event_ListRooms.ext', () => {
beforeEach(() => {
webClient.options.autojoinrooms = false;
webClient.clientOptions.autojoinrooms = false;
jest.spyOn(RoomPersistence, 'updateRooms').mockImplementation(() => {});
});
@ -229,7 +229,7 @@ describe('SessionEvents', () => {
});
it('should call SessionCommands.joinRoom if webClient and room is configured for autojoin', () => {
webClient.options.autojoinrooms = true;
webClient.clientOptions.autojoinrooms = true;
jest.spyOn(SessionCommands, 'joinRoom').mockImplementation(() => {});
const data: ListRoomsData = { roomList: [{ roomId, autoJoin: true } as any, { roomId: 2, autoJoin: false } as any] };
@ -291,6 +291,7 @@ describe('SessionEvents', () => {
jest.spyOn(SessionPersistence, 'updateInfo').mockImplementation(() => {});
webClient.protobuf.controller.Event_ServerIdentification = { ServerOptions: { SupportsPasswordHash: 1 } };
webClient.options = {};
});
it('update status/info and login', () => {

View file

@ -79,7 +79,7 @@ function connectionClosed({ reason, reasonStr }: ConnectionClosedData) {
function listRooms({ roomList }: ListRoomsData) {
RoomPersistence.updateRooms(roomList);
if (webClient.options.autojoinrooms) {
if (webClient.clientOptions.autojoinrooms) {
roomList.forEach(({ autoJoin, roomId }) => {
if (autoJoin) {
SessionCommands.joinRoom(roomId);
@ -120,45 +120,49 @@ function serverIdentification(info: ServerIdentificationData) {
return;
}
switch (webClient.options.reason) {
const getPasswordSalt = passwordSaltSupported(serverOptions, webClient);
const { options } = webClient;
switch (options.reason) {
case WebSocketConnectReason.LOGIN:
SessionCommands.updateStatus(StatusEnum.LOGGING_IN, 'Logging In...');
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
if (getPasswordSalt) {
SessionCommands.requestPasswordSalt(options);
} else {
SessionCommands.login();
SessionCommands.login(options);
}
break;
case WebSocketConnectReason.REGISTER:
const passwordSalt = passwordSaltSupported(serverOptions, webClient) ? generateSalt() : null;
SessionCommands.register(passwordSalt);
const passwordSalt = getPasswordSalt ? generateSalt() : null;
SessionCommands.register(options, passwordSalt);
break;
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
if (getPasswordSalt) {
SessionCommands.requestPasswordSalt(options);
} else {
SessionCommands.activateAccount();
SessionCommands.activateAccount(options);
}
break;
case WebSocketConnectReason.PASSWORD_RESET_REQUEST:
SessionCommands.resetPasswordRequest();
SessionCommands.resetPasswordRequest(options);
break;
case WebSocketConnectReason.PASSWORD_RESET_CHALLENGE:
SessionCommands.resetPasswordChallenge();
SessionCommands.resetPasswordChallenge(options);
break;
case WebSocketConnectReason.PASSWORD_RESET:
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
if (getPasswordSalt) {
SessionCommands.requestPasswordSalt(options);
} else {
SessionCommands.resetPassword();
SessionCommands.resetPassword(options);
}
break;
default:
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Reason: ' + webClient.options.reason);
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Reason: ' + options.reason);
SessionCommands.disconnect();
break;
}
webClient.options = {};
SessionPersistence.updateInfo(serverName, serverVersion);
}

View file

@ -89,8 +89,8 @@ export class SessionPersistence {
ServerDispatch.serverMessage(sanitizeHtml(message));
}
static accountAwaitingActivation() {
ServerDispatch.accountAwaitingActivation();
static accountAwaitingActivation(options: WebSocketConnectOptions) {
ServerDispatch.accountAwaitingActivation(options);
}
static accountActivationSuccess() {

View file

@ -32,8 +32,8 @@ export class WebSocketService {
protocol = 'ws';
}
const { host, port, keepalive } = options;
this.keepalive = keepalive;
const { host, port } = options;
this.keepalive = this.webClient.clientOptions.keepalive;
this.socket = this.createWebSocket(`${protocol}://${host}:${port}`);
}