In line with current security standards, we use with security_enforced
extensively in our code. When doing CI (Continuous Integration) builds or working interactively we use sfdx force:user:permset:assign
to assign permission sets that grant the field level access so the Apex tests pass. And when our product is installed no tests are run so no problem there.
But packaging 2 creates the packaging org on the fly and runs the Apex tests with no hook point to do any org preparation. So what strategy works to get the right field level permissions set?
- Duplicate all the permissions in the
Admin.profile-meta.xml
?- This assumes that the packaging process does use that profile. Does it?
- And that the
Admin.profile-meta.xml
is applied in the packaging org. Is it?
- Assign the permission sets programatically in the
@TestSetup
method of every test? But that then hasMIXED_DML_OPERATION
challenges. - Modify the product code to not do security checks when tests are running. (Yuk.)
- Better approaches?
We are getting test failures on packaging related to custom fields we add to the Event
object and are trying to figure out why.