fix: stabilize DOC0 upload fingerprint metadata
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 5s
CI (SIAX Cloud) / sonar (pull_request) Skipped
Security Scan (SIAX Cloud) / security (push) Successful in 14s
CI (SIAX Cloud) / security (push) Successful in 17s
CI (SIAX Cloud) / security (pull_request) Successful in 19s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 19s
CI (SIAX Cloud) / integration (pull_request) Successful in 28s
masterplan-lock / check (pull_request) Successful in 32s
CI (SIAX Cloud) / quality (push) Successful in 51s
CI (SIAX Cloud) / quality (pull_request) Successful in 50s
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 5s
CI (SIAX Cloud) / sonar (pull_request) Skipped
Security Scan (SIAX Cloud) / security (push) Successful in 14s
CI (SIAX Cloud) / security (push) Successful in 17s
CI (SIAX Cloud) / security (pull_request) Successful in 19s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 19s
CI (SIAX Cloud) / integration (pull_request) Successful in 28s
masterplan-lock / check (pull_request) Successful in 32s
CI (SIAX Cloud) / quality (push) Successful in 51s
CI (SIAX Cloud) / quality (pull_request) Successful in 50s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { Doc0UploadClient, Doc0UploadOutcomeUnknownError, Doc0InspectionUnavailableError } from '../../src/document-workbench/doc0-upload-client';
|
||||
import { Doc0UploadClient, Doc0UploadOutcomeUnknownError, Doc0InspectionUnavailableError, prepareDoc0UploadIdentity } from '../../src/document-workbench/doc0-upload-client';
|
||||
|
||||
const bytes = new TextEncoder().encode('source bytes');
|
||||
const input = {
|
||||
@@ -48,6 +48,39 @@ describe('DOC0 upload client', () => {
|
||||
pipelineStage: 'parsed',
|
||||
});
|
||||
});
|
||||
it.each(['rapport åäö.xlsx', 'folder/name.txt', 'Back\\path.txt', 'A"B.txt', 'row\r\nname.txt'])(
|
||||
'uses stable multipart metadata while retaining original name: %s', async (filename) => {
|
||||
const fixture = { ...input, filename, mimeType: 'APPLICATION/PDF' };
|
||||
const identity = prepareDoc0UploadIdentity(fixture);
|
||||
const fetchImpl = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {
|
||||
const form = init?.body as FormData;
|
||||
expect(JSON.parse(form.get('input') as string).displayName).toBe(filename);
|
||||
expect((form.get('file') as File).name).toBe(identity.wireFilename);
|
||||
expect((form.get('file') as File).type).toBe('application/pdf');
|
||||
return Response.json(receipt, { status: 201 });
|
||||
});
|
||||
await new Doc0UploadClient({ baseUrl: 'https://doc0.test', serviceToken: 'test', maxBytes: 100, fetchImpl }).upload(fixture);
|
||||
expect(identity.sourceSha256).toBe(receipt.currentVersion.checksumSha256);
|
||||
expect(identity.requestFingerprint).toMatch(/^[0-9a-f]{64}$/);
|
||||
expect(fetchImpl).toHaveBeenCalledOnce();
|
||||
},
|
||||
);
|
||||
it('rejects non-canonical identity headers before any upload', async () => {
|
||||
const fetchImpl = vi.fn();
|
||||
const client = new Doc0UploadClient({ baseUrl: 'https://doc0.test', serviceToken: 'test', maxBytes: 100, fetchImpl });
|
||||
for (const tenantId of [' tenant-a', 'tenant-a ', 'tenant-å', 'tenant-\n']) {
|
||||
await expect(client.upload({ ...input, tenantId })).rejects.toThrow(/Invalid/);
|
||||
}
|
||||
expect(fetchImpl).not.toHaveBeenCalled();
|
||||
});
|
||||
it('rejects ambiguous MIME values before any upload', async () => {
|
||||
const fetchImpl = vi.fn();
|
||||
const client = new Doc0UploadClient({ baseUrl: 'https://doc0.test', serviceToken: 'test', maxBytes: 100, fetchImpl });
|
||||
for (const mimeType of ['text/plain; charset=utf-8', 'text/å', ' text/plain', 'not-a-mime']) {
|
||||
await expect(client.upload({ ...input, mimeType })).rejects.toThrow(/MIME/);
|
||||
}
|
||||
expect(fetchImpl).not.toHaveBeenCalled();
|
||||
});
|
||||
it.each([
|
||||
{ document: { ...receipt.document, tenantId: 'tenant-b' } },
|
||||
{ document: { ...receipt.document, projectId: 'other' } },
|
||||
|
||||
Reference in New Issue
Block a user