Trying to develop some test classes around security and noticed this issue and was curious if anyone else has found this, is it a bug, and have you been able to work around it within the system.runAs in the test methods:
ISSUE:
In test methods when getting the userrecordaccess.maxaccesslevel for ANY record to which the running user only has READ access, the MAXACCESSLEVEL ALWAYS returs 'Transfer'.
This is NOT the case though as the user should only have read access.
Steps to recreate:
- Create a record to which a user only has READ access.
- Replace the IDs in the below pseudo code with the user id and record id as appropriate
- You will see that calling the UserRecordAccess using the userid and recorded outside of the runAs produces the 'Read' result
- Inside the runAs the result is 'Transfer' and the assertion fails (and yes actually querying the userrecordaccess produces the same 'Transfer' result)
@isTest(SEEALLDATA = TRUE)
private static void test_one(){
User popAdmin = [Select ID From User Where ID = '005F0000003GluW'];
UserRecordAccess ura = [Select RecordID, MaxAccessLevel From UserRecordAccess Where UserID = '005F0000003GluW' AND RecordID = '003L000000Lb1cF'];
system.assertEquals('Read',ura.MaxAccessLevel);
system.runAs(popAdmin){
contact c = [Select UserRecordAccess.MaxAccessLevel From Contact Where ID = '003L000000Lb1cF'];
system.assertEquals('Read',c.UserRecordAccess.MaxAccessLevel);
}
}
I fail to see why the MAXACCESSLEVEL is being returned as 'Transfer' using the new MaxAccessLevel in the record Query ran inside the runAs block. I am curious to know if this is a bug or is running as expected