Skip to content

Commit 7fa4148

Browse files
committed
add cleanup function in test using udata command
1 parent b22a9f4 commit 7fa4148

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tests/auth.2fa-user.spec.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { test, expect } from '@playwright/test'
22
import { generateSync } from 'otplib'
3+
import { exec } from 'child_process'
4+
5+
const TWOFA_EMAIL = '[email protected]'
6+
const TWOFA_PASSWORD = '@1337Password42'
37

48
test.describe('2FA Authentication Flow', () => {
59
// Test credentials for 2FA setup flow
6-
const TWOFA_EMAIL = '[email protected]'
7-
const TWOFA_PASSWORD = '@1337Password42'
810

911
test.beforeEach(async ({ page, baseURL }) => {
1012
// clean any existing session
@@ -101,3 +103,21 @@ test.describe('2FA Authentication Flow', () => {
101103
await expect(page).toHaveURL(`${loginURL}/`)
102104
})
103105
})
106+
107+
test.afterAll(async () => {
108+
await new Promise((resolve, reject) => {
109+
// We need to run the udata command since a user can't unset its 2FA.
110+
// Using uvx as we may not be located in the correct workspace, uses latest pypi udata version.
111+
// We don't use any udata.cfg.
112+
exec(`uvx --with udata udata user unset-two-factor ${TWOFA_EMAIL}`, (error, stdout) => {
113+
if (error) {
114+
console.error(`Error running udata command cleanup : ${error.message}`)
115+
reject(error)
116+
}
117+
else {
118+
console.log(`udata command cleanup output : ${stdout}`)
119+
resolve(null)
120+
}
121+
})
122+
})
123+
})

0 commit comments

Comments
 (0)