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

FIX (GraphEngine): @W-13869734@: Fix crash on explicit access level specified in Database.query method #1154

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

MrEminent42
Copy link
Contributor

@MrEminent42 MrEminent42 commented Aug 17, 2023

  • Parses methods in Database class that include a System.AccessLevel as their last parameter.
  • If AccessLevel.USER_MODE is specified, prevents expected validations from being created on the vertex.
    • That way, no violations are thrown in the case that no FLS checks are performed. This is okay because the query is performed in user mode.

Notes:

  • Need to confirm in ValidationConverter#getHolder that childApexValue instanceof ApexStringValue is true IF AND ONLY IF the vertex we are inspecting is one of the Database.whatever methods that could contain an explicit access level.
    • Meaning, is there any other situation in which, when calling convertSoqlQueryInfo(ValidationHolder, ProcessFields, HashSet<SoqlQueryInfo>, boolean), the last boolean (representing an override that makes any SOQL operation safe to perform without FLS validations) should be true?
    • Put another way, Is there any other situation in which a SOQL query's access level could be overridden by an external factor?

Additional notes:

  • Added a new tests to UseWithSharingOnDatabaseOperation to test the Database.query(String, AccessLevel) method specifically when it has an access level specified.
  • Updated SharingPolicySubclassesTest to use a select subset of possible database operations, not all of them. The tests were taking quite a long time. Testing all operations was not necessary since the full breadth of operations is tested in SharingPolicySimpleTest.

Known bugs/limiting behavior:

  • Only the insert, merge, query, undelete, upsert, and update methods of the Database class in Apex are checked for FLS violations. TODO: check all methods, like queryWithBinds, etc.

@MrEminent42 MrEminent42 changed the title FIX (GraphEngine): @W-13869734@: Fix crash on FIX (GraphEngine): @W-13869734@: Fix crash on explicit access level specified in Database.query method Aug 18, 2023
@MrEminent42 MrEminent42 force-pushed the d/W-13869734 branch 2 times, most recently from bfdf195 to 38f0d95 Compare August 21, 2023 20:16
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes these tests to only use a subset of the methods in the Database class. They were taking way too long. Full coverage of all methods is in SharingPolicySimpleTest.java.

"Database.getQueryLocator('SELECT Id, NumberOfEmployees FROM account WHERE NumberOfEmployees = 3 LIMIT 1')",
"Database.getQueryLocatorWithBinds('SELECT Id, NumberOfEmployees FROM account WHERE NumberOfEmployees = 3 LIMIT 1', new Map<String, Object>{'name' => 'KENSINGTON'})",
"Database.getQueryLocator('SELECT Name, NumberOfEmployees FROM account WHERE NumberOfEmployees = 3 LIMIT 1')",
"Database.getQueryLocatorWithBinds('SELECT Name, NumberOfEmployees FROM account WHERE NumberOfEmployees = :i LIMIT 1', new Map<String, Object>{'i' => 3})",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated these because Josh mentioned SELECT Id, .. is not good to have, possibly an error. Also, I made the original binds when I didn't really know what they were, and they didn't make sense.

@MrEminent42 MrEminent42 marked this pull request as ready for review August 21, 2023 20:20
@MrEminent42 MrEminent42 force-pushed the d/W-13869734 branch 2 times, most recently from 53ca55e to bd667f7 Compare August 30, 2023 17:16
…h explicit AccessLevel

@W-13869734@: clean up docs again

@W-13869734@: clean up docs

@W-13869734@: PR feedback, refactor boolean pass-down

@W-13869734@: clean up

@W-13869734@: fix unused test

@W-13869734@: add disabled test for methods in Database class beyond basic 6

@W-13869734@: fix bug expecting validations & crashing when Database.query() and similar were executed in USER_MODE

@W-13869734@: update UseWithSharingOnDatabaseOperation tests

- limit subclasses tests to only a few select database operations, not all of them; significantly speeds up testing
- update the list of DATABASE_METHODS to include Database.query(String, AccessLevel)
@jfeingold35 jfeingold35 merged commit 4cf8f39 into forcedotcom:dev Aug 30, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants