Skip to content

Commit

Permalink
Merge branch 'gh-2455-FederatedStore-getTraits-audit' into gh-2357-fe…
Browse files Browse the repository at this point in the history
…deratedstore-federated-operation

# Conflicts:
#	store-implementation/federated-store/src/main/java/uk/gov/gchq/gaffer/federatedstore/operation/handler/impl/FederatedGetTraitsHandler.java
  • Loading branch information
GCHQDev404 committed Jul 6, 2021
2 parents 1d2f4b1 + ed912c8 commit 687c293
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ public Set<StoreTrait> getTraits(final FederatedOperation op, final Context cont
for (final Graph graph : graphs) {
try {
Set<StoreTrait> execute = graph.execute(getTraits, context);
//Deprecate, although a FedOp is being used that can specify merging, it is ignored.
if (firstPass) {
traits.addAll(execute);
firstPass = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties;
import uk.gov.gchq.gaffer.commonutil.StreamUtil;
import uk.gov.gchq.gaffer.federatedstore.exception.StorageException;
import uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperation;
import uk.gov.gchq.gaffer.graph.Graph;
import uk.gov.gchq.gaffer.graph.GraphConfig;
import uk.gov.gchq.gaffer.graph.GraphSerialisable;
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.library.GraphLibrary;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.schema.Schema;
import uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition;
import uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition;
Expand All @@ -54,6 +56,7 @@
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static uk.gov.gchq.gaffer.federatedstore.FederatedGraphStorage.GRAPH_IDS_NOT_VISIBLE;
import static uk.gov.gchq.gaffer.federatedstore.util.FederatedStoreUtil.getFederatedWrappedTraits;
import static uk.gov.gchq.gaffer.store.TestTypes.DIRECTED_EITHER;
import static uk.gov.gchq.gaffer.user.StoreUser.AUTH_1;
import static uk.gov.gchq.gaffer.user.StoreUser.AUTH_2;
Expand Down Expand Up @@ -415,7 +418,7 @@ public void shouldGetSchemaForBlankUserWhenPermissiveReadAccessPredicateConfigur
public void shouldGetTraitsForAddingUser() throws Exception {
graphStorage.put(a, new FederatedAccess(Sets.newHashSet(X), X));
graphStorage.put(b, access);
final Set<StoreTrait> traits = graphStorage.getTraits(null, new Context(testUser));
final Set<StoreTrait> traits = graphStorage.getTraits(new FederatedOperation.Builder().op(new GetTraits.Builder().currentTraits(false).build()).build(), new Context(testUser));
assertNotEquals(5, traits.size(), "Revealing hidden traits");
assertEquals(10, traits.size());
}
Expand All @@ -424,15 +427,15 @@ public void shouldGetTraitsForAddingUser() throws Exception {
public void shouldNotGetTraitsForAddingUserWhenBlockingReadAccessPredicateConfigured() throws Exception {
graphStorage.put(a, new FederatedAccess(Sets.newHashSet(X), X));
graphStorage.put(b, blockingReadAccess);
final Set<StoreTrait> traits = graphStorage.getTraits(null, new Context(blankUser));
final Set<StoreTrait> traits = graphStorage.getTraits(getFederatedWrappedTraits(), new Context(blankUser));
assertEquals(0, traits.size(), "Revealing hidden traits");
}

@Test
public void shouldGetTraitsForAuthUser() throws Exception {
graphStorage.put(a, new FederatedAccess(Sets.newHashSet(X), X));
graphStorage.put(b, access);
final Set<StoreTrait> traits = graphStorage.getTraits(null, new Context(authUser));
final Set<StoreTrait> traits = graphStorage.getTraits(new FederatedOperation.Builder().op(new GetTraits.Builder().currentTraits(false).build()).build(), new Context(authUser));
assertNotEquals(5, traits.size(), "Revealing hidden traits");
assertEquals(10, traits.size());
}
Expand All @@ -441,15 +444,15 @@ public void shouldGetTraitsForAuthUser() throws Exception {
public void shouldNotGetTraitsForBlankUser() throws Exception {
graphStorage.put(a, new FederatedAccess(Sets.newHashSet(X), X));
graphStorage.put(b, access);
final Set<StoreTrait> traits = graphStorage.getTraits(null, new Context(new Context(blankUser)));
final Set<StoreTrait> traits = graphStorage.getTraits(getFederatedWrappedTraits(), new Context(new Context(blankUser)));
assertEquals(0, traits.size(), "Revealing hidden traits");
}

@Test
public void shouldGetTraitsForBlankUserWhenPermissiveReadAccessPredicateConfigured() throws Exception {
graphStorage.put(a, new FederatedAccess(Sets.newHashSet(X), X));
graphStorage.put(b, permissiveReadAccess);
final Set<StoreTrait> traits = graphStorage.getTraits(null, new Context(blankUser));
final Set<StoreTrait> traits = graphStorage.getTraits(new FederatedOperation.Builder().op(new GetTraits.Builder().currentTraits(false).build()).build(), new Context(blankUser));
assertNotEquals(5, traits.size(), "Revealing hidden traits");
assertEquals(10, traits.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public class FederatedStoreSchemaTest {
private FederatedStore fStore;
private static final FederatedStoreProperties FEDERATED_PROPERTIES = new FederatedStoreProperties();

private static Class currentClass = new Object() { }.getClass().getEnclosingClass();
private static Class currentClass = new Object() {
}.getClass().getEnclosingClass();
private static final AccumuloProperties PROPERTIES = AccumuloProperties.loadStoreProperties(StreamUtil.openStream(currentClass, "properties/singleUseAccumuloStore.properties"));

@BeforeEach
Expand Down Expand Up @@ -283,16 +284,18 @@ public void shouldThrowValidationMissingPropertyWithOverlappingSchemas() throws
// Then
OperationException exception = assertThrows(OperationException.class, () -> {
fStore.execute(new AddElements.Builder()
.input(new Edge.Builder()
.group("e1")
.source("source1")
.dest("dest2")
.property("prop1", "value1")
.build())
.build(), testContext);
.input(new Edge.Builder()
.group("e1")
.source("source1")
.dest("dest2")
.property("prop1", "value1")
.build())
.build(), testContext);
});
assertTrue(exception.getMessage().contains("returned false for properties: {prop2: null}"));
String message = exception.getCause().getMessage();
assertTrue(message.contains("returned false for properties: {prop2: null}"), message);
}

private SchemaEdgeDefinition getProp(final String propName) {
return new SchemaEdgeDefinition.Builder()
.source(STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;
import uk.gov.gchq.gaffer.store.schema.Schema;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -93,11 +92,11 @@ public void shouldGetZeroTraitsForEmptyStore() throws Exception {
new Context(testUser()));

// Then
assertEquals(Collections.emptySet(), traits);
assertEquals(null, traits);
}

@Test
public void shouldGetZeroTraitsForEmptyStoreWithCurrentTraits() throws Exception {
public void shouldGetNullTraitsForEmptyStoreWithCurrentTraits() throws Exception {
// Given
federatedStore.initialise(FED_STORE_ID, null, properties);
assertEquals(0, federatedStore.getAllGraphIds(testUser()).size(),
Expand All @@ -109,7 +108,7 @@ public void shouldGetZeroTraitsForEmptyStoreWithCurrentTraits() throws Exception
.build(), new Context(testUser()));

// Then
assertEquals(Collections.emptySet(), traits);
assertEquals(null, traits);
}

@Test
Expand Down Expand Up @@ -215,7 +214,7 @@ public void shouldGetCurrentTraitsWhenContainsStoreWithOtherTraitsWithOptions()
POST_AGGREGATION_FILTERING,
POST_TRANSFORMATION_FILTERING
),
traits);
Sets.newHashSet(traits));
}

public static class TestStoreImpl extends Store {
Expand Down

0 comments on commit 687c293

Please sign in to comment.