Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.salesforce.exception.UnexpectedException;
import com.salesforce.exception.UnimplementedMethodException;
import com.salesforce.exception.UserActionException;
import com.salesforce.graph.DeepCloneable;
import com.salesforce.graph.ops.ApexStandardLibraryUtil;
import com.salesforce.graph.ops.CloneUtil;
Expand Down Expand Up @@ -171,14 +170,12 @@ private static AbstractSanitizableValue<?> buildSanitizedValue(
} else if (sanitizableValue instanceof ApexSoqlValue) {
sanitizedValue =
buildSanitizedValue(builder, (SoqlExpressionVertex) sanitizableValueVertex);
} else if (sanitizableValue instanceof ApexSingleValue) {
} else if (sanitizableValue instanceof ApexSingleValue
|| sanitizableValue instanceof ApexCustomValue) {
sanitizedValue =
builder.declarationVertex(SyntheticTypedVertex.get("List<SObject>"))
.withStatus(ValueStatus.INDETERMINANT)
.buildList();
} else if (sanitizableValue instanceof ApexCustomValue) {
throw new UserActionException(
"Action needed: Do not use stripInaccessible() check on custom settings since custom settings expect only CRUD");
} else {
throw new UnexpectedException(
"ApexValue type not handled for stripInaccessible call: " + sanitizableValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ public void testAccessDecisionValueCreation() {
firstItem.getTypeVertex().get().getCanonicalType(), equalToIgnoringCase("Account"));
}

@Test
public void testCustomSettings() {
String[] sourceCode = {
"public class MyClass {\n"
+ " public static void doSomething() {\n"
+ " MySettings__c ms = MySettings__c.getOrgDefaults();\n"
+ " SObjectAccessDecision sd = Security.stripInaccessible(AccessType.UPDATABLE, ms);\n"
+ " System.debug(sd.getRecords());\n"
+ " }\n"
+ "}\n"
};

TestRunner.Result<SystemDebugAccumulator> result = TestRunner.walkPath(g, sourceCode);
SystemDebugAccumulator visitor = result.getVisitor();

final ApexListValue outputListValue = visitor.getSingletonResult();
assertThat(
outputListValue.isSanitized(
MethodBasedSanitization.SanitizerMechanism.STRIP_INACCESSIBLE,
FlsConstants.StripInaccessibleAccessType.UPDATABLE),
equalTo(true));
assertThat(outputListValue.isIndeterminant(), equalTo(true));
}

@Test
public void testAccessDecisionValueIncorrectAccessType() {
String[] sourceCode = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.salesforce.rules.fls.apex;

import com.salesforce.exception.UserActionException;
import com.salesforce.rules.ApexFlsViolationRule;
import com.salesforce.testutils.BaseFlsTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -32,20 +30,4 @@ public void testValidCase() {

assertNoViolation(rule, sourceCode);
}

@Test
public void testRejectCustomSettingFlsCheck() {
String[] sourceCode = {
"public class MyClass {\n"
+ " public static void foo() {\n"
+ " MySettings__c ms = MySettings__c.getOrgDefaults();\n"
+ " SObjectAccessDecision sd = Security.stripInaccessible(AccessType.UPDATABLE, ms);\n"
+ " update sd.getRecords();\n"
+ " }\n"
+ "}\n"
};

Assertions.assertThrows(
UserActionException.class, () -> assertNoViolation(rule, sourceCode));
}
}