You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-30 04:23:07 +03:00
Support for MSC2457 logout_devices param for setPassword() (#2285)
This commit is contained in:
@ -1056,4 +1056,57 @@ describe("MatrixClient", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("setPassword", () => {
|
||||
const auth = { session: 'abcdef', type: 'foo' };
|
||||
const newPassword = 'newpassword';
|
||||
const callback = () => {};
|
||||
|
||||
const passwordTest = (expectedRequestContent: any, expectedCallback?: Function) => {
|
||||
const [callback, method, path, queryParams, requestContent] = client.http.authedRequest.mock.calls[0];
|
||||
if (expectedCallback) {
|
||||
expect(callback).toBe(expectedCallback);
|
||||
} else {
|
||||
expect(callback).toBeFalsy();
|
||||
}
|
||||
expect(method).toBe('POST');
|
||||
expect(path).toEqual('/account/password');
|
||||
expect(queryParams).toBeFalsy();
|
||||
expect(requestContent).toEqual(expectedRequestContent);
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
client.http.authedRequest.mockClear().mockResolvedValue({});
|
||||
});
|
||||
|
||||
it("no logout_devices specified", async () => {
|
||||
await client.setPassword(auth, newPassword);
|
||||
passwordTest({ auth, new_password: newPassword });
|
||||
});
|
||||
|
||||
it("no logout_devices specified + callback", async () => {
|
||||
await client.setPassword(auth, newPassword, callback);
|
||||
passwordTest({ auth, new_password: newPassword }, callback);
|
||||
});
|
||||
|
||||
it("overload logoutDevices=true", async () => {
|
||||
await client.setPassword(auth, newPassword, true);
|
||||
passwordTest({ auth, new_password: newPassword, logout_devices: true });
|
||||
});
|
||||
|
||||
it("overload logoutDevices=true + callback", async () => {
|
||||
await client.setPassword(auth, newPassword, true, callback);
|
||||
passwordTest({ auth, new_password: newPassword, logout_devices: true }, callback);
|
||||
});
|
||||
|
||||
it("overload logoutDevices=false", async () => {
|
||||
await client.setPassword(auth, newPassword, false);
|
||||
passwordTest({ auth, new_password: newPassword, logout_devices: false });
|
||||
});
|
||||
|
||||
it("overload logoutDevices=false + callback", async () => {
|
||||
await client.setPassword(auth, newPassword, false, callback);
|
||||
passwordTest({ auth, new_password: newPassword, logout_devices: false }, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -7819,18 +7819,45 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* Make a request to change your password.
|
||||
* @param {Object} authDict
|
||||
* @param {string} newPassword The new desired password.
|
||||
* @param {boolean} logoutDevices Should all sessions be logged out after the password change. Defaults to true.
|
||||
* @param {module:client.callback} callback Optional.
|
||||
* @return {Promise} Resolves: TODO
|
||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||
*/
|
||||
public setPassword(authDict: any, newPassword: string, callback?: Callback): Promise<any> { // TODO: Types
|
||||
public setPassword(
|
||||
authDict: any,
|
||||
newPassword: string,
|
||||
callback?: Callback,
|
||||
): Promise<{}>;
|
||||
public setPassword(
|
||||
authDict: any,
|
||||
newPassword: string,
|
||||
logoutDevices: boolean,
|
||||
callback?: Callback,
|
||||
): Promise<{}>;
|
||||
public setPassword(
|
||||
authDict: any,
|
||||
newPassword: string,
|
||||
logoutDevices?: Callback | boolean,
|
||||
callback?: Callback,
|
||||
): Promise<{}> {
|
||||
if (typeof logoutDevices === 'function') {
|
||||
callback = logoutDevices;
|
||||
}
|
||||
if (typeof logoutDevices !== 'boolean') {
|
||||
// Use backwards compatible behaviour of not specifying logout_devices
|
||||
// This way it is left up to the server:
|
||||
logoutDevices = undefined;
|
||||
}
|
||||
|
||||
const path = "/account/password";
|
||||
const data = {
|
||||
'auth': authDict,
|
||||
'new_password': newPassword,
|
||||
'logout_devices': logoutDevices,
|
||||
};
|
||||
|
||||
return this.http.authedRequest(
|
||||
return this.http.authedRequest<{}>(
|
||||
callback, Method.Post, path, null, data,
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user