SafeLoggableData implements KeyValueServiceLogArbitrator { @Override public boolean isRowComponentNameSafe(TableReference tableReference, String rowComponentName) { return permittedRowComponents().containsKey(tableReference) && permittedRowComponents().get(tableReference).contains(rowComponentName); }  abstract Set<TableReference> permittedTableReferences(); @Value.Lazy Set<String> permittedInternalTableReferences(); abstract Map<TableReference, Set<String>> permittedRowComponents(); abstract Map<TableReference, Set<String>> permittedColumnNames(); @Override boolean isTableReferenceSafe(TableReference tableReference); @Override boolean isInternalTableReferenceSafe(String internalTableReference); @Override boolean isRowComponentNameSafe(TableReference tableReference, String rowComponentName); @Override boolean isColumnNameSafe(TableReference tableReference, String columnName);  }
@Test public void rowComponentsExplicitlyMarkedSafeAreSafe() { SafeLoggableData safeLoggableData = ImmutableSafeLoggableData.builder() .putPermittedRowComponents(TABLE_REFERENCE_1, ImmutableSet.of(ROW_COMPONENT_1)) .build(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_1, ROW_COMPONENT_1)).isTrue(); }
@Test public void rowComponentsNotExplicitlyMarkedSafeAreUnsafe() { SafeLoggableData safeLoggableData = ImmutableSafeLoggableData.builder() .putPermittedRowComponents(TABLE_REFERENCE_1, ImmutableSet.of(ROW_COMPONENT_1)) .build(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_1, ROW_COMPONENT_2)).isFalse(); }
@Test public void rowComponentsMarkedSafeOnlyForOtherTablesAreNotSafe() { SafeLoggableData safeLoggableData = ImmutableSafeLoggableData.builder() .putPermittedRowComponents(TABLE_REFERENCE_1, ImmutableSet.of(ROW_COMPONENT_1)) .putPermittedRowComponents(TABLE_REFERENCE_2, ImmutableSet.of(ROW_COMPONENT_2)) .build(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_1, ROW_COMPONENT_2)).isFalse(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_2, ROW_COMPONENT_1)).isFalse(); }
@Test public void rowComponentsInUnknownTablesAreNotSafe() { SafeLoggableData safeLoggableData = ImmutableSafeLoggableData.builder().build(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_3, ROW_COMPONENT_1)).isFalse(); }
@Test public void columnNamesNotExplicitlyMarkedSafeAreUnsafe() { SafeLoggableData safeLoggableData = ImmutableSafeLoggableData.builder() .putPermittedColumnNames(TABLE_REFERENCE_1, ImmutableSet.of(COLUMN_NAME_1)) .build(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_1, COLUMN_NAME_2)).isFalse(); }
@Test public void columnNamesMarkedSafeOnlyForOtherTablesAreNotSafe() { SafeLoggableData safeLoggableData = ImmutableSafeLoggableData.builder() .putPermittedColumnNames(TABLE_REFERENCE_1, ImmutableSet.of(COLUMN_NAME_1)) .putPermittedColumnNames(TABLE_REFERENCE_2, ImmutableSet.of(COLUMN_NAME_2)) .build(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_1, COLUMN_NAME_2)).isFalse(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_2, COLUMN_NAME_1)).isFalse(); }
@Test public void columnNamesInUnknownTablesAreNotSafe() { SafeLoggableData safeLoggableData = ImmutableSafeLoggableData.builder().build(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_3, ROW_COMPONENT_1)).isFalse(); }
@Test public void rowComponentsDoNotInheritSafetyFromTableReferences() { SafeLoggableData safeLoggableData = ImmutableSafeLoggableData.builder() .addPermittedTableReferences(TABLE_REFERENCE_1) .build(); assertThat(safeLoggableData.isRowComponentNameSafe(TABLE_REFERENCE_1, ROW_COMPONENT_1)).isFalse(); }