use of io.trino.spi.security.ViewExpression in project trino by trinodb.
the class TestFilterInaccessibleColumns method testMaskingWithCaseOnNotAccessibleColumn.
@Test
public void testMaskingWithCaseOnNotAccessibleColumn() {
accessControl.deny(privilege(USER, "nation.nationkey", SELECT_COLUMN));
accessControl.columnMask(new QualifiedObjectName(CATALOG, TINY_SCHEMA_NAME, "nation"), "comment", USER, new ViewExpression(ADMIN, Optional.of(CATALOG), Optional.of(TINY_SCHEMA_NAME), "CASE nationkey WHEN 6 THEN 'masked-comment' ELSE comment END"));
assertThat(assertions.query("SELECT * FROM nation WHERE name = 'FRANCE'")).matches("VALUES (CAST('FRANCE' AS VARCHAR(25)), BIGINT '3', CAST('masked-comment' AS VARCHAR(152)))");
assertThat(assertions.query("SELECT * FROM nation WHERE name = 'CANADA'")).matches("VALUES (CAST('CANADA' AS VARCHAR(25)), BIGINT '1', CAST('eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold' AS VARCHAR(152)))");
}
use of io.trino.spi.security.ViewExpression in project trino by trinodb.
the class TestFilterInaccessibleColumns method testMaskingWithCaseOnNotAccessibleColumnKO.
@Test
public void testMaskingWithCaseOnNotAccessibleColumnKO() {
accessControl.deny(privilege(USER, "nation.nationkey", SELECT_COLUMN));
accessControl.columnMask(new QualifiedObjectName(CATALOG, TINY_SCHEMA_NAME, "nation"), "comment", USER, new ViewExpression(USER, Optional.of(CATALOG), Optional.of(TINY_SCHEMA_NAME), "CASE nationkey WHEN 6 THEN 'masked-comment' ELSE comment END"));
assertThatThrownBy(() -> assertions.query("SELECT * FROM nation WHERE name = 'FRANCE'")).hasMessage("Access Denied: Cannot select from columns [nationkey, regionkey, name, comment] in table or view local.tiny.nation");
}
use of io.trino.spi.security.ViewExpression in project trino by trinodb.
the class TestFileBasedSystemAccessControl method assertViewExpressionEquals.
private static void assertViewExpressionEquals(Optional<ViewExpression> result, ViewExpression expected) {
assertTrue(result.isPresent());
ViewExpression actual = result.get();
assertEquals(actual.getIdentity(), expected.getIdentity(), "Identity");
assertEquals(actual.getCatalog(), expected.getCatalog(), "Catalog");
assertEquals(actual.getSchema(), expected.getSchema(), "Schema");
assertEquals(actual.getExpression(), expected.getExpression(), "Expression");
}
use of io.trino.spi.security.ViewExpression in project trino by trinodb.
the class TestFileBasedSystemAccessControl method testGetRowFilter.
@Test
public void testGetRowFilter() {
SystemAccessControl accessControl = newFileBasedSystemAccessControl("file-based-system-access-table.json");
assertEquals(accessControl.getRowFilter(ALICE, new CatalogSchemaTableName("some-catalog", "bobschema", "bobcolumns")), Optional.empty());
assertViewExpressionEquals(accessControl.getRowFilter(CHARLIE, new CatalogSchemaTableName("some-catalog", "bobschema", "bobcolumns")), new ViewExpression(CHARLIE.getIdentity().getUser(), Optional.of("some-catalog"), Optional.of("bobschema"), "starts_with(value, 'filter')"));
assertViewExpressionEquals(accessControl.getRowFilter(CHARLIE, new CatalogSchemaTableName("some-catalog", "bobschema", "bobcolumns_with_grant")), new ViewExpression("filter-user", Optional.of("some-catalog"), Optional.of("bobschema"), "starts_with(value, 'filter-with-user')"));
}
use of io.trino.spi.security.ViewExpression in project trino by trinodb.
the class TestFileBasedSystemAccessControl method testGetColumnMask.
@Test
public void testGetColumnMask() {
SystemAccessControl accessControl = newFileBasedSystemAccessControl("file-based-system-access-table.json");
assertEquals(accessControl.getColumnMask(ALICE, new CatalogSchemaTableName("some-catalog", "bobschema", "bobcolumns"), "masked", VARCHAR), Optional.empty());
assertViewExpressionEquals(accessControl.getColumnMask(CHARLIE, new CatalogSchemaTableName("some-catalog", "bobschema", "bobcolumns"), "masked", VARCHAR), new ViewExpression(CHARLIE.getIdentity().getUser(), Optional.of("some-catalog"), Optional.of("bobschema"), "'mask'"));
assertViewExpressionEquals(accessControl.getColumnMask(CHARLIE, new CatalogSchemaTableName("some-catalog", "bobschema", "bobcolumns"), "masked_with_user", VARCHAR), new ViewExpression("mask-user", Optional.of("some-catalog"), Optional.of("bobschema"), "'mask-with-user'"));
}
Aggregations