Skip to content

Commit

Permalink
@W-13569669@: update tests to use 2d arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEminent42 committed Jul 26, 2023
1 parent 599ed60 commit fd320e5
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,39 @@ private static Stream<Arguments> provideNoViolationTests() {
Stream.Builder<Arguments> sb = Stream.builder();
Stream<Arguments> databaseOperations = provideSelectDatabaseOperations();

String[] noViolationSharingPolicyCombos = {
String[][] noViolationSharingPolicyCombos = {
// when Two (center column) has "inherited sharing", the calling class (rightmost
// column) must be "with sharing" or "inherited sharing" (entrypoint OK)
"with sharing , inherited sharing , inherited sharing ",
"without sharing , inherited sharing , inherited sharing ",
"inherited sharing , inherited sharing , inherited sharing ",
" , inherited sharing , inherited sharing ",
"with sharing , inherited sharing , with sharing ",
"without sharing , inherited sharing , with sharing ",
"inherited sharing , inherited sharing , with sharing ",
" , inherited sharing , with sharing ",
{"with sharing "," inherited sharing "," inherited sharing ",},
{"without sharing "," inherited sharing "," inherited sharing ",},
{"inherited sharing "," inherited sharing "," inherited sharing ",},
{" "," inherited sharing "," inherited sharing ",},
{"with sharing "," inherited sharing "," with sharing ",},
{"without sharing "," inherited sharing "," with sharing ",},
{"inherited sharing "," inherited sharing "," with sharing ",},
{" "," inherited sharing "," with sharing ",},
// when Two (center column) has "with sharing," anything goes
"with sharing , with sharing , inherited sharing ",
"without sharing , with sharing , inherited sharing ",
"inherited sharing , with sharing , inherited sharing ",
" , with sharing , inherited sharing ",
"with sharing , with sharing , without sharing ",
"without sharing , with sharing , without sharing ",
"inherited sharing , with sharing , without sharing ",
" , with sharing , without sharing ",
"with sharing , with sharing , with sharing ",
"without sharing , with sharing , with sharing ",
"inherited sharing , with sharing , with sharing ",
" , with sharing , with sharing ",
"with sharing , with sharing , ",
"without sharing , with sharing , ",
"inherited sharing , with sharing , ",
" , with sharing , ",
{"with sharing "," with sharing "," inherited sharing ",},
{"without sharing "," with sharing "," inherited sharing ",},
{"inherited sharing "," with sharing "," inherited sharing ",},
{" "," with sharing "," inherited sharing ",},
{"with sharing "," with sharing "," without sharing ",},
{"without sharing "," with sharing "," without sharing ",},
{"inherited sharing "," with sharing "," without sharing ",},
{" "," with sharing "," without sharing ",},
{"with sharing "," with sharing "," with sharing ",},
{"without sharing "," with sharing "," with sharing ",},
{"inherited sharing "," with sharing "," with sharing ",},
{" "," with sharing "," with sharing ",},
{"with sharing "," with sharing "," ",},
{"without sharing "," with sharing "," ",},
{"inherited sharing "," with sharing "," ",},
{" "," with sharing "," ",},
};

databaseOperations.forEach(
operationArg -> {
for (String sharingPolicyCombo : noViolationSharingPolicyCombos) {
String[] policies = sharingPolicyCombo.split(",");
for (String[] policies : noViolationSharingPolicyCombos) {
sb.add(
Arguments.of(
operationArg.get()[0],
Expand Down Expand Up @@ -117,54 +116,53 @@ private static Stream<Arguments> provideViolationTests() {
Stream.Builder<Arguments> sb = Stream.builder();
Stream<Arguments> databaseOperations = provideSelectDatabaseOperations();

String[] violationSharingPolicyCombos = {
String[][] violationSharingPolicyCombos = {
// when Two (center column) has no declaration, look to its parent, One (left column)
"without sharing , , inherited sharing ",
"without sharing , , without sharing ",
"without sharing , , with sharing ",
"without sharing , , ",
{"without sharing "," "," inherited sharing ",},
{"without sharing "," "," without sharing ",},
{"without sharing "," "," with sharing ",},
{"without sharing "," "," ",},
// when Two (center) has no declaration and One (parent, left col) has "inherited
// sharing", look to calling class (right col). running as "without" or omitted =
// violation.
"inherited sharing , , without sharing ",
"inherited sharing , , ",
{"inherited sharing "," "," without sharing ",},
{"inherited sharing "," "," ",},
// when neither Two nor One (center, left cols) have declarations, look to calling
// class (right col). no declaration or without sharing means violation
" , , ",
" , , without sharing ",
{" "," "," ",},
{" "," "," without sharing ",},
// when Two (center col) has "inherited sharing" and it inherits "without sharing" or no
// declaration from its calling class (right col), this is a violation
"with sharing , inherited sharing , without sharing ",
"without sharing , inherited sharing , without sharing ",
"inherited sharing , inherited sharing , without sharing ",
" , inherited sharing , without sharing ",
"with sharing , inherited sharing , ",
"without sharing , inherited sharing , ",
"inherited sharing , inherited sharing , ",
" , inherited sharing , ",
{"with sharing "," inherited sharing "," without sharing ",},
{"without sharing "," inherited sharing "," without sharing ",},
{"inherited sharing "," inherited sharing "," without sharing ",},
{" "," inherited sharing "," without sharing ",},
{"with sharing "," inherited sharing "," ",},
{"without sharing "," inherited sharing "," ",},
{"inherited sharing "," inherited sharing "," ",},
{" "," inherited sharing "," ",},
// when Two runs "without sharing", it's a violation no matter what
"with sharing , without sharing , inherited sharing ",
"without sharing , without sharing , inherited sharing ",
"inherited sharing , without sharing , inherited sharing ",
" , without sharing , inherited sharing ",
"with sharing , without sharing , without sharing ",
"without sharing , without sharing , without sharing ",
"inherited sharing , without sharing , without sharing ",
" , without sharing , without sharing ",
"with sharing , without sharing , with sharing ",
"without sharing , without sharing , with sharing ",
"inherited sharing , without sharing , with sharing ",
" , without sharing , with sharing ",
"with sharing , without sharing , ",
"without sharing , without sharing , ",
"inherited sharing , without sharing , ",
" , without sharing , ",
{"with sharing "," without sharing "," inherited sharing ",},
{"without sharing "," without sharing "," inherited sharing ",},
{"inherited sharing "," without sharing "," inherited sharing ",},
{" "," without sharing "," inherited sharing ",},
{"with sharing "," without sharing "," without sharing ",},
{"without sharing "," without sharing "," without sharing ",},
{"inherited sharing "," without sharing "," without sharing ",},
{" "," without sharing "," without sharing ",},
{"with sharing "," without sharing "," with sharing ",},
{"without sharing "," without sharing "," with sharing ",},
{"inherited sharing "," without sharing "," with sharing ",},
{" "," without sharing "," with sharing ",},
{"with sharing "," without sharing "," ",},
{"without sharing "," without sharing "," ",},
{"inherited sharing "," without sharing "," ",},
{" "," without sharing "," ",},
};

databaseOperations.forEach(
operationArg -> {
for (String sharingPolicyCombo : violationSharingPolicyCombos) {
String[] policies = sharingPolicyCombo.split(",");
for (String[] policies : violationSharingPolicyCombos) {
sb.add(
Arguments.of(
operationArg.get()[0],
Expand Down Expand Up @@ -196,25 +194,24 @@ private static Stream<Arguments> provideWarningParentTests() {
Stream.Builder<Arguments> sb = Stream.builder();
Stream<Arguments> databaseOperations = provideSelectDatabaseOperations();

String[] warningParentSharingPolicyCombos = {
String[][] warningParentSharingPolicyCombos = {
// when Two (center col) has no declaration, but it inherits "with sharing" from One
// (left col), it runs as "with sharing," but has a warning message of implicit
// inheritance from its parent.
"with sharing , , inherited sharing ",
"with sharing , , without sharing ",
"with sharing , , with sharing ",
"with sharing , , ",
{"with sharing "," "," inherited sharing ",},
{"with sharing "," "," without sharing ",},
{"with sharing "," "," with sharing ",},
{"with sharing "," "," ",},
// when Two (center col) has no declaration and One (left col) has "inherited sharing,"
// and the calling class (right col) has "with sharing" or "inherited sharing," it runs
// as "with sharing," but has a warning message of implicit inheritance from its parent.
"inherited sharing , , with sharing ",
"inherited sharing , , inherited sharing ",
{"inherited sharing "," "," with sharing ",},
{"inherited sharing "," "," inherited sharing ",},
};

databaseOperations.forEach(
operationArg -> {
for (String sharingPolicyCombo : warningParentSharingPolicyCombos) {
String[] policies = sharingPolicyCombo.split(",");
for (String[] policies : warningParentSharingPolicyCombos) {
sb.add(
Arguments.of(
operationArg.get()[0],
Expand Down Expand Up @@ -246,18 +243,17 @@ private static Stream<Arguments> provideWarningCallingTests() {
Stream.Builder<Arguments> sb = Stream.builder();
Stream<Arguments> databaseOperations = provideSelectDatabaseOperations();

String[] warningCallingSharingPolicyCombos = {
String[][] warningCallingSharingPolicyCombos = {
// When neither Two nor One (center, left cols) have explicit sharing policies, but they
// inherit a safe sharing policy from the calling class (right col), it is safe to run,
// but this needs a warning message about implicit inheritance from the calling class.
" , , inherited sharing ",
" , , with sharing ",
{" "," "," inherited sharing ",},
{" "," "," with sharing ",},
};

databaseOperations.forEach(
operationArg -> {
for (String sharingPolicyCombo : warningCallingSharingPolicyCombos) {
String[] policies = sharingPolicyCombo.split(",");
for (String[] policies : warningCallingSharingPolicyCombos) {
sb.add(
Arguments.of(
operationArg.get()[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,24 @@ private static Stream<Arguments> provideNoViolationTests() {
Stream<Arguments> databaseOperations = provideSelectDatabaseOperations();

// spotless:off
String[] noViolationSharingPolicyCombos = {
String[][] noViolationSharingPolicyCombos = {
// anything "inherited sharing" inherits from the calling class, overriding the parent (left column).
// In this case, since MyClass is the entrypoint, it runs as "with sharing" (as noted in Apex documentation).
"with sharing , inherited sharing ",
"inherited sharing , inherited sharing ",
"without sharing , inherited sharing ",
" , inherited sharing ",
// anything "with sharing" overrides its parent to be safe.
"with sharing , with sharing ",
"without sharing , with sharing ",
"inherited sharing , with sharing ",
" , with sharing ",
{"with sharing "," inherited sharing ",},
{"inherited sharing "," inherited sharing ",},
{"without sharing "," inherited sharing ",},
{" "," inherited sharing ",},
// anything "with sharing" overrides its parent to be safe.
{"with sharing "," with sharing ",},
{"without sharing "," with sharing ",},
{"inherited sharing "," with sharing ",},
{" "," with sharing ",},
};
// spotless:on

databaseOperations.forEach(
operationArg -> {
for (String sharingPolicyCombo : noViolationSharingPolicyCombos) {
String[] policies = sharingPolicyCombo.split(",");
for (String[] policies : noViolationSharingPolicyCombos) {
sb.add(
Arguments.of(
operationArg.get()[0],
Expand All @@ -87,20 +86,19 @@ private static Stream<Arguments> provideViolationTests() {
Stream<Arguments> databaseOperations = provideSelectDatabaseOperations();

// spotless:off
String[] violationSharingPolicyCombos = {
"without sharing , ",
"with sharing , without sharing ",
"without sharing , without sharing ",
"inherited sharing , without sharing ",
" , without sharing ",
" , ",
String[][] violationSharingPolicyCombos = {
{"without sharing "," ",},
{"with sharing "," without sharing ",},
{"without sharing "," without sharing ",},
{"inherited sharing "," without sharing ",},
{" "," without sharing ",},
{" "," ",},
};
// spotless:on

databaseOperations.forEach(
operationArg -> {
for (String sharingPolicyCombo : violationSharingPolicyCombos) {
String[] policies = sharingPolicyCombo.split(",");
for (String[] policies : violationSharingPolicyCombos) {
sb.add(
Arguments.of(
operationArg.get()[0],
Expand Down Expand Up @@ -130,16 +128,15 @@ private static Stream<Arguments> provideWarningParentTests() {
Stream<Arguments> databaseOperations = provideSelectDatabaseOperations();

// spotless:off
String[] warningParentSharingPolicyCombos = {
"with sharing , ",
"inherited sharing , ",
String[][] warningParentSharingPolicyCombos = {
{"with sharing "," ",},
{"inherited sharing "," ",},
};
// spotless:on

databaseOperations.forEach(
operationArg -> {
for (String sharingPolicyCombo : warningParentSharingPolicyCombos) {
String[] policies = sharingPolicyCombo.split(",");
for (String[] policies : warningParentSharingPolicyCombos) {
sb.add(
Arguments.of(
operationArg.get()[0],
Expand Down

0 comments on commit fd320e5

Please sign in to comment.