1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-28 15:22:05 +03:00

Fix close button on forgot password flow (#12732)

* Fix close button on forgot password flow

The 'x' had escaped out the right of the button for some reason

* Add test that actually opens the dialog in question

* Actually screenshot the right thing

* Unnecessary screenshot
This commit is contained in:
David Baker
2024-07-05 10:51:21 +01:00
committed by GitHub
parent 2f953f1d0f
commit 06117695bc
8 changed files with 141 additions and 17 deletions

View File

@ -39,6 +39,15 @@ export interface HomeserverInstance {
* @param password login password
*/
loginUser(userId: string, password: string): Promise<Credentials>;
/**
* Sets a third party identifier for the given user. This only supports setting a single 3pid and will
* replace any others.
* @param userId The full ID of the user to edit (as returned from registerUser)
* @param medium The medium of the 3pid to set
* @param address The address of the 3pid to set
*/
setThreepid(userId: string, medium: string, address: string): Promise<void>;
}
export interface StartHomeserverOpts {

View File

@ -94,6 +94,8 @@ export class Synapse implements Homeserver, HomeserverInstance {
protected docker: Docker = new Docker();
public config: HomeserverConfig & { serverId: string };
private adminToken?: string;
public constructor(private readonly request: APIRequestContext) {}
/**
@ -152,12 +154,17 @@ export class Synapse implements Homeserver, HomeserverInstance {
return [path.join(synapseLogsPath, "stdout.log"), path.join(synapseLogsPath, "stderr.log")];
}
public async registerUser(username: string, password: string, displayName?: string): Promise<Credentials> {
private async registerUserInternal(
username: string,
password: string,
displayName?: string,
admin = false,
): Promise<Credentials> {
const url = `${this.config.baseUrl}/_synapse/admin/v1/register`;
const { nonce } = await this.request.get(url).then((r) => r.json());
const mac = crypto
.createHmac("sha1", this.config.registrationSecret)
.update(`${nonce}\0${username}\0${password}\0notadmin`)
.update(`${nonce}\0${username}\0${password}\0${admin ? "" : "not"}admin`)
.digest("hex");
const res = await this.request.post(url, {
data: {
@ -165,7 +172,7 @@ export class Synapse implements Homeserver, HomeserverInstance {
username,
password,
mac,
admin: false,
admin,
displayname: displayName,
},
});
@ -185,6 +192,10 @@ export class Synapse implements Homeserver, HomeserverInstance {
};
}
public registerUser(username: string, password: string, displayName?: string): Promise<Credentials> {
return this.registerUserInternal(username, password, displayName, false);
}
public async loginUser(userId: string, password: string): Promise<Credentials> {
const url = `${this.config.baseUrl}/_matrix/client/v3/login`;
const res = await this.request.post(url, {
@ -207,4 +218,30 @@ export class Synapse implements Homeserver, HomeserverInstance {
homeServer: json.home_server,
};
}
public async setThreepid(userId: string, medium: string, address: string): Promise<void> {
if (this.adminToken === undefined) {
const result = await this.registerUserInternal("admin", "totalyinsecureadminpassword", undefined, true);
this.adminToken = result.accessToken;
}
const url = `${this.config.baseUrl}/_synapse/admin/v2/users/${userId}`;
const res = await this.request.put(url, {
data: {
threepids: [
{
medium,
address,
},
],
},
headers: {
Authorization: `Bearer ${this.adminToken}`,
},
});
if (!res.ok()) {
throw await res.json();
}
}
}