/
githubmirror
/
strapi
Обзор
Документация
Войти
/
githubmirror
/
strapi
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/utils/api-tests/strapi.js
111 строк
3 KB
Nico André
chore(lint): add non-blocking oxlint setup (#26923)
31 июл 2026, 16:56
Не верифицирован
31 июл 2026, 16:56
6469af3
Код
Авторство
О чём код?
'use strict'; const path = require('path'); const _ = require('lodash'); const dotenv = require('dotenv'); const { createStrapi } = require('../../core/strapi'); const { createUtils } = require('./utils'); const superAdminCredentials = { email: 'admin@strapi.io', firstname: 'admin', lastname: 'admin', password: 'Password123', }; const superAdminLoginInfo = _.pick(superAdminCredentials, ['email', 'password']); const createStrapiInstance = async ({ ensureSuperAdmin = true, logLevel = 'warn', bypassAuth = true, bootstrap, register, strapiOptions = {}, /** When false (default), opts out of deprecated expiresIn so tests use new session config defaults. Set true to test legacy/deprecation behavior. */ skipDefaultSessionConfig = false, } = {}) => { // read .env file as it could have been updated dotenv.config({ path: process.env.ENV_PATH }); const baseDir = path.dirname(process.env.ENV_PATH); const options = { appDir: baseDir, distDir: baseDir, autoReload: true, ...strapiOptions, }; const instance = createStrapi(options); // Ensure Koa trusts X-Forwarded-* headers in tests so asHTTPS() can simulate HTTPS instance.config.set('server.proxy.koa', true); // Use the new session config so tests do not trigger the expiresIn deprecation warning. // Set maxRefreshTokenLifespan and maxSessionLifespan (same defaults as session-auth) so // bootstrap sees the new API and does not warn. We do not set expiresIn. if (!skipDefaultSessionConfig) { const hasNewMaxRefresh = instance.config.get('admin.auth.sessions.maxRefreshTokenLifespan') != null; const hasNewMaxSession = instance.config.get('admin.auth.sessions.maxSessionLifespan') != null; if (!hasNewMaxRefresh || !hasNewMaxSession) { const THIRTY_DAYS_SEC = 30 * 24 * 60 * 60; const ONE_DAY_SEC = 24 * 60 * 60; if (!hasNewMaxRefresh) { instance.config.set('admin.auth.sessions.maxRefreshTokenLifespan', THIRTY_DAYS_SEC); } if (!hasNewMaxSession) { instance.config.set('admin.auth.sessions.maxSessionLifespan', ONE_DAY_SEC); } } } if (bypassAuth) { instance.get('auth').register('content-api', { name: 'test-auth', authenticate() { return { authenticated: true }; }, verify() {}, }); } if (bootstrap) { const modules = instance.get('modules'); const originalBootstrap = modules.bootstrap; modules.bootstrap = async () => { await bootstrap({ strapi: instance }); await originalBootstrap(); }; } if (register) { const originalRegister = instance.register.bind(instance); instance.register = async function () { await register({ strapi: instance }); return originalRegister(); }; } await instance.load(); instance.log.level = logLevel; await instance.server.listen(); const utils = createUtils(instance); if (ensureSuperAdmin) { await utils.createUserIfNotExists(superAdminCredentials); } return instance; }; module.exports = { createStrapiInstance, superAdmin: { loginInfo: superAdminLoginInfo, credentials: superAdminCredentials, }, };