mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Azure DevOps Boards: a query's "Export to CSV" is imported (Board Column or State as lists, Board Lane as swimlanes, Title 1/2/3 tree levels as parent cards, "Name <address>" people, regional dates, other columns as custom fields), and a board exports as the CSV "Import from CSV" reads. Microsoft Lists: a list's "Export to CSV" is imported (Status or Progress as the lists, people, dates, tags, other columns as custom fields), and a board exports as a CSV that "New list - From CSV" makes a list of. Microsoft Project: the "XML Format" (MSPDI) plan is imported (summary tasks as swimlanes, progress as lists, subtasks, resources, predecessors), read by a small XML reader that never resolves a DTD or an entity, and a board exports as a plan Project opens. Outlook: .msg files are read without a library - the Compound File Binary format (MS-CFB) and the message's properties (MS-OXMSG) - into the mail import, threads and attachments included, alone or in a .zip with .eml files; a board exports as .eml files Outlook opens. The reader was checked against .msg files saved by Outlook. Teams and OneNote: fetched from Microsoft Graph with the member's token (chats and channels; notebooks with their pages' HTML, to-do boxes as a checklist), or read from a file - Teams' personal export .tar, Graph chat messages, and the files WeKan exports: Teams chats as Graph chat messages, OneNote pages as Graph's create-page XHTML in a .zip. All six are under the Microsoft heading of Import and Export, with tests, negative tests, live tests for the two Graph imports, documentation and the import instruction in every language. Low confidence translations include ace, ak, ay, bm, bo, bua, chr, csb, cv, dz, ee, ff, fj, gn, gv, haw, ig, iu, kl, ks, kok, kw, ht, hsb, fur, fo, ga, gd, ku, lld, nah, nap, rup, sah, sc, scn, se, nd, nso, ss, om, rn, rw, sm, sn, qu, pap, lg, mg, mi, ny, so, mai, sd, ps, or_IN, my, si, rm, la, lb, tig, tlh, uz-AR, ve, ve-PP, ve-CC, vo, wa, wal, wo, zgh, to, tpi, wa-RR and ts. Thanks to xet7 !
114 lines
7.7 KiB
JavaScript
114 lines
7.7 KiB
JavaScript
'use strict';
|
|
|
|
// Import from a service's API (decided 2026-10-14): the shared part - the
|
|
// catalog and its credential check, the server methods' gate, the request
|
|
// through the SSRF guard, the import page's form and the wiring of the six
|
|
// services. Each service's own client and parser are tested in
|
|
// tests/<key>ApiImport.test.cjs; releases/live-tests/<key>-import.mjs run them
|
|
// against the real services from build.sh / build.bat.
|
|
// Run: node tests/apiImport.test.cjs
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { API_IMPORT_SERVICES, MAX_FIELD_LENGTH, apiImportService, cleanApiImportCredentials } = require('../models/lib/apiImportServices.js');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const read = f => fs.readFileSync(path.join(ROOT, f), 'utf8');
|
|
const KEYS = ['planka', 'mstodo', 'onenote', 'teams', 'kanbanflow', 'basecamp', 'googletasks', 'googlekeep'];
|
|
const PARSERS = { planka: 'parsePlankaApi', mstodo: 'parseMicrosoftTodoApi', onenote: 'parseOnenoteApi', teams: 'parseTeamsExport', kanbanflow: 'parseKanbanflowApi',
|
|
basecamp: 'parseBasecampApi', googletasks: 'parseGoogleTasksApi', googlekeep: 'parseGoogleKeepApi' };
|
|
|
|
(async () => {
|
|
assert.deepEqual(API_IMPORT_SERVICES.map(s => s.key), KEYS);
|
|
// The credentials a call may carry.
|
|
assert.deepEqual(cleanApiImportCredentials('planka', { url: ' https://planka.example.org/ ', username: ' me ', password: ' p w ' }),
|
|
{ url: 'https://planka.example.org', username: 'me', password: ' p w ' }, 'a secret is kept exactly, the rest trimmed');
|
|
assert.deepEqual(cleanApiImportCredentials('basecamp', { account: '123', token: 't' }), { account: '123', token: 't' });
|
|
// Negative: an unknown service or field, a missing one, a non-string, too long, a bad address.
|
|
for (const [key, input, why] of [
|
|
['trello', { token: 't' }, /Unknown import service/],
|
|
['mstodo', null, /required/],
|
|
['mstodo', ['t'], /required/],
|
|
['mstodo', {}, /token is required/],
|
|
['mstodo', { token: 't', url: 'https://x' }, /Unexpected credential field url/],
|
|
['mstodo', { token: 42 }, /not valid/],
|
|
['mstodo', { token: 'x'.repeat(MAX_FIELD_LENGTH + 1) }, /not valid/],
|
|
['planka', { url: 'file:///etc/passwd', username: 'u', password: 'p' }, /url is not valid/],
|
|
['planka', { url: 'https://user:pw@planka.example.org', username: 'u', password: 'p' }, /url is not valid/],
|
|
['planka', { url: 'not a url', username: 'u', password: 'p' }, /url is not valid/],
|
|
]) assert.throws(() => cleanApiImportCredentials(key, input), why, `${key} ${JSON.stringify(input)}`);
|
|
assert.equal(apiImportService('nope'), null);
|
|
console.log(' ok - the catalog and its credential check');
|
|
|
|
// The server: login, the import switch, no Sandstorm, rate limited, nothing stored.
|
|
const server = read('server/apiImport.js');
|
|
assert.match(server, /if \(!userId\) throw new Meteor\.Error\('error-notAuthorized'\);/);
|
|
assert.match(server, /await assertImportEnabled\(\);/, 'the Admin Panel switch that disables import also disables this');
|
|
assert.match(server, /Meteor\.settings\?\.public\?\.sandstorm\) throw/);
|
|
assert.match(server, /cleanApiImportCredentials\(service, credentials\)/);
|
|
assert.match(server, /DDPRateLimiter\.addRule\(\{ type: 'method', name: name => \['apiImportList', 'apiImportFetch'\]\.includes\(name\)/);
|
|
for (const key of KEYS) assert.match(server, new RegExp(`import \\* as ${key} from '/models/lib/apiImport/${key}';`));
|
|
// Negative: credentials never written anywhere or logged.
|
|
assert.doesNotMatch(server, /insertAsync|updateAsync|upsertAsync|console\.(log|warn|error)/);
|
|
assert.match(read('server/imports.js'), /^import '\/server\/apiImport';$/m);
|
|
const request = read('server/lib/apiImportRequest.js');
|
|
assert.match(request, /fetchSafe\(url, \{/);
|
|
assert.match(request, /maxRedirects: 0, maxResponseBytes: MAX_RESPONSE_BYTES/);
|
|
assert.match(request, /redirect: 'error'/, 'an allowed private host is still fetched without redirects');
|
|
assert.match(request, /API_IMPORT_ALLOWED_PRIVATE_HOSTS/);
|
|
// Negative: an error says only the origin and the status, never the answer.
|
|
// A successful answer may be text (2026-11-21: a OneNote page's HTML, asked
|
|
// for with Accept: text/html), read only after the non-2xx answer has been
|
|
// turned into an error that holds no body.
|
|
const okAt = request.indexOf('if (!response.ok) {');
|
|
assert.ok(okAt > 0);
|
|
assert.doesNotMatch(request.slice(0, request.indexOf('if (response.status === 204)')), /response\.text\(\)/);
|
|
assert.match(request.slice(okAt, okAt + 200), /new Error\(`\$\{origin\} answered HTTP \$\{response\.status\}`\)/);
|
|
assert.match(request, /if \(\/\^text\\\/\/i\.test\(accept\)\) \{\s*try \{ return await response\.text\(\); \}/);
|
|
console.log(' ok - the server methods: gated, rate limited, through the SSRF guard');
|
|
|
|
// The wiring of every service.
|
|
const sources = read('models/lib/importSources.js');
|
|
const shape = read('models/lib/importSourceShape.js');
|
|
const parsers = read('models/lib/externalParsers.js');
|
|
const importJs = read('models/import.js');
|
|
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
|
|
for (const key of KEYS) {
|
|
// OneNote and Teams also read a file of their own (files, zipSend), still a JSON source.
|
|
assert.match(sources, new RegExp(`\\{ key: '${key}', name: '[^']+', \\.\\.\\.JSON_SOURCE(, [^}]*)?, api: true \\}`), key);
|
|
assert.match(shape, new RegExp(`case '${key}'`), key);
|
|
assert.match(parsers, new RegExp(` ${key}: ${PARSERS[key]},`), key);
|
|
assert.match(importJs, new RegExp(` case '${key}':`), key);
|
|
assert.ok(fs.existsSync(path.join(ROOT, `models/lib/apiImport/${key}.js`)), `${key} client`);
|
|
assert.ok(fs.existsSync(path.join(ROOT, `tests/${key}ApiImport.test.cjs`)), `${key} test`);
|
|
assert.ok(fs.existsSync(path.join(ROOT, `releases/live-tests/${key}-import.mjs`)), `${key} live test`);
|
|
assert.equal(typeof en[`import-board-instruction-${key}`], 'string', `${key} instruction`);
|
|
}
|
|
assert.match(importJs, /creator = new KanboardCreator\(data, importSource\);/);
|
|
// The page: the form, and secrets cleared once used.
|
|
const page = read('client/components/import/import.js');
|
|
assert.match(read('client/components/import/import.jade'), /if apiImport\s*\n\s*\+apiImportFetch\(service=apiImport\)/);
|
|
assert.match(page, /tpl\.\$\('\.js-api-import-field\[type="password"\]'\)\.val\(''\);/);
|
|
assert.match(read('client/components/import/import.jade'), /type="password" autocomplete="off"/);
|
|
for (const key of ['api-import-desc', 'api-import-list', 'api-import-fetch', 'api-import-fetched', 'api-import-failed', 'api-import-token']) {
|
|
assert.equal(typeof en[key], 'string', key);
|
|
}
|
|
console.log(' ok - eight services wired: source, shape, parser, import, client, test, live test, instruction');
|
|
|
|
// A shape the fetch does not return is refused before any parser runs.
|
|
const { validateImportSourceShape } = await import('../models/lib/importSourceShape.js');
|
|
validateImportSourceShape('planka', { planka: { item: { id: '1' }, included: {} } });
|
|
validateImportSourceShape('mstodo', { lists: [] });
|
|
validateImportSourceShape('kanbanflow', { board: {}, tasks: [] });
|
|
validateImportSourceShape('basecamp', { project: {}, cardTables: [] });
|
|
validateImportSourceShape('googlekeep', { notes: [] });
|
|
for (const [key, value] of [['planka', {}], ['mstodo', { value: [] }], ['kanbanflow', { tasks: [] }], ['basecamp', { project: {} }],
|
|
['googletasks', []], ['googlekeep', { items: [] }]]) {
|
|
assert.throws(() => validateImportSourceShape(key, value), /Invalid/, key);
|
|
}
|
|
console.log(' ok - the import refuses a shape no fetch returns');
|
|
|
|
console.log('\napiImport: all tests passed');
|
|
})().catch(error => { console.error(error); process.exit(1); });
|