Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend] Taxii feed cursor should be reset when data from is changed on UI (#8463) #8844

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions opencti-platform/opencti-graphql/config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
"enabled": true,
"interval": 6000000
},
"ingestion_manager": {
"enabled": false
},
"providers": {
"local": {
"strategy": "LocalStrategy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const ingestionEditField = async (context: AuthContext, user: AuthUser, i
verifyIngestionAuthenticationContent(ingestionConfiguration.authentication_type, authenticationValueField.value[0]);
}
}

const { element } = await updateAttribute(context, user, ingestionId, ENTITY_TYPE_INGESTION_TAXII, input);
await registerConnectorForIngestion(context, {
id: element.id,
Expand All @@ -68,6 +69,11 @@ export const ingestionEditField = async (context: AuthContext, user: AuthUser, i
is_running: element.ingestion_running ?? false,
connector_user_id: element.user_id
});

if (input.some(((editInput) => editInput.key === 'added_after_start'))) {
await patchTaxiiIngestion(context, user, ingestionId, { current_state_cursor: undefined });
}

await publishUserAction({
user,
event_type: 'mutation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import gql from 'graphql-tag';
import type { GraphQLFormattedError } from 'graphql/error';
import { queryAsAdminWithSuccess } from '../../utils/testQueryHelper';
import { IngestionAuthType, TaxiiVersion } from '../../../src/generated/graphql';
import { queryAsAdmin } from '../../utils/testQuery';
import { ADMIN_USER, queryAsAdmin, testContext } from '../../utils/testQuery';
import { now } from '../../../src/utils/format';
import { findById as findIngestionById, patchTaxiiIngestion } from '../../../src/modules/ingestion/ingestion-taxii-domain';

describe('TAXII ingestion resolver standard behavior', () => {
let createdTaxiiIngesterId: string;
Expand All @@ -20,14 +22,14 @@ describe('TAXII ingestion resolver standard behavior', () => {
};
const ingesterQueryResult = await queryAsAdminWithSuccess({
query: gql`
mutation createTaxiiIngester($input: IngestionTaxiiAddInput!) {
ingestionTaxiiAdd(input: $input) {
id
entity_type
ingestion_running
}
},
`,
mutation createTaxiiIngester($input: IngestionTaxiiAddInput!) {
ingestionTaxiiAdd(input: $input) {
id
entity_type
ingestion_running
}
},
`,
variables: INGESTER_TO_CREATE
});
expect(ingesterQueryResult.data?.ingestionTaxiiAdd.id).toBeDefined();
Expand All @@ -52,6 +54,31 @@ describe('TAXII ingestion resolver standard behavior', () => {
expect(ingesterQueryResult.data?.ingestionTaxiiFieldPatch.authentication_value).toEqual('username:P@ssw0rd!');
});

it('should reset cursor when a user change the start date', async () => {
// shortcut to set a cursor that is defined
const state = { current_state_cursor: 'aaaaaaaaaaaaaaaaaaa', last_execution_date: now() };
const result = await patchTaxiiIngestion(testContext, ADMIN_USER, createdTaxiiIngesterId, state);
expect(result.current_state_cursor).toBe('aaaaaaaaaaaaaaaaaaa');

const ingesterChangeDateResult = await queryAsAdminWithSuccess({
query: gql`
mutation ingestionTaxiiFieldPatch($id: ID!, $input: [EditInput!]!) {
ingestionTaxiiFieldPatch(id: $id, input: $input) {
id
current_state_cursor
added_after_start
}
}
`,
variables: { id: createdTaxiiIngesterId, input: [{ key: 'added_after_start', value: [now()] }] }
});
expect(ingesterChangeDateResult.data?.ingestionTaxiiFieldPatch.id).toBeDefined();

const ingestionState = await findIngestionById(testContext, ADMIN_USER, createdTaxiiIngesterId);
expect(ingestionState.id).toBeDefined();
expect(ingestionState.current_state_cursor).not.toBeDefined();
});

it('should edit a TAXII ingester with : in authentication value be refused', async () => {
const ingesterQueryResult = await queryAsAdmin({
query: gql`
Expand All @@ -75,10 +102,10 @@ describe('TAXII ingestion resolver standard behavior', () => {
it('should delete a TAXII ingester', async () => {
const ingesterQueryResult = await queryAsAdminWithSuccess({
query: gql`
mutation deleteTaxiiIngester($id: ID!) {
ingestionTaxiiDelete(id: $id)
}
`,
mutation deleteTaxiiIngester($id: ID!) {
ingestionTaxiiDelete(id: $id)
}
`,
variables: { id: createdTaxiiIngesterId }
});
expect(ingesterQueryResult.data?.ingestionTaxiiDelete).toEqual(createdTaxiiIngesterId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export const queryAsAdminWithSuccess = async (request: { query: any, variables:
variables: request.variables,
});
expect(requestResult, `Something is wrong with this query: ${request.query}`).toBeDefined();
if (requestResult.errors) {
logApp.info('Unexpected error; requestResult:', { requestResult });
}
expect(requestResult.errors, `This errors should not be there: ${requestResult.errors}`).toBeUndefined();
return requestResult;
};
Expand All @@ -31,6 +34,9 @@ export const adminQueryWithSuccess = async (request: { query: any, variables: an
variables: request.variables,
});
expect(requestResult, `Something is wrong with this query: ${request.query}`).toBeDefined();
if (requestResult.errors) {
logApp.info('Unexpected error; requestResult:', { requestResult });
}
expect(requestResult.errors, `This errors should not be there: ${requestResult.errors}`).toBeUndefined();
return requestResult;
};
Expand All @@ -43,6 +49,9 @@ export const adminQueryWithSuccess = async (request: { query: any, variables: an
export const queryAsUserWithSuccess = async (client: AxiosInstance, request: { query: any, variables: any }) => {
const requestResult = await executeInternalQuery(client, print(request.query), request.variables);
expect(requestResult, `Something is wrong with this query: ${request.query}`).toBeDefined();
if (requestResult.errors) {
logApp.info('Unexpected error; requestResult:', { requestResult });
}
expect(requestResult.errors, `This errors should not be there: ${JSON.stringify(requestResult.errors)}`).toBeUndefined();
return requestResult;
};
Expand Down