96dc79cfe6
- Convert all require()/module.exports to import/export across 260+ files - Add "type": "module" to package.json to enable ESM by default - Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible - Convert eslint.config.js to ESM with sourceType: "module" - Replace __dirname/__filename with import.meta.dirname/import.meta.filename - Replace require.main === module with process.argv[1] === import.meta.filename - Remove 'use strict' directives (implicit in ESM) - Convert dynamic require() in switch statements to static import lookup maps (dns.js, domains.js, backupformats.js, backupsites.js, network.js) - Extract self-referencing exports.CONSTANT patterns into standalone const declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.) - Lazify SERVICES object in services.js to avoid circular dependency TDZ issues - Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests - Add _setMockApp() to ldapserver.js for ESM-safe test mocking - Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests - Convert backupupload.js to use dynamic imports so --check exits before loading the module graph (which requires BOX_ENV) - Update check-install to use ESM import for infra_version.js - Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations) - All 1315 tests passing Migration stats (AI-assisted using Cursor with Claude): - Wall clock time: ~3-4 hours - Assistant completions: ~80-100 - Estimated token usage: ~1-2M tokens Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
3.0 KiB
JavaScript
70 lines
3.0 KiB
JavaScript
/* global it:false */
|
|
|
|
import * as appstore from '../appstore.js';
|
|
import BoxError from '../boxerror.js';
|
|
import * as common from './common.js';
|
|
import expect from 'expect.js';
|
|
import nock from 'nock';
|
|
import * as provision from '../provision.js';
|
|
import safe from 'safetydance';
|
|
|
|
/* global describe:false */
|
|
/* global before:false */
|
|
/* global after:false */
|
|
|
|
describe('Provision', function () {
|
|
const { domainSetup, auditSource, cleanup } = common;
|
|
|
|
describe('Activate', function () {
|
|
before(async function () {
|
|
await domainSetup();
|
|
if (!nock.isActive()) nock.activate();
|
|
});
|
|
after(cleanup);
|
|
|
|
it('cannot activate when appstore unreachable', async function () {
|
|
const [error] = await safe(provision.activate('username', 'password', 'test@cloudron.io', 'Some Name', '1.2.3.4', auditSource));
|
|
expect(error.reason).to.be(BoxError.NETWORK_ERROR);
|
|
});
|
|
|
|
it('cannot activate with non-201', async function () {
|
|
const scope1 = nock(await appstore.getApiServerOrigin())
|
|
.post('/api/v1/register_cloudron3', (body) => typeof body.domain === 'string' && typeof body.version === 'string')
|
|
.reply(401, {});
|
|
|
|
const [error] = await safe(provision.activate('username', 'password', 'test@cloudron.io', 'Some Name', '1.2.3.4', auditSource));
|
|
expect(error.reason).to.be(BoxError.EXTERNAL_ERROR);
|
|
expect(scope1.isDone()).to.be.ok();
|
|
scope1.persist(false);
|
|
});
|
|
|
|
it('cannot activate with incorrect fields', async function () {
|
|
const scope1 = nock(await appstore.getApiServerOrigin())
|
|
.post('/api/v1/register_cloudron3', (body) => typeof body.domain === 'string' && typeof body.version === 'string')
|
|
.reply(201, { id: '32' });
|
|
|
|
const [error] = await safe(provision.activate('username', 'password', 'test@cloudron.io', 'Some Name', '1.2.3.4', auditSource));
|
|
expect(error.reason).to.be(BoxError.EXTERNAL_ERROR);
|
|
expect(scope1.isDone()).to.be.ok();
|
|
scope1.persist(false);
|
|
});
|
|
|
|
it('can activate with correct fields', async function () {
|
|
const scope1 = nock(await appstore.getApiServerOrigin())
|
|
.post('/api/v1/register_cloudron3', (body) => typeof body.domain === 'string' && typeof body.version === 'string')
|
|
.reply(201, { cloudronId: '32', cloudronToken: 'xx' });
|
|
|
|
const scope2 = nock(await appstore.getApiServerOrigin())
|
|
.post('/api/v1/subscription3?accessToken=xx', (body) => typeof body.state === 'object' && typeof body.state.userCount === 'number')
|
|
.reply(200, { features: {} });
|
|
|
|
await provision.activate('username', 'password', 'test@cloudron.io', 'Some Name', '1.2.3.4', auditSource);
|
|
expect(scope1.isDone()).to.be.ok();
|
|
scope1.persist(false);
|
|
|
|
expect(scope2.isDone()).to.be.ok();
|
|
scope2.persist(false);
|
|
});
|
|
});
|
|
});
|