server-api-token-inbound-auth.test.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. import assert from 'node:assert/strict';
  2. import { spawn, spawnSync } from 'node:child_process';
  3. import { mkdtempSync } from 'node:fs';
  4. import net from 'node:net';
  5. import { tmpdir } from 'node:os';
  6. import path from 'node:path';
  7. import process from 'node:process';
  8. import { test } from 'node:test';
  9. test('API tokens enforce inbound mailbox scope and keep token management session-only', async (t) => {
  10. const fixture = await startTestServer();
  11. try {
  12. const seeded = seedInboundAccessFixtures(fixture.dataDir, fixture.sessionSecret);
  13. const adminCookie = await login(fixture.baseUrl, 'admin', 'password123');
  14. const securityAdminCookie = await login(fixture.baseUrl, 'token-security-admin', 'password123');
  15. const aliceCookie = await login(fixture.baseUrl, 'token-alice', 'password123');
  16. const bobCookie = await login(fixture.baseUrl, 'token-bob', 'password123');
  17. const sendOnly = await createToken(fixture.baseUrl, aliceCookie, {
  18. name: 'alice send only',
  19. scopes: ['send']
  20. });
  21. const aliceOwner = await createToken(fixture.baseUrl, aliceCookie, {
  22. name: 'alice owner messages',
  23. scopes: ['messages:read'],
  24. mailboxAccess: 'owner'
  25. });
  26. const aliceSelected = await createToken(fixture.baseUrl, aliceCookie, {
  27. name: 'alice selected messages',
  28. scopes: ['messages:read', 'mailboxes:read'],
  29. mailboxAccess: 'selected',
  30. mailboxIds: [seeded.alicePrimaryMailboxId]
  31. });
  32. const adminSelected = await createToken(fixture.baseUrl, adminCookie, {
  33. name: 'admin selected bob',
  34. scopes: ['messages:read', 'mailboxes:read'],
  35. mailboxAccess: 'selected',
  36. mailboxIds: [seeded.bobMailboxId]
  37. });
  38. const adminAll = await createToken(fixture.baseUrl, adminCookie, {
  39. name: 'admin all messages',
  40. scopes: ['messages:read', 'mailboxes:read'],
  41. mailboxAccess: 'all'
  42. });
  43. await t.test('Bearer message reads are scope-limited, isolated, and read-only', async () => {
  44. const deniedByScope = await requestJson(fixture.baseUrl, '/api/inbound-messages', {
  45. bearer: sendOnly.token
  46. });
  47. assert.equal(deniedByScope.status, 403);
  48. assert.match(deniedByScope.body.error, /messages:read/);
  49. const ownerList = await requestJson(fixture.baseUrl, '/api/inbound-messages?page=1&pageSize=100', {
  50. bearer: aliceOwner.token
  51. });
  52. assert.equal(ownerList.status, 200);
  53. assert.equal(ownerList.body.total, 2);
  54. assert.deepEqual(
  55. new Set(ownerList.body.messages.map((message) => message.mailboxId)),
  56. new Set([seeded.alicePrimaryMailboxId, seeded.aliceSecondaryMailboxId])
  57. );
  58. assert.equal(ownerList.body.messages.some((message) => message.mailboxId === seeded.bobMailboxId), false);
  59. const ownerCrossUserFilter = await requestJson(
  60. fixture.baseUrl,
  61. `/api/inbound-messages?mailboxId=${seeded.bobMailboxId}`,
  62. { bearer: aliceOwner.token }
  63. );
  64. assert.equal(ownerCrossUserFilter.status, 200);
  65. assert.equal(ownerCrossUserFilter.body.total, 0);
  66. assert.deepEqual(ownerCrossUserFilter.body.messages, []);
  67. const selectedList = await requestJson(fixture.baseUrl, '/api/inbound-messages?page=1&pageSize=100', {
  68. bearer: aliceSelected.token
  69. });
  70. assert.equal(selectedList.status, 200);
  71. assert.equal(selectedList.body.total, 1);
  72. assert.deepEqual(selectedList.body.messages.map((message) => message.id), [seeded.alicePrimaryMessageId]);
  73. const selectedMailboxes = await requestJson(fixture.baseUrl, '/api/mailboxes', {
  74. bearer: aliceSelected.token
  75. });
  76. assert.equal(selectedMailboxes.status, 200);
  77. assert.deepEqual(selectedMailboxes.body.mailboxes.map((mailbox) => mailbox.id), [seeded.alicePrimaryMailboxId]);
  78. const selectedUnlistedFilter = await requestJson(
  79. fixture.baseUrl,
  80. `/api/inbound-messages?mailboxId=${seeded.aliceSecondaryMailboxId}`,
  81. { bearer: aliceSelected.token }
  82. );
  83. assert.equal(selectedUnlistedFilter.status, 200);
  84. assert.equal(selectedUnlistedFilter.body.total, 0);
  85. const selectedAuthorizedDetail = await requestJson(
  86. fixture.baseUrl,
  87. `/api/inbound-messages/${seeded.alicePrimaryMessageId}`,
  88. { bearer: aliceSelected.token }
  89. );
  90. assert.equal(selectedAuthorizedDetail.status, 200);
  91. assert.equal(selectedAuthorizedDetail.body.message.subject, 'Alice primary message');
  92. for (const [pathname, bearer] of [
  93. [`/api/inbound-messages/${seeded.bobMessageId}`, aliceOwner.token],
  94. [`/api/inbound-messages/${seeded.aliceSecondaryMessageId}`, aliceSelected.token],
  95. [`/api/inbound-mailboxes/${seeded.bobMailboxId}/folders`, aliceOwner.token],
  96. [`/api/inbound-mailboxes/${seeded.aliceSecondaryMailboxId}/folders`, aliceSelected.token]
  97. ]) {
  98. const hidden = await requestJson(fixture.baseUrl, pathname, { bearer });
  99. assert.equal(hidden.status, 404, pathname);
  100. }
  101. const adminSelectedList = await requestJson(fixture.baseUrl, '/api/inbound-messages?pageSize=100', {
  102. bearer: adminSelected.token
  103. });
  104. assert.equal(adminSelectedList.status, 200);
  105. assert.equal(adminSelectedList.body.total, 1);
  106. assert.deepEqual(adminSelectedList.body.messages.map((message) => message.id), [seeded.bobMessageId]);
  107. const adminSelectedMailboxes = await requestJson(fixture.baseUrl, '/api/mailboxes', {
  108. bearer: adminSelected.token
  109. });
  110. assert.equal(adminSelectedMailboxes.status, 200);
  111. assert.deepEqual(adminSelectedMailboxes.body.mailboxes.map((mailbox) => mailbox.id), [seeded.bobMailboxId]);
  112. const adminSelectedDetail = await requestJson(
  113. fixture.baseUrl,
  114. `/api/inbound-messages/${seeded.bobMessageId}`,
  115. { bearer: adminSelected.token }
  116. );
  117. assert.equal(adminSelectedDetail.status, 200);
  118. assert.equal(adminSelectedDetail.body.message.subject, 'Bob private message');
  119. const adminAllList = await requestJson(fixture.baseUrl, '/api/inbound-messages?pageSize=100', {
  120. bearer: adminAll.token
  121. });
  122. assert.equal(adminAllList.status, 200);
  123. assert.equal(adminAllList.body.total, 4);
  124. assert.equal(adminAllList.body.messages.length, 4);
  125. const adminAllMailboxList = await requestJson(fixture.baseUrl, '/api/mailboxes', {
  126. bearer: adminAll.token
  127. });
  128. assert.equal(adminAllMailboxList.status, 200);
  129. assert.equal(adminAllMailboxList.body.mailboxes.length, 4);
  130. const deniedMutation = await requestJson(
  131. fixture.baseUrl,
  132. `/api/inbound-messages/${seeded.alicePrimaryMessageId}`,
  133. {
  134. method: 'PATCH',
  135. bearer: aliceSelected.token,
  136. body: { read: true }
  137. }
  138. );
  139. assert.equal(deniedMutation.status, 401);
  140. const unchanged = await requestJson(
  141. fixture.baseUrl,
  142. `/api/inbound-messages/${seeded.alicePrimaryMessageId}`,
  143. { cookie: aliceCookie }
  144. );
  145. assert.equal(unchanged.status, 200);
  146. assert.equal(unchanged.body.message.read, false);
  147. });
  148. await t.test('session token management reveals recoverable values and enforces admin-only all-mailbox access', async () => {
  149. const aliceTokens = await requestJson(fixture.baseUrl, '/api/api-tokens', { cookie: aliceCookie });
  150. assert.equal(aliceTokens.status, 200);
  151. assert.match(aliceTokens.response.headers.get('cache-control') || '', /no-store/i);
  152. for (const created of [sendOnly, aliceOwner, aliceSelected]) {
  153. const listed = aliceTokens.body.tokens.find((token) => token.id === created.id);
  154. assert.ok(listed, created.name);
  155. assert.equal(listed.tokenRecoverable, true);
  156. assert.equal(listed.token, created.token);
  157. }
  158. const adminTokens = await requestJson(fixture.baseUrl, '/api/api-tokens', { cookie: adminCookie });
  159. assert.equal(adminTokens.status, 200);
  160. assert.match(adminTokens.response.headers.get('cache-control') || '', /no-store/i);
  161. const historical = adminTokens.body.tokens.find((token) => token.id === seeded.historicalTokenId);
  162. assert.ok(historical);
  163. assert.equal(historical.name, 'historical unrecoverable');
  164. assert.equal(historical.tokenRecoverable, false);
  165. assert.equal(Object.hasOwn(historical, 'token'), false);
  166. const basicAdminTokens = await requestJson(fixture.baseUrl, '/api/api-tokens', {
  167. basic: ['admin', 'password123']
  168. });
  169. assert.equal(basicAdminTokens.status, 200);
  170. assert.equal(basicAdminTokens.body.tokens.every((token) => !Object.hasOwn(token, 'token')), true);
  171. const ordinaryAll = await requestJson(fixture.baseUrl, '/api/api-tokens', {
  172. method: 'POST',
  173. cookie: aliceCookie,
  174. body: {
  175. name: 'ordinary all denied',
  176. scopes: ['messages:read'],
  177. mailboxAccess: 'all'
  178. }
  179. });
  180. assert.equal(ordinaryAll.status, 400);
  181. assert.match(ordinaryAll.body.error, /管理员/);
  182. const ordinaryCrossUserSelected = await requestJson(fixture.baseUrl, '/api/api-tokens', {
  183. method: 'POST',
  184. cookie: aliceCookie,
  185. body: {
  186. name: 'ordinary cross-user selected denied',
  187. scopes: ['messages:read'],
  188. mailboxAccess: 'selected',
  189. mailboxIds: [seeded.bobMailboxId]
  190. }
  191. });
  192. assert.equal(ordinaryCrossUserSelected.status, 400);
  193. assert.match(ordinaryCrossUserSelected.body.error, /不存在|无权访问/);
  194. const adminAllMailboxes = await requestJson(fixture.baseUrl, '/api/inbound-mailboxes?all=true', {
  195. cookie: adminCookie
  196. });
  197. assert.equal(adminAllMailboxes.status, 200);
  198. assert.equal(adminAllMailboxes.body.mailboxes.length, 4);
  199. assert.deepEqual(
  200. new Set(adminAllMailboxes.body.mailboxes.map((mailbox) => mailbox.id)),
  201. new Set([
  202. seeded.adminMailboxId,
  203. seeded.alicePrimaryMailboxId,
  204. seeded.aliceSecondaryMailboxId,
  205. seeded.bobMailboxId
  206. ])
  207. );
  208. const ordinaryAllMailboxes = await requestJson(fixture.baseUrl, '/api/inbound-mailboxes?all=true', {
  209. cookie: bobCookie
  210. });
  211. assert.equal(ordinaryAllMailboxes.status, 403);
  212. const basicAdminAllMailboxes = await requestJson(fixture.baseUrl, '/api/inbound-mailboxes?all=true', {
  213. basic: ['admin', 'password123']
  214. });
  215. assert.equal(basicAdminAllMailboxes.status, 403);
  216. const rotated = await requestJson(fixture.baseUrl, `/api/api-tokens/${aliceOwner.id}/rotate`, {
  217. method: 'POST',
  218. cookie: aliceCookie
  219. });
  220. assert.equal(rotated.status, 200);
  221. assert.match(rotated.response.headers.get('cache-control') || '', /no-store/i);
  222. assert.equal(rotated.body.token.id, aliceOwner.id);
  223. assert.equal(rotated.body.token.tokenRecoverable, true);
  224. assert.ok(rotated.body.token.token);
  225. assert.notEqual(rotated.body.token.token, aliceOwner.token);
  226. const oldTokenRejected = await requestJson(fixture.baseUrl, '/api/inbound-messages', {
  227. bearer: aliceOwner.token
  228. });
  229. assert.equal(oldTokenRejected.status, 401);
  230. const newTokenAccepted = await requestJson(fixture.baseUrl, '/api/inbound-messages?pageSize=100', {
  231. bearer: rotated.body.token.token
  232. });
  233. assert.equal(newTokenAccepted.status, 200);
  234. assert.equal(newTokenAccepted.body.total, 2);
  235. const listAfterRotate = await requestJson(fixture.baseUrl, '/api/api-tokens', { cookie: aliceCookie });
  236. const rotatedSummary = listAfterRotate.body.tokens.find((token) => token.id === aliceOwner.id);
  237. assert.equal(rotatedSummary.token, rotated.body.token.token);
  238. assert.notEqual(rotatedSummary.token, aliceOwner.token);
  239. const demoted = await requestJson(fixture.baseUrl, `/api/admin/users/${seeded.adminUserId}`, {
  240. method: 'PATCH',
  241. cookie: securityAdminCookie,
  242. body: { role: 'user' }
  243. });
  244. assert.equal(demoted.status, 200);
  245. assert.equal(demoted.body.user.role, 'user');
  246. const allMessagesAfterDemotion = await requestJson(fixture.baseUrl, '/api/inbound-messages', {
  247. bearer: adminAll.token
  248. });
  249. assert.equal(allMessagesAfterDemotion.status, 200);
  250. assert.equal(allMessagesAfterDemotion.body.total, 0);
  251. const allMailboxesAfterDemotion = await requestJson(fixture.baseUrl, '/api/mailboxes', {
  252. bearer: adminAll.token
  253. });
  254. assert.equal(allMailboxesAfterDemotion.status, 200);
  255. assert.deepEqual(allMailboxesAfterDemotion.body.mailboxes, []);
  256. });
  257. } finally {
  258. fixture.child.kill('SIGTERM');
  259. await waitForExit(fixture.child, 1000);
  260. }
  261. });
  262. async function createToken(baseUrl, cookie, input) {
  263. const result = await requestJson(baseUrl, '/api/api-tokens', {
  264. method: 'POST',
  265. cookie,
  266. body: input
  267. });
  268. assert.equal(result.status, 201, JSON.stringify(result.body));
  269. assert.match(result.response.headers.get('cache-control') || '', /no-store/i);
  270. assert.ok(result.body.token.token);
  271. return result.body.token;
  272. }
  273. function seedInboundAccessFixtures(dataDir, sessionSecret) {
  274. const script = `
  275. import { DatabaseSync } from 'node:sqlite';
  276. import path from 'node:path';
  277. import {
  278. createApiToken,
  279. createDomain,
  280. createInboundMailbox,
  281. createInboundMessage,
  282. createUser,
  283. getUserByLogin,
  284. initDatabase
  285. } from './src/db.js';
  286. initDatabase(process.env.DATA_DIR, process.env.SESSION_SECRET);
  287. const admin = getUserByLogin('admin');
  288. const alice = createUser({
  289. username: 'token-alice',
  290. email: 'token-alice@example.test',
  291. password: 'password123',
  292. status: 'active'
  293. });
  294. const bob = createUser({
  295. username: 'token-bob',
  296. email: 'token-bob@example.test',
  297. password: 'password123',
  298. status: 'active'
  299. });
  300. createUser({
  301. username: 'token-security-admin',
  302. email: 'token-security-admin@example.test',
  303. password: 'password123',
  304. role: 'admin',
  305. status: 'active'
  306. });
  307. const createUserDomain = (user, name) => createDomain(user.id, {
  308. domain: name,
  309. selector: 'mh',
  310. verificationToken: 'verify-' + name,
  311. dkimPublic: 'public-' + name,
  312. dkimPrivate: 'private-' + name,
  313. senderHost: 'mail.' + name,
  314. sendingIp: '127.0.0.1',
  315. spfExtra: '',
  316. dmarcPolicy: 'none',
  317. dmarcRua: ''
  318. });
  319. createUserDomain(admin, 'token-admin.example');
  320. createUserDomain(alice, 'token-alice.example');
  321. createUserDomain(bob, 'token-bob.example');
  322. const adminMailbox = createInboundMailbox(admin.id, {
  323. address: 'inbox@token-admin.example',
  324. password: 'mailbox-password'
  325. });
  326. const alicePrimaryMailbox = createInboundMailbox(alice.id, {
  327. address: 'primary@token-alice.example',
  328. password: 'mailbox-password'
  329. });
  330. const aliceSecondaryMailbox = createInboundMailbox(alice.id, {
  331. address: 'secondary@token-alice.example',
  332. password: 'mailbox-password'
  333. });
  334. const bobMailbox = createInboundMailbox(bob.id, {
  335. address: 'inbox@token-bob.example',
  336. password: 'mailbox-password'
  337. });
  338. const createMessage = (mailbox, subject, sequence) => createInboundMessage(mailbox, {
  339. sender: 'sender@example.net',
  340. recipients: [mailbox.address],
  341. subject,
  342. messageId: '<token-inbound-' + sequence + '@example.net>',
  343. rawMessage: 'Subject: ' + subject + '\\r\\n\\r\\n' + subject,
  344. textBody: subject,
  345. receivedAt: '2026-07-14T0' + sequence + ':00:00.000Z'
  346. });
  347. const adminMessage = createMessage(adminMailbox, 'Admin private message', 1);
  348. const alicePrimaryMessage = createMessage(alicePrimaryMailbox, 'Alice primary message', 2);
  349. const aliceSecondaryMessage = createMessage(aliceSecondaryMailbox, 'Alice secondary message', 3);
  350. const bobMessage = createMessage(bobMailbox, 'Bob private message', 4);
  351. const historical = createApiToken(admin.id, 'historical unrecoverable', {
  352. scopes: ['messages:read'],
  353. mailboxAccess: 'owner'
  354. });
  355. const database = new DatabaseSync(path.join(process.env.DATA_DIR, 'mailhub.sqlite'));
  356. database.prepare("UPDATE api_tokens SET token_secret = '' WHERE id = ?").run(historical.id);
  357. database.close();
  358. console.log(JSON.stringify({
  359. adminUserId: admin.id,
  360. adminMailboxId: adminMailbox.id,
  361. alicePrimaryMailboxId: alicePrimaryMailbox.id,
  362. aliceSecondaryMailboxId: aliceSecondaryMailbox.id,
  363. bobMailboxId: bobMailbox.id,
  364. adminMessageId: adminMessage.id,
  365. alicePrimaryMessageId: alicePrimaryMessage.id,
  366. aliceSecondaryMessageId: aliceSecondaryMessage.id,
  367. bobMessageId: bobMessage.id,
  368. historicalTokenId: historical.id
  369. }));
  370. `;
  371. const result = spawnSync(process.execPath, ['--input-type=module', '-e', script], {
  372. cwd: process.cwd(),
  373. env: {
  374. ...process.env,
  375. DATA_DIR: dataDir,
  376. SESSION_SECRET: sessionSecret
  377. },
  378. encoding: 'utf8'
  379. });
  380. assert.equal(result.status, 0, result.stderr || result.stdout);
  381. return JSON.parse(result.stdout);
  382. }
  383. async function requestJson(baseUrl, pathname, {
  384. method = 'GET',
  385. cookie = '',
  386. bearer = '',
  387. basic = null,
  388. body
  389. } = {}) {
  390. const headers = {};
  391. if (cookie) headers.Cookie = cookie;
  392. if (bearer) headers.Authorization = `Bearer ${bearer}`;
  393. if (basic) headers.Authorization = `Basic ${Buffer.from(basic.join(':')).toString('base64')}`;
  394. if (body !== undefined) headers['Content-Type'] = 'application/json';
  395. const response = await fetch(`${baseUrl}${pathname}`, {
  396. method,
  397. headers,
  398. body: body === undefined ? undefined : JSON.stringify(body),
  399. redirect: 'manual'
  400. });
  401. const text = await response.text();
  402. return {
  403. response,
  404. status: response.status,
  405. body: text ? JSON.parse(text) : null
  406. };
  407. }
  408. async function login(baseUrl, username, password) {
  409. const response = await fetch(`${baseUrl}/api/login`, {
  410. method: 'POST',
  411. headers: { 'Content-Type': 'application/json' },
  412. body: JSON.stringify({ username, password })
  413. });
  414. assert.equal(response.status, 200);
  415. const cookie = response.headers.get('set-cookie')?.split(';')[0] || '';
  416. assert.ok(cookie);
  417. return cookie;
  418. }
  419. async function startTestServer() {
  420. const port = await freePort();
  421. const dataDir = mkdtempSync(path.join(tmpdir(), 'mailhub-token-inbound-auth-'));
  422. const sessionSecret = 'token-inbound-auth-session-secret';
  423. const child = spawn(process.execPath, ['src/server.js'], {
  424. cwd: process.cwd(),
  425. env: {
  426. ...process.env,
  427. PORT: String(port),
  428. DATA_DIR: dataDir,
  429. SESSION_SECRET: sessionSecret,
  430. ADMIN_USER: 'admin',
  431. ADMIN_EMAIL: 'admin@example.test',
  432. ADMIN_PASSWORD: 'password123',
  433. DNS_AUTO_CHECK_ENABLED: 'false',
  434. DELIVERY_TRACKING_ENABLED: 'false',
  435. WEBHOOK_WORKER_ENABLED: 'false',
  436. SUBMISSION_ENABLED: 'false',
  437. IMAP_ENABLED: 'false',
  438. POP3_ENABLED: 'false'
  439. },
  440. stdio: ['ignore', 'pipe', 'pipe']
  441. });
  442. await waitForOutput(child, 'MailHub listening');
  443. return { child, baseUrl: `http://127.0.0.1:${port}`, dataDir, sessionSecret };
  444. }
  445. function freePort() {
  446. return new Promise((resolve, reject) => {
  447. const server = net.createServer();
  448. server.listen(0, '127.0.0.1', () => {
  449. const address = server.address();
  450. server.close(() => {
  451. if (address && typeof address === 'object') resolve(address.port);
  452. else reject(new Error('Unable to allocate a test port.'));
  453. });
  454. });
  455. });
  456. }
  457. function waitForOutput(child, text) {
  458. return new Promise((resolve, reject) => {
  459. const timeout = setTimeout(() => reject(new Error(`Timed out waiting for ${text}`)), 5000);
  460. let output = '';
  461. const onData = (chunk) => {
  462. output += chunk.toString();
  463. if (!output.includes(text)) return;
  464. clearTimeout(timeout);
  465. child.stdout.off('data', onData);
  466. resolve();
  467. };
  468. child.stdout.on('data', onData);
  469. child.once('exit', (code) => {
  470. clearTimeout(timeout);
  471. reject(new Error(`Server exited before startup with code ${code}`));
  472. });
  473. });
  474. }
  475. function waitForExit(child, timeoutMs) {
  476. if (child.exitCode !== null) return Promise.resolve(child.exitCode);
  477. return new Promise((resolve) => {
  478. const timeout = setTimeout(() => resolve(null), timeoutMs);
  479. child.once('exit', (code) => {
  480. clearTimeout(timeout);
  481. resolve(code);
  482. });
  483. });
  484. }