Ensure tests support E2EE

This commit is contained in:
Half-Shot 2022-01-18 15:43:49 +00:00
parent 75047fda95
commit 83df9deb6a
2 changed files with 18 additions and 6 deletions

View File

@ -1,7 +1,7 @@
import axios from "axios"; import axios from "axios";
import { HmacSHA1 } from "crypto-js"; import { HmacSHA1 } from "crypto-js";
import e from "express"; import e from "express";
import { LogService, MatrixClient, MemoryStorageProvider, PantalaimonClient } from "matrix-bot-sdk"; import { LogService, MatrixClient, MemoryStorageProvider, PantalaimonClient, RustSdkCryptoStorageProvider } from "matrix-bot-sdk";
import config from "../../src/config"; import config from "../../src/config";
const REGISTRATION_ATTEMPTS = 10; const REGISTRATION_ATTEMPTS = 10;
@ -82,8 +82,13 @@ export async function registerNewTestUser(isAdmin: boolean, label: string = "")
*/ */
export async function newTestUser(isAdmin: boolean = false, label: string = ""): Promise<MatrixClient> { export async function newTestUser(isAdmin: boolean = false, label: string = ""): Promise<MatrixClient> {
const username = await registerNewTestUser(isAdmin, label); const username = await registerNewTestUser(isAdmin, label);
const pantalaimon = new PantalaimonClient(config.homeserverUrl, new MemoryStorageProvider()); if (config.pantalaimon) {
return await pantalaimon.createClientWithCredentials(username, username); const pantalaimon = new PantalaimonClient(config.homeserverUrl, new MemoryStorageProvider());
return await pantalaimon.createClientWithCredentials(username, username);
} else {
const client = new MatrixClient(config.homeserverUrl, config.accessToken, new MemoryStorageProvider(), new RustSdkCryptoStorageProvider(config.dataPath));
client.crypto.prepare(await client.getJoinedRooms());
}
} }
/** /**

View File

@ -19,7 +19,8 @@ import {
MemoryStorageProvider, MemoryStorageProvider,
LogService, LogService,
LogLevel, LogLevel,
RichConsoleLogger RichConsoleLogger,
RustSdkCryptoStorageProvider
} from "matrix-bot-sdk"; } from "matrix-bot-sdk";
import { Mjolnir} from '../../src/Mjolnir'; import { Mjolnir} from '../../src/Mjolnir';
import config from "../../src/config"; import config from "../../src/config";
@ -80,8 +81,14 @@ export async function makeMjolnir(): Promise<Mjolnir> {
LogService.setLogger(new RichConsoleLogger()); LogService.setLogger(new RichConsoleLogger());
LogService.setLevel(LogLevel.fromString(config.logLevel, LogLevel.DEBUG)); LogService.setLevel(LogLevel.fromString(config.logLevel, LogLevel.DEBUG));
LogService.info("test/mjolnirSetupUtils", "Starting bot..."); LogService.info("test/mjolnirSetupUtils", "Starting bot...");
const pantalaimon = new PantalaimonClient(config.homeserverUrl, new MemoryStorageProvider()); let client: MatrixClient;
const client = await pantalaimon.createClientWithCredentials(config.pantalaimon.username, config.pantalaimon.password); if (config.pantalaimon) {
const pantalaimon = new PantalaimonClient(config.homeserverUrl, new MemoryStorageProvider());
client = await pantalaimon.createClientWithCredentials(config.pantalaimon.username, config.pantalaimon.password);
} else {
client = new MatrixClient(config.homeserverUrl, config.accessToken, new MemoryStorageProvider(), new RustSdkCryptoStorageProvider(config.dataPath));
client.crypto.prepare(await client.getJoinedRooms());
}
patchMatrixClient(); patchMatrixClient();
await ensureAliasedRoomExists(client, config.managementRoom); await ensureAliasedRoomExists(client, config.managementRoom);
let mjolnir = await Mjolnir.setupMjolnirFromConfig(client); let mjolnir = await Mjolnir.setupMjolnirFromConfig(client);