This repository has been archived on 2025-04-22. You can view files and clone it, but cannot push or open issues or pull requests.
hlk_autotest/tests/common/auth.ts
2024-12-29 21:51:02 +08:00

52 lines
1.5 KiB
TypeScript

import { getEnvVar } from '@/utils/envUtils';
import { readFileSync } from 'fs';
const authConfig = {
authFilePath: '.auth/',
indexedDBFilePath: '.auth/',
};
class AuthAccount {
account: string;
password: string;
authFile: string;
indexedDBFile: string;
constructor(account: string, password: string, authFile: string, indexedDBFile: string) {
this.account = account;
this.password = password;
this.authFile = authFile;
this.indexedDBFile = indexedDBFile;
}
static loadIndexedDBFile(account: string, accountArray: AuthAccount[]) {
try {
for (const item of accountArray) {
if (item.account === account) {
return JSON.parse(readFileSync(item.indexedDBFile, 'utf-8'));
}
}
} catch (e) {
throw new Error('indexedDB文件读取失败');
}
throw new Error('未找到该账户');
}
}
const firstAccount = new AuthAccount(
getEnvVar('boss_account'),
getEnvVar('boss_password'),
`${authConfig.authFilePath}${getEnvVar('boss_account')}.json`,
`${authConfig.indexedDBFilePath}${getEnvVar('boss_account')}_indexedDB.json`,
);
const secondAccount = new AuthAccount(
getEnvVar('boss_account_2'),
getEnvVar('boss_password_2'),
`${authConfig.authFilePath}${getEnvVar('boss_account_2')}.json`,
`${authConfig.indexedDBFilePath}${getEnvVar('boss_account_2')}_indexedDB.json`,
);
export { firstAccount, secondAccount, AuthAccount };