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/frontend] Fix enable references behavior when adding entities to containers #6175

Merged
merged 3 commits into from
Apr 3, 2024

Conversation

JeremyCloarec
Copy link
Contributor

@JeremyCloarec JeremyCloarec commented Feb 29, 2024

This PR is only to fix enable references behavior in the scope of the #5884 issue. Other PRs will aim to fully fix the enable references behavior for all entities, and the full list of problems can be seen in the #6074

Checklist

  • I consider the submitted work as finished
  • I tested the code for its functionality
  • I wrote test cases for the relevant uses case
  • I added/update the relevant documentation (either on github or on notion)
  • Where necessary I refactored code to improve the overall quality

Copy link

codecov bot commented Feb 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.75%. Comparing base (0067e4d) to head (949e85d).
Report is 1 commits behind head on master.

❗ Current head 949e85d differs from pull request most recent head cba58bc. Consider uploading reports for the commit cba58bc to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6175      +/-   ##
==========================================
- Coverage   67.76%   66.75%   -1.02%     
==========================================
  Files         532      541       +9     
  Lines       65065    64556     -509     
  Branches     5462     5307     -155     
==========================================
- Hits        44093    43094     -999     
- Misses      20972    21462     +490     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JeremyCloarec JeremyCloarec marked this pull request as ready for review March 4, 2024 10:52
@JeremyCloarec JeremyCloarec linked an issue Mar 4, 2024 that may be closed by this pull request
@@ -12126,8 +12126,8 @@ type ReportEditMutations {
fieldPatch(input: [EditInput]!, commitMessage: String, references: [String]): Report @auth(for: [KNOWLEDGE_KNUPDATE])
contextPatch(input: EditContext): Report @auth(for: [KNOWLEDGE_KNUPDATE])
contextClean: Report @auth(for: [KNOWLEDGE_KNUPDATE])
relationAdd(input: StixRefRelationshipAddInput!): StixRefRelationship @auth(for: [KNOWLEDGE_KNUPDATE])
relationDelete(toId: StixRef!, relationship_type: String!): Report @auth(for: [KNOWLEDGE_KNUPDATE])
relationAdd(input: StixRefRelationshipAddInput!, commitMessage: String, references: [String]): StixRefRelationship @auth(for: [KNOWLEDGE_KNUPDATE])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all these API changes will need a client python update (here see opencti_report.py add_stix_object_or_stix_relationship)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point thank you, I'll update the client as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reading python client code, I think it's better to add commitMessage and references data to StixRefRelationshipAddInput instead of adding new parameters here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's to be consistent with our existing APIs, which all declare (if I'm not mistaken) commitMessage and references as separate parameters. Ex:

relationsAdd(input: StixRefRelationshipsAddInput!, commitMessage: String, references: [String]): StixCoreObject
relationDelete(toId: StixRef!, relationship_type: String!, commitMessage: String, references: [String]): StixCoreObject

@JeremyCloarec JeremyCloarec added the filigran team use to identify PR from the Filigran team label Mar 15, 2024
@SouadHadjiat
Copy link
Member

When trying to update a grouping with external reference enforced (as an admin), I don't see the list of external references in the dialog :

image

I can see the query in the network inspector (which returns 0 results), maybe the filter is not right :

image

@JeremyCloarec
Copy link
Contributor Author

When trying to update a grouping with external reference enforced (as an admin), I don't see the list of external references in the dialog :

That's a bug that we also noticed, that is described here #6074 with the description "Edit an entity while having external reference". It will be worked on in the next step.
Right now the external reference dialog only has the external references already added to the report, and you can not see other external references from the platform in it.

Copy link
Member

@aHenryJard aHenryJard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only PR reading comment for now.

});
});

test('Add and remove observable from Observables tab of a Report as Admin user', async ({ page }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: is it intended that this "test" is not inside a test.describe block ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of! The describe blocks I used before were either to: group up tests that are dependant on each other (for the role/group/user creation), or to run the tests in the describe block with a specific context (the authentication describe block is used to run the authentication in a new browser context, to be able to log in the new user without having to log out the main user).
Since this test is independant from any others, I decided to not include it in a describe.
But the structure of the test file and the usage of describe blocks in general could be up to debate for sure

Comment on lines +28 to +48
test('Create basic user role', async ({ page }) => {
const rolesSettingsPage = new RolesSettingsPage(page);
const rolePage = new RolePage(page);
const roleFormPage = new RoleFormPage(page);

await page.goto('/dashboard/settings/accesses/roles');
await expect(rolesSettingsPage.getSettingsPage()).toBeVisible();
await rolesSettingsPage.getAddRoleButton().click();
await roleFormPage.fillNameInput(noBypassRoleName);
await roleFormPage.getCreateButton().click();
await expect(rolesSettingsPage.getRoleInList(noBypassRoleName)).toBeVisible();
await rolesSettingsPage.getRoleInList(noBypassRoleName).click();
await rolePage.getEditButton().click();
await roleFormPage.getCapabilitiesTab().click();
await roleFormPage.getAccessKnowledgeCheckbox().click();
await expect(roleFormPage.getAccessKnowledgeCheckbox()).toBeChecked();
await roleFormPage.getCreateUpdateKnowledgeCheckbox().click();
await expect(roleFormPage.getCreateUpdateKnowledgeCheckbox()).toBeChecked();
await roleFormPage.getAccessAdministrationCheckbox().click();
await expect(roleFormPage.getAccessAdministrationCheckbox()).toBeChecked();
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random thinking: I guess we could have some way to reuse that piece of test code that creates user/roles and groups I don't mean one groups for all test, but have a methode like createRole(roleName, listOfCapacities) ...etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, we already talked about that with Souad and Jpk actually. We are planning to discuss it more during the e2e workshop

relationAdd: ({ input }) => stixDomainObjectAddRelation(context, context.user, id, input),
relationDelete: ({ toId, relationship_type: relationshipType }) => stixDomainObjectDeleteRelation(context, context.user, id, toId, relationshipType),
relationAdd: ({ input, commitMessage, references }) => stixDomainObjectAddRelation(context, context.user, id, input, { commitMessage, references }),
// eslint-disable-next-line max-len
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you split the line instead ? Or is it really not readable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find a nice way to keep it readable and keep lint happy, so i went with this. Also, in other resolvers like stixCoreRelationship, the relationDelete line was also handled this way

@JeremyCloarec JeremyCloarec changed the title [backend/frontend] Fix enable references behavior when adding entities to report [backend/frontend] Fix enable references behavior when adding entities to containers Apr 3, 2024
@SamuelHassine SamuelHassine merged commit ddbbd7e into master Apr 3, 2024
4 of 6 checks passed
@SamuelHassine SamuelHassine deleted the issue/5884 branch April 3, 2024 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filigran team use to identify PR from the Filigran team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mechanisms inconsistency when "enforce reference" is activated
4 participants