@@ -79,22 +79,20 @@ private class fflib_SecurityUtilsTest {
7979 }
8080
8181 @TestVisible
82- static User setupTestUser (String profileName ){
82+ static User setupTestUser (Boolean limitedAccess ){
8383 Profile p ;
84- Boolean applyReadOnlyPermissionSet = false ;
85- if (profileName == ' Read Only' ) {
86- applyReadOnlyPermissionSet = true ;
84+
85+ if (limitedAccess ) {
8786 try {
88- p = getProfile (profileName );
87+ p = getProfile (' Minimum Access - Salesforce ' );
8988 } catch (QueryException ex ) {
9089 if (ex .getMessage ().contains (' List has no rows for assignment to SObject' )) {
91- // #315 If the "Read Only" Profile is absent, then assume it's a Spring '21 org and see if there's a
92- // "Minimum Access - Salesforce" Profile we can use instead.
93- p = getProfile (' Minimum Access - Salesforce' );
90+ // #440 - not ideal, but we'll fall back to the rather liberally permissioned 'Read Only' profile that exists in very old orgs
91+ p = getProfile (' Read Only' );
9492 }
9593 }
9694 } else {
97- p = getProfile (profileName );
95+ p = getProfile (' System Administrator ' );
9896 }
9997
10098 // username global uniqueness is still enforced in tests
@@ -118,7 +116,7 @@ private class fflib_SecurityUtilsTest {
118116 );
119117 insert usr ;
120118
121- if (applyReadOnlyPermissionSet ) {
119+ if (limitedAccess ) {
122120 // #315 We need to assign the Perm Set to grant Account "Read" access
123121 PermissionSet accountReadPS = [SELECT Id FROM PermissionSet WHERE Name = ' ReadOnlyPermissionSet' ];
124122 PermissionSetAssignment psa = new PermissionSetAssignment (AssigneeId = usr .Id , PermissionSetId = accountReadPS .Id );
@@ -129,7 +127,7 @@ private class fflib_SecurityUtilsTest {
129127
130128 @isTest
131129 static void readonly_field_access () {
132- User testUser = setupTestUser (' Read Only ' );
130+ User testUser = setupTestUser (true );
133131 System .runAs (testUser ){
134132 {
135133 fflib_SecurityUtils .SecurityException ex ;
@@ -172,7 +170,7 @@ private class fflib_SecurityUtilsTest {
172170
173171 @isTest
174172 static void readonly_object_access () {
175- User testUser = setupTestUser (' Read Only ' );
173+ User testUser = setupTestUser (true );
176174 System .runAs (testUser ){
177175 {
178176 fflib_SecurityUtils .SecurityException ex ;
@@ -226,7 +224,7 @@ private class fflib_SecurityUtilsTest {
226224
227225 @isTest
228226 static void readonly_objectAndField_access () {
229- User testUser = setupTestUser (' Read Only ' );
227+ User testUser = setupTestUser (true );
230228 System .runAs (testUser ){
231229 {
232230 fflib_SecurityUtils .SecurityException ex ;
@@ -311,7 +309,7 @@ private class fflib_SecurityUtilsTest {
311309
312310 @isTest
313311 static void sysadmin_objectAndField_access () {
314- User testUser = setupTestUser (' System Administrator ' );
312+ User testUser = setupTestUser (false );
315313 System .runAs (testUser ){
316314 fflib_SecurityUtils .checkInsert (
317315 Account .SObjectType ,
0 commit comments