Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1419 from finos/1417-corrected-fieldspec-permits-…
Browse files Browse the repository at this point in the history
…for-whitelist

fix(#1417): added whitelist check to permits fucntion in fieldSpec
  • Loading branch information
hashbyhayter authored Oct 4, 2019
2 parents 1becbc2 + 412ed79 commit ef95162
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public boolean permits(Object value) {
return false;
}

if (whitelist != null && !whitelist.list().contains(value)) {
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

class FieldSpecTests {
Expand Down Expand Up @@ -229,6 +230,20 @@ public StringGenerator createGenerator() {
assertFalse(spec.permits("Anything"));
}

@Test
void permits_whenNotInWhiteList_returnsFalse() {
FieldSpec spec = FieldSpec.fromList(DistributedList.singleton(10));

assertFalse(spec.permits(11));
}

@Test
void permits_whenInWhiteList_returnsTrue() {
FieldSpec spec = FieldSpec.fromList(DistributedList.singleton(10));

assertTrue(spec.permits(10));
}

private class MockedRestrictions implements TypedRestrictions {
private final boolean isEqual;

Expand Down

0 comments on commit ef95162

Please sign in to comment.