Skip to content

Commit

Permalink
[backend] Fix of creation with associated file in entities (#6075)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kedae authored Feb 22, 2024
1 parent 1c6233d commit 7645465
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ test('Check navigation on all pages', async ({ page }) => {

// Other
await leftBarPage.clickOnMenu('Investigations');
await expect(page.getByText('Investigations')).toBeVisible();
await expect(page.getByRole('paragraph')).toHaveText('Investigations');
await leftBarPage.clickOnMenu('Dashboards');
await expect(page.locator('ol').getByText('Dashboards')).toBeVisible();
await expect(page.getByRole('paragraph')).toHaveText('Dashboards');

});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from '../fixtures/baseFixtures';
import { ReportPage } from '../model/report.pageModel';
import { ReportDetailsPage } from '../model/reportDetails.pageModel';
import { ReportFormPage } from '../model/reportForm.pageModel';
import * as path from 'path';

test('Create a new report page', async ({ page }) => {
const reportPage = new ReportPage(page);
Expand All @@ -11,6 +12,24 @@ test('Create a new report page', async ({ page }) => {
await reportPage.addNewReport();
await reportForm.fillNameInput('Test e2e');
await reportPage.getCreateReportButton().click();
await reportPage.getItemFromList('Test e2e Unknown - admin No').click();
await reportPage.getItemFromList('Test e2e').click();
await expect(reportDetailsPage.getReportDetailsPage()).toBeVisible();
});

test('Create a new report with associated file', async ({ page }) => {
const reportPage = new ReportPage(page);
const reportDetailsPage = new ReportDetailsPage(page);
const reportForm = new ReportFormPage(page);
await page.goto('/dashboard/analyses/reports');
await reportPage.addNewReport();
await reportForm.fillNameInput('Test e2e with file');
const fileChooserPromise = page.waitForEvent('filechooser');
await page.getByRole('button', { name: 'Select your file', exact: true }).click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(__dirname, 'createReport.spec.ts'));
await reportPage.getCreateReportButton().click();
await reportPage.getItemFromList('Test e2e with file').click();
await expect(reportDetailsPage.getReportDetailsPage()).toBeVisible();
await page.getByRole('tab', { name: 'Data' }).click();
await expect(page.getByRole('button', { name: 'createReport.spec.ts Launch' })).toBeVisible()
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('Create a new report page and test update', async ({ page }) => {
await reportPage.addNewReport();
await reportForm.fillNameInput('Test Update e2e');
await reportPage.getCreateReportButton().click();
await reportPage.getItemFromList( 'Test Update e2e Unknown - admin No' ).click();
await reportPage.getItemFromList( 'Test Update e2e' ).click();
await reportDetailsPage.getEditButton().click();
await reportForm.fillNameInput('Modification Test Update e2e');
await reportForm.getCloseButton().click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ test('Check EE activation', async ({ page }) => {
await page.getByRole('button', { name: 'Enable' }).click();
expect(page.getByText(/^Enterprise$/)).toBeVisible();
await page.getByRole('button', { name: 'Disable Enterprise Edition' }).click();
expect(page.getByText(/^Enterprise$/)).toBeVisible();
});

test('Check Logo replacement', async ({ page }) => {
Expand Down
10 changes: 5 additions & 5 deletions opencti-platform/opencti-graphql/src/database/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ const updateAttributeRaw = async (context, user, instance, inputs, opts = {}) =>
const preparedAliases = (aliasesInput.value ?? [])
.filter((a) => isNotEmptyField(a))
.filter((a) => normalizeName(a) !== normalizeName(instance.name)
&& normalizeName(a) !== normalizeName(askedModificationName))
&& normalizeName(a) !== normalizeName(askedModificationName))
.map((a) => a.trim());
aliasesInput.value = R.uniqBy((e) => normalizeName(e), preparedAliases);
}
Expand Down Expand Up @@ -1667,12 +1667,12 @@ const updateAttributeRaw = async (context, user, instance, inputs, opts = {}) =>
// Impact the updated_at only if stix data is impacted
// In case of upsert, this addition will be supported by the parent function
if (impactedInputs.length > 0 && isUpdatedAtObject(instance.entity_type)
&& !impactedInputs.find((i) => i.key === 'updated_at')) {
&& !impactedInputs.find((i) => i.key === 'updated_at')) {
const updatedAtInput = { key: 'updated_at', value: [today] };
impactedInputs.push(updatedAtInput);
}
if (impactedInputs.length > 0 && isModifiedObject(instance.entity_type)
&& !impactedInputs.find((i) => i.key === 'modified')) {
&& !impactedInputs.find((i) => i.key === 'modified')) {
const modifiedAtInput = { key: 'modified', value: [today] };
impactedInputs.push(modifiedAtInput);
}
Expand Down Expand Up @@ -3005,7 +3005,7 @@ const buildEntityData = async (context, user, input, type, opts = {}) => {
// If file directly attached
if (!isEmptyField(input.file)) {
const path = `import/${type}/${internalId}`;
const file = await upload(context, user, path, input.file, { entity: { internal_id: internalId } });
const file = await upload(context, user, path, input.file, { entity: data });
data.x_opencti_files = [storeFileConverter(user, file)];
// Add external references from files if necessary
const entitySetting = await getEntitySettingFromCache(context, type);
Expand Down Expand Up @@ -3043,7 +3043,7 @@ const buildEntityData = async (context, user, input, type, opts = {}) => {

const createEntityRaw = async (context, user, rawInput, type, opts = {}) => {
// region confidence control
const input = structuredClone(rawInput);
const input = { ...rawInput };
const { confidenceLevelToApply } = controlCreateInputWithUserConfidence(user, input);
input.confidence = confidenceLevelToApply; // confidence of new entity will be capped to user's confidence
// endregion
Expand Down

0 comments on commit 7645465

Please sign in to comment.