Files
wekan/tests/deckImport.test.cjs
T
Lauri Ojansivu 51238ed8ad Import: attachment files of Jira, Nextcloud Deck, OpenProject, Asana and GitLab.
Their exports name attachments without carrying the files, so the files
were reported as a loss. Each service documents where a file is
downloaded, behind the same sign-in as its API:

- Jira: fields.attachment[].content (/rest/api/3/attachment/content/<id>),
  Basic email:API token; Jira's redirect to its media store is followed
  without the sign-in.
- Deck: /index.php/apps/deck/api/v1.0|v1.1/boards/../stacks/../cards/..
  /attachments/<id>, Basic user:app password, OCS-APIRequest: true.
- OpenProject: _links.downloadLocation, relative to the instance, Basic
  apikey:<key>.
- Asana: GET /attachments/<gid>?opt_fields=download_url with a personal
  access token, then the signed download_url without it; a file the
  export embeds (export_boards.pl) is taken as it is; one kept on Google
  Drive and the like is a link, reported.
- GitLab: a private project's /uploads/ link through
  /api/v4/projects/<id>/uploads/<secret>/<file> (17.4+), Bearer token.

The import page asks for the address, user and token under "Attachment
files" for these five (the REST import takes the same as attachmentAuth).
They go with that one import: held beside the creator in a WeakMap, never
stored or logged, the token field emptied on Import, and sent ONLY to
the origin the member typed - an export names any URL it likes. Every
download is the import's SSRF-guarded fetch, which validates each hop
and drops Authorization on a cross-origin redirect. A file that cannot
be fetched is on the loss report with its reason. Unticking Attachments
leaves them out (Jira's per-issue field is pruned too).

Zenkit is left out: it publishes no way to download a file.

Tests: importAttachmentAuth.test.cjs (each service's request, the
sign-in only to its origin, malformed sign-ins, never stored or
logged), the parser tests pin the attachment lists, a Meteor test
imports an embedded Asana file onto its card and shows a Jira file is
reported without a sign-in and that the sign-in never reaches an address
the guard refuses, and import-attachment-auth.e2e.js the page (not run
here). Not run against the live services.

Thanks to xet7 !
2026-10-15 01:27:26 +03:00

76 lines
4.1 KiB
JavaScript

'use strict';
// Nextcloud Deck import field fidelity (models/lib/externalParsers.js).
// Run: node tests/deckImport.test.cjs
//
// The Deck parser used to keep title, description, due date, one assignee and
// label names. It now keeps every assignee, comments embedded from the OCS
// comments API, archive state, done and creation times and the stack/card
// order; trashed stacks and cards are skipped rather than resurrected, and
// sharing rules and attachments are reported as losses. ACL entries never
// become board members: a file naming a user must not grant them access.
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
async function main() {
const { parseNextcloudDeck } = await import('../models/lib/externalParsers.js');
const { planImportedTask } = await import('../models/lib/importedTaskPlan.js');
const fixture = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures/import-formats/deck.json')));
const expected = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures/import-formats/expectations.json')));
const parsed = parseNextcloudDeck(fixture);
assert.equal(parsed.tasks.length, 1, 'the trashed card is skipped');
const [task] = parsed.tasks;
assert.equal(task.title, expected.title);
assert.equal(task.description, expected.description);
assert.equal(task.owner_username, 'deck-a');
assert.deepEqual(task.assignees, ['deck-b']);
assert.equal(task.requested_by, 'deck-owner');
assert.deepEqual(task.tags, [expected.label]);
assert.deepEqual(parsed.warnings, [{ path: '/stacks/0/cards', reason: '1 deleted card(s) skipped' }]);
assert.deepEqual(parsed.unsupported.map(u => u.path), ['/acl']);
// Each listed attachment is downloaded from Deck's attachment endpoint.
assert.deepEqual(task.attachments, [{ name: 'audit.txt', deck: { boardId: 1, stackId: 1, cardId: task.attachments[0].deck.cardId, id: 1, type: 'file' } }]);
const plan = planImportedTask(task, { members: { 'deck-a': 'uA', 'deck-b': 'uB', 'deck-guest': 'uG' } });
assert.deepEqual(plan.memberIds, ['uA', 'uB'], 'assignees become members; the ACL guest does not');
assert.equal(plan.card.createdAt.toISOString(), '2026-09-01T00:00:00.000Z');
assert.equal(plan.card.archived, false);
assert.equal(plan.card.endAt, undefined, 'done: null is not a completion date');
assert.deepEqual(plan.comments.map(c => [c.text, c.createdAt.toISOString()]),
[[`deck-user: ${expected.comment}`, '2026-09-30T12:34:56.000Z']]);
// Order, archive, done and trashed stacks.
const ordered = parseNextcloudDeck({
board: { title: 'B' },
stacks: [
{ title: 'Later', order: 2, cards: [] },
{ title: 'Gone', order: 0, deletedAt: 5, cards: [{ title: 'ghost' }] },
{ title: 'First', order: 1, cards: [
{ title: 'second', order: 9, archived: true, done: '2026-09-30T12:34:56+00:00' },
{ title: 'first', order: 1, labels: ['plain'] },
] },
],
});
assert.deepEqual(ordered.columns.map(c => c.title), ['First', 'Later']);
assert.deepEqual(ordered.tasks.map(t => t.title), ['first', 'second']);
assert.equal(ordered.tasks[1].archived, true);
assert.equal(planImportedTask(ordered.tasks[1]).card.endAt.toISOString(), '2026-09-30T12:34:56.000Z');
assert.deepEqual(ordered.tasks[0].tags, ['plain']);
assert.deepEqual(ordered.warnings, [{ path: '/stacks', reason: '1 deleted stack(s) skipped' }]);
// Negative: malformed members and comments are ignored, not thrown on.
const odd = parseNextcloudDeck({ stacks: [{ title: 'S', cards: [{ assignedUsers: [null, {}, 'plain-uid'], comments: 'x', archived: 'true', attachmentCount: 2 }] }] });
assert.equal(odd.tasks[0].owner_username, 'plain-uid');
assert.deepEqual(odd.tasks[0].comments, []);
assert.equal(odd.tasks[0].archived, false, 'only a real boolean archives');
assert.match(odd.unsupported[0].reason, /^2 attachment\(s\) not listed in the export/, 'a count names nothing to download');
assert.deepEqual(parseNextcloudDeck({}).tasks, []);
console.log(' ok - Deck assignees, comments, order, archive/done state and losses import');
}
main().catch(error => { console.error(error); process.exitCode = 1; });