mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Decided on 2026-10-14. On the import page each of the six asks for what its service needs - a self-hosted Planka its address, username and password; the others an access token (Basecamp also its account id) - lists what that account can import, and fetches the chosen board, list or project. The credentials go with each call and are used for that call's requests only; they are never stored or logged, and the page clears secret fields once a fetch has used them. The fetched JSON fills the import text box and the import goes on as for a pasted export: the service's parser (models/lib/<key>ApiFormat.js) into the generalized importer, with the members step and the loss report. The same JSON can be pasted, or posted to POST /api/boards/import/<key>. - server/apiImport.js: apiImportList and apiImportFetch, signed in only, off with the Admin Panel's import switch, not in Sandstorm, rate limited; credentials checked against the service's own fields (models/lib/apiImportServices.js). - server/lib/apiImportRequest.js: every request through the SSRF guard - pinned address, no redirects, bounded in time and size - so a Planka address cannot point the server at its own network; an administrator can allow such a host with API_IMPORT_ALLOWED_PRIVATE_HOSTS. An error names only the origin and the status. - models/lib/apiImport/<key>.js: each service's client, plain Node with the request injected, paging bounded and the token only in a header. - Each has a docs page under docs/Features/ImportExport/, listed in the coverage index and External-Tools.md. Tests: tests/<key>ApiImport.test.cjs (client with a fake request, every parsed field, wrong shapes), tests/apiImport.test.cjs (credentials, the gate, the wiring, the shapes refused), api-import.e2e.js (the form for every service, fetched JSON imported through the page, refusals incl. a private address). Live tests, read only, run from build.sh / build.bat -> Tests -> Live tests with your own accounts (releases/live-tests/README.md); they were not run here. New strings translated in all locales. Also: the release risk baseline allows the services' API addresses, and the guards that count import creators, list the import sources and pin the platform fetch() calls know the new ones. Thanks to xet7 !
77 lines
4.3 KiB
JavaScript
77 lines
4.3 KiB
JavaScript
'use strict';
|
|
|
|
// The one description of every import source (models/lib/importSources.js),
|
|
// which the import page, "Import many boards" and api.py's lists follow, and
|
|
// the one path the page reads every source through.
|
|
// Run: node tests/importSources.test.cjs
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
|
|
|
async function main() {
|
|
const reg = await import('../models/lib/importSources.js');
|
|
const many = await import('../models/lib/importManyFiles.js');
|
|
const { EXTERNAL_PARSERS } = await import('../models/lib/externalParsers.js');
|
|
let passed = 0;
|
|
const test = (name, fn) => { fn(); passed += 1; console.log(' ok -', name); };
|
|
|
|
test('every source is described once, with what its file is sent as', () => {
|
|
const keys = reg.IMPORT_SOURCES.map(s => s.key);
|
|
assert.equal(new Set(keys).size, keys.length, 'no source twice');
|
|
// 43, and the six fetched from a service's API (models/lib/apiImportServices.js).
|
|
assert.equal(keys.length, 49, "every source the import page offers");
|
|
for (const source of reg.IMPORT_SOURCES) {
|
|
assert.ok(source.product || source.name, source.key);
|
|
assert.ok(['text', 'json', 'excel', 'rows'].includes(source.send), `${source.key} send`);
|
|
assert.ok(source.paste || (source.files && source.files.length), `${source.key} can be given somehow`);
|
|
for (const ext of source.files || []) assert.match(ext, /^\.[a-z]+$/, `${source.key} ${ext}`);
|
|
}
|
|
assert.equal(reg.acceptFor('vikunja'), '.zip,.json');
|
|
assert.equal(reg.zipIsOneExport('notion'), true);
|
|
assert.equal(reg.zipIsOneExport('todoist'), false);
|
|
assert.equal(reg.importSource('nope'), null, 'negative: an unknown source is nothing');
|
|
});
|
|
|
|
test('the server knows every source the registry names, and the generalized ones are parsed', () => {
|
|
const shape = read('models/lib/importSourceShape.js');
|
|
const importJs = read('models/import.js');
|
|
for (const source of reg.IMPORT_SOURCES) {
|
|
assert.match(shape, new RegExp(`case '${source.key}':`), `${source.key} has a shape check`);
|
|
if (source.creator === 'generalized' && !['leo', 'opml', 'kanboard'].includes(source.key)) {
|
|
assert.equal(typeof EXTERNAL_PARSERS[source.key], 'function', `${source.key} has a parser`);
|
|
}
|
|
if (source.zipSend === 'zip') assert.match(importJs, new RegExp(`case '${source.key}':[\\s\\S]{0,800}?zip`, 'i'), `${source.key} reads its .zip on the server`);
|
|
}
|
|
assert.match(importJs, /new KanboardCreator\(data, 'leo'\)/);
|
|
});
|
|
|
|
test('the many-files lists are read from it', () => {
|
|
assert.deepEqual(many.EXCEL_SOURCES, reg.IMPORT_SOURCES.filter(s => s.send === 'excel').map(s => s.key));
|
|
assert.deepEqual(many.ZIP_EXPORT_SOURCES.sort(), ['notion', 'plane', 'vikunja', 'wekan']);
|
|
assert.deepEqual(many.OWN_CREATOR_SOURCES.sort(), ['csv', 'excel', 'jira', 'trello', 'wekan']);
|
|
// api.py cannot import JavaScript; its lists must agree by hand.
|
|
const api = read('api.py');
|
|
assert.match(api, new RegExp(`EXCEL_IMPORT_SOURCES = \\{${many.EXCEL_SOURCES.map(k => `'${k}'`).join(', ')}\\}`));
|
|
});
|
|
|
|
test('the page reads every source through one path, with one file chooser', () => {
|
|
const page = read('client/components/import/import.js');
|
|
assert.match(page, /import \{ IMPORT_SOURCES, importSource as importSourceSpec, acceptFor, isApiImport \} from '\/models\/lib\/importSources';/);
|
|
assert.match(page, /doc = documentForFile\(dataSource, file\.name \|\| '', new Uint8Array\(await file\.arrayBuffer\(\)\)\);/);
|
|
// Negative: no source has a file-reading branch of its own any more.
|
|
for (const key of ['vikunja', 'notion', 'plane', 'planner', 'monday', 'wrike', 'markdown']) {
|
|
assert.doesNotMatch(page, new RegExp(`if \\(dataSource === '${key}'`), key);
|
|
}
|
|
assert.doesNotMatch(page, /^const IMPORT_SOURCES = \[/m, 'no second list');
|
|
const jade = read('client/components/import/import.jade');
|
|
assert.equal((jade.match(/type="file"/g) || []).length, 3, 'one file chooser, Trello\'s package and Import many boards');
|
|
assert.match(jade, /input\.js-import-file\(id='import-file' type="file" accept="\{\{importAccept\}\}"\)/);
|
|
});
|
|
|
|
console.log(`\nimportSources: ${passed} checks passed`);
|
|
}
|
|
|
|
main().catch(error => { console.error(error); process.exit(1); });
|