-
Notifications
You must be signed in to change notification settings - Fork 914
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] Fix missing entities in shared Report (#8333) #8366
Draft
marieflorescontact
wants to merge
8
commits into
master
Choose a base branch
from
issue/8333
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
78a4330
[backend] Fix missing entities in shared Report (#8333)
marieflorescontact 27b5ff2
[backend] WIP: test (#8333)
marieflorescontact 7c7a264
Add trigger of tasks in tests
aHenryJard 3ed753a
Add enable org method in testQuery
aHenryJard a76cf75
[backend] WIP: test (#8333)
marieflorescontact 0eef569
[backend] drone (#8333)
marieflorescontact b678c62
[backend] drone (#8333)
marieflorescontact 5c0c5e2
[backend] drone (#8333)
marieflorescontact File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
.../opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import gql from 'graphql-tag'; | ||
import { | ||
ADMIN_API_TOKEN, | ||
ADMIN_USER, | ||
adminQuery, | ||
API_URI, | ||
FIVE_MINUTES, | ||
getOrganizationIdByName, | ||
PLATFORM_ORGANIZATION, | ||
PYTHON_PATH, | ||
TEST_ORGANIZATION, | ||
testContext, | ||
USER_EDITOR, | ||
} from '../../utils/testQuery'; | ||
import { adminQueryWithSuccess, enableCEAndUnSetOrganization, enableEEAndSetOrganization, queryAsUserWithSuccess } from '../../utils/testQueryHelper'; | ||
import { findById } from '../../../src/domain/report'; | ||
import { execChildPython } from '../../../src/python/pythonBridge'; | ||
import { taskHandler } from '../../../src/manager/taskManager'; | ||
|
||
const READ_QUERY = gql` | ||
query caseIncident($id: String!) { | ||
caseIncident(id: $id) { | ||
id | ||
standard_id | ||
name | ||
authorized_members { | ||
id | ||
access_right | ||
} | ||
currentUserAccessRight | ||
} | ||
} | ||
`; | ||
|
||
const DELETE_QUERY = gql` | ||
mutation CaseIncidentDelete($id: ID!) { | ||
caseIncidentDelete(id: $id) | ||
} | ||
`; | ||
|
||
const ORGANIZATION_SHARING_QUERY = gql` | ||
mutation StixCoreObjectSharingGroupAddMutation( | ||
$id: ID! | ||
$organizationId: ID! | ||
) { | ||
stixCoreObjectEdit(id: $id) { | ||
restrictionOrganizationAdd(organizationId: $organizationId) { | ||
id | ||
objectOrganization { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const importOpts: string[] = [API_URI, ADMIN_API_TOKEN, './tests/data/DATA-TEST-STIX2_v2.json']; | ||
|
||
describe('Database provision', () => { | ||
it('Should import creation succeed', async () => { | ||
// Inject data | ||
const execution = await execChildPython(testContext, ADMIN_USER, PYTHON_PATH, 'local_importer.py', importOpts); | ||
expect(execution).not.toBeNull(); | ||
expect(execution.status).toEqual('success'); | ||
}, FIVE_MINUTES); | ||
// Python lib is fixed but we need to wait for a new release | ||
it('Should import update succeed', async () => { | ||
const execution = await execChildPython(testContext, ADMIN_USER, PYTHON_PATH, 'local_importer.py', importOpts); | ||
expect(execution).not.toBeNull(); | ||
expect(execution.status).toEqual('success'); | ||
}, FIVE_MINUTES); | ||
}); | ||
|
||
describe('Organization sharing standard behavior for container', () => { | ||
let reportInternalId: string; | ||
let organizationId: string; | ||
it('should load Report', async () => { | ||
const report = await findById(testContext, ADMIN_USER, 'report--57162a65-2a58-560b-9a65-47c3f040f3d4'); // Report is in DATA-TEST-STIX_v2.json | ||
reportInternalId = report.internal_id; | ||
}); | ||
it('should platform organization sharing and EE activated', async () => { | ||
await enableEEAndSetOrganization(PLATFORM_ORGANIZATION); | ||
}); | ||
it('should share Report with Organization', async () => { | ||
// Get organization id | ||
organizationId = await getOrganizationIdByName(TEST_ORGANIZATION.name); | ||
const organizationSharingQueryResult = await adminQueryWithSuccess({ | ||
query: ORGANIZATION_SHARING_QUERY, | ||
variables: { id: reportInternalId, organizationId } | ||
}); | ||
expect(organizationSharingQueryResult?.data?.stixCoreObjectEdit.restrictionOrganizationAdd).not.toBeNull(); | ||
expect(organizationSharingQueryResult?.data?.stixCoreObjectEdit.restrictionOrganizationAdd.objectOrganization[0].name).toEqual(TEST_ORGANIZATION.name); | ||
|
||
// Need background task magic to happens for sharing | ||
await taskHandler(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a kind of hack, not sure of this. But we will have some random issue if the manager has not run before next test. The alternative would be to do this test at domain level in taskManager-test, calling taskManager.executeShare. |
||
}); | ||
it('should Editor user access all objects', async () => { | ||
const REPORT_STIX_DOMAIN_ENTITIES = gql` | ||
query report($id: String!) { | ||
report(id: $id) { | ||
id | ||
standard_id | ||
objects(first: 30) { | ||
edges { | ||
node { | ||
... on BasicObject { | ||
id | ||
standard_id | ||
} | ||
... on BasicRelationship { | ||
id | ||
standard_id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
const queryResult = await queryAsUserWithSuccess(USER_EDITOR.client, { | ||
query: REPORT_STIX_DOMAIN_ENTITIES, | ||
variables: { id: reportInternalId }, | ||
}); | ||
expect(queryResult.data.report.objects.edges.length).toEqual(10); | ||
}); | ||
it('should delete Report', async () => { | ||
// Delete the case | ||
await adminQuery({ | ||
query: DELETE_QUERY, | ||
variables: { id: reportInternalId }, | ||
}); | ||
// Verify is no longer found | ||
const queryResult = await adminQueryWithSuccess({ query: READ_QUERY, variables: { id: reportInternalId } }); | ||
expect(queryResult?.data?.caseIncident).toBeNull(); | ||
}); | ||
it('should plateform organization sharing and EE deactivated', async () => { | ||
await enableCEAndUnSetOrganization(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no needed finally