feat: revoke token after sensitive operations (#6993)

fix #6914
This commit is contained in:
darkskygit
2024-05-20 06:38:48 +00:00
parent 4c77ffd469
commit df73b6ddc7
5 changed files with 193 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ import { faker } from '@faker-js/faker';
import { hash } from '@node-rs/argon2';
import type { BrowserContext, Cookie, Page } from '@playwright/test';
import { expect } from '@playwright/test';
import type { Assertions } from 'ava';
import { z } from 'zod';
export async function getCurrentMailMessageCount() {
@@ -26,6 +27,19 @@ export async function getLatestMailMessage() {
return data.items[0];
}
export async function getTokenFromLatestMailMessage<A extends Assertions>(
test?: A
) {
const tokenRegex = /token=3D([^"&]+)/;
const emailContent = await getLatestMailMessage();
const tokenMatch = emailContent.Content.Body.match(tokenRegex);
const token = tokenMatch
? decodeURIComponent(tokenMatch[1].replace(/=\r\n/, ''))
: null;
test?.truthy(token);
return token;
}
export async function getLoginCookie(
context: BrowserContext
): Promise<Cookie | undefined> {