Skip to content

Commit fb83e3e

Browse files
committed
make accessToken optional instead of using empty string
1 parent b09f67c commit fb83e3e

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

playwright/e2e/settings/encryption-user-tab/encryption-tab.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test.describe("Encryption tab", () => {
2626
test.beforeEach(async ({ page, homeserver, credentials }) => {
2727
// The bot bootstraps cross-signing, creates a key backup and sets up a recovery key
2828
const botCredentials = { ...credentials };
29-
botCredentials.accessToken = ""; // use a new login for the bot
29+
delete botCredentials.accessToken; // use a new login for the bot
3030
const res = await createBot(page, homeserver, botCredentials);
3131
recoveryKey = res.recoveryKey;
3232
expectedBackupVersion = res.expectedBackupVersion;

playwright/e2e/settings/encryption-user-tab/recovery.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test.describe("Recovery section in Encryption tab", () => {
1818
test.beforeEach(async ({ page, homeserver, credentials }) => {
1919
// The bot bootstraps cross-signing, creates a key backup and sets up a recovery key
2020
const botCredentials = { ...credentials };
21-
botCredentials.accessToken = ""; // use a new login for the bot
21+
delete botCredentials.accessToken; // use a new login for the bot
2222
const res = await createBot(page, homeserver, botCredentials);
2323
recoveryKey = res.recoveryKey;
2424
});

playwright/pages/bot.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import type { Credentials, HomeserverInstance } from "../plugins/homeserver";
1616
import type { GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
1717
import { bootstrapCrossSigningForClient, Client } from "./client";
1818

19+
export interface CredentialsOptionalAccessToken extends Omit<Credentials, "accessToken"> {
20+
accessToken?: string;
21+
}
22+
1923
export interface CreateBotOpts {
2024
/**
2125
* A prefix to use for the userid. If unspecified, "bot_" will be used.
@@ -58,7 +62,7 @@ const defaultCreateBotOptions = {
5862
type ExtendedMatrixClient = MatrixClient & { __playwright_recovery_key: GeneratedSecretStorageKey };
5963

6064
export class Bot extends Client {
61-
public credentials?: Credentials;
65+
public credentials?: CredentialsOptionalAccessToken;
6266
private handlePromise: Promise<JSHandle<ExtendedMatrixClient>>;
6367

6468
constructor(
@@ -73,13 +77,13 @@ export class Bot extends Client {
7377
/**
7478
* Set the credentials used by the bot.
7579
*
76-
* If `credentials.accessToken` is set to the empty string, then
77-
* `buildClient` will log in a new session. Note that `getCredentials`
78-
* will return the credentials passed to this function, rather than
79-
* the updated credentials from the new login. In particular, the
80-
* `accessToken` and `deviceId` will not be updated.
80+
* If `credentials.accessToken` is unset, then `buildClient` will log in a
81+
* new session. Note that `getCredentials` will return the credentials
82+
* passed to this function, rather than the updated credentials from the new
83+
* login. In particular, the `accessToken` and `deviceId` will not be
84+
* updated.
8185
*/
82-
public setCredentials(credentials: Credentials): void {
86+
public setCredentials(credentials: CredentialsOptionalAccessToken): void {
8387
if (this.credentials) throw new Error("Bot has already started");
8488
this.credentials = credentials;
8589
}
@@ -89,7 +93,7 @@ export class Bot extends Client {
8993
return client.evaluate((cli) => cli.__playwright_recovery_key);
9094
}
9195

92-
private async getCredentials(): Promise<Credentials> {
96+
private async getCredentials(): Promise<CredentialsOptionalAccessToken> {
9397
if (this.credentials) return this.credentials;
9498
// We want to pad the uniqueId but not the prefix
9599
const username =
@@ -170,7 +174,7 @@ export class Bot extends Client {
170174
getSecretStorageKey,
171175
};
172176

173-
if (!credentials.accessToken) {
177+
if ("accessToken" in credentials) {
174178
const loginCli = new window.matrixcs.MatrixClient({
175179
baseUrl,
176180
store: new window.matrixcs.MemoryStore(),

playwright/pages/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type {
2828
EmptyObject,
2929
} from "matrix-js-sdk/src/matrix";
3030
import type { RoomMessageEventContent } from "matrix-js-sdk/src/types";
31-
import { type Credentials } from "../plugins/homeserver";
31+
import { type CredentialsOptionalAccessToken } from "./bot";
3232

3333
export class Client {
3434
public network: Network;
@@ -424,7 +424,7 @@ export class Client {
424424
/**
425425
* Bootstraps cross-signing.
426426
*/
427-
public async bootstrapCrossSigning(credentials: Credentials): Promise<void> {
427+
public async bootstrapCrossSigning(credentials: CredentialsOptionalAccessToken): Promise<void> {
428428
const client = await this.prepareClient();
429429
return bootstrapCrossSigningForClient(client, credentials);
430430
}
@@ -522,7 +522,7 @@ export class Client {
522522
*/
523523
export function bootstrapCrossSigningForClient(
524524
client: JSHandle<MatrixClient>,
525-
credentials: Credentials,
525+
credentials: CredentialsOptionalAccessToken,
526526
resetKeys: boolean = false,
527527
) {
528528
return client.evaluate(

0 commit comments

Comments
 (0)