Skip to content

Commit

Permalink
[backend] missing opts definition file_marking for file upload(#5548)
Browse files Browse the repository at this point in the history
  • Loading branch information
aHenryJard committed May 2, 2024
1 parent 35e593d commit 4f445d5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface FileUploadOpts {
meta? : any,
noTriggerImport?: boolean,
errorOnExisting?: boolean,
file_markings?: string[],
}

interface FileUploadData {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest';
import { fileToReadStream, SUPPORT_STORAGE_PATH, uploadToStorage } from '../../../src/database/file-storage-helper';
import type { AuthContext } from '../../../src/types/user';
import { ADMIN_USER } from '../../utils/testQuery';
import { MARKING_TLP_CLEAR } from '../../../src/schema/identifier';
import { findById as findDocumentById } from '../../../src/modules/internal/document/document-domain';

const adminContext: AuthContext = { user: ADMIN_USER, tracing: undefined, source: 'file-storage-helper-test', otp_mandatory: false };

describe('File storage upload with marking', () => {
it('should file upload succeed to S3 and data in elastic have marking stored.', async () => {
const file = fileToReadStream('./tests/data/', 'file-storage-helper-test.txt', 'file-storage-test.txt', 'text/plain');
const uploadedFileWithMarking = await uploadToStorage(adminContext, ADMIN_USER, SUPPORT_STORAGE_PATH, file, { file_markings: [MARKING_TLP_CLEAR] });
expect(uploadedFileWithMarking.upload.id).toBeDefined();
// and expect no exception.

const document = await findDocumentById(adminContext, ADMIN_USER, uploadedFileWithMarking.upload.id);
expect(document.metaData.file_markings).toBeDefined();
expect(document.metaData.file_markings?.length, 'One marking MARKING_TLP_CLEAR is expected on this document.').toBe(1);
if (document.metaData.file_markings) {
expect(document.metaData.file_markings[0]).toBe(MARKING_TLP_CLEAR);
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The content is anything.

0 comments on commit 4f445d5

Please sign in to comment.