use of io.trino.spi.security.ViewExpression in project trino by trinodb.
the class TestColumnMask method testDifferentIdentity.
@Test
public void testDifferentIdentity() {
accessControl.reset();
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "orders"), "orderkey", RUN_AS_USER, new ViewExpression(RUN_AS_USER, Optional.of(CATALOG), Optional.of("tiny"), "100"));
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "orders"), "orderkey", USER, new ViewExpression(RUN_AS_USER, Optional.of(CATALOG), Optional.of("tiny"), "(SELECT sum(orderkey) FROM orders)"));
assertThat(assertions.query("SELECT max(orderkey) FROM orders")).matches("VALUES BIGINT '1500000'");
}
use of io.trino.spi.security.ViewExpression in project trino by trinodb.
the class TestColumnMask method testMaterializedView.
@Test
public void testMaterializedView() {
// mask materialized view columns
accessControl.reset();
accessControl.columnMask(new QualifiedObjectName(MOCK_CATALOG, "default", "nation_fresh_materialized_view"), "name", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "reverse(name)"));
accessControl.columnMask(new QualifiedObjectName(MOCK_CATALOG, "default", "nation_materialized_view"), "name", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "reverse(name)"));
accessControl.columnMask(new QualifiedObjectName(MOCK_CATALOG, "default", "materialized_view_with_casts"), "name", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "reverse(name)"));
assertThat(assertions.query(Session.builder(SESSION).setIdentity(Identity.forUser(USER).build()).build(), "SELECT name FROM mock.default.nation_fresh_materialized_view WHERE nationkey = 1")).matches("VALUES CAST('ANITNEGRA' AS VARCHAR(25))");
assertThat(assertions.query(Session.builder(SESSION).setIdentity(Identity.forUser(USER).build()).build(), "SELECT name FROM mock.default.nation_materialized_view WHERE nationkey = 1")).matches("VALUES CAST('ANITNEGRA' AS VARCHAR(25))");
assertThat(assertions.query(Session.builder(SESSION).setIdentity(Identity.forUser(USER).build()).build(), "SELECT name FROM mock.default.materialized_view_with_casts WHERE nationkey = 1")).matches("VALUES CAST('RA' AS VARCHAR(2))");
}
use of io.trino.spi.security.ViewExpression in project trino by trinodb.
the class TestFilterInaccessibleColumns method testRowFilterOnNotAccessibleColumn.
@Test
public void testRowFilterOnNotAccessibleColumn() {
accessControl.rowFilter(new QualifiedObjectName(CATALOG, TINY_SCHEMA_NAME, "nation"), USER, new ViewExpression(ADMIN, Optional.of(CATALOG), Optional.of(TINY_SCHEMA_NAME), "comment IS NOT null"));
accessControl.deny(privilege(USER, "nation.comment", SELECT_COLUMN));
assertThat(assertions.query("SELECT * FROM nation WHERE name = 'FRANCE'")).matches("VALUES (BIGINT '6', CAST('FRANCE' AS VARCHAR(25)), BIGINT '3')");
}
use of io.trino.spi.security.ViewExpression in project trino by trinodb.
the class TestFilterInaccessibleColumns method testRowFilterOnNotAccessibleColumnKO.
@Test
public void testRowFilterOnNotAccessibleColumnKO() {
accessControl.rowFilter(new QualifiedObjectName(CATALOG, TINY_SCHEMA_NAME, "nation"), USER, new ViewExpression(USER, Optional.of(CATALOG), Optional.of(TINY_SCHEMA_NAME), "comment IS NOT null"));
accessControl.deny(privilege(USER, "nation.comment", SELECT_COLUMN));
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 TestFilterInaccessibleColumns method testMaskingOnAccessibleColumn.
@Test
public void testMaskingOnAccessibleColumn() {
accessControl.columnMask(new QualifiedObjectName(CATALOG, TINY_SCHEMA_NAME, "nation"), "nationkey", USER, new ViewExpression(ADMIN, Optional.of(CATALOG), Optional.of(TINY_SCHEMA_NAME), "-nationkey"));
assertThat(assertions.query("SELECT * FROM nation WHERE name = 'FRANCE'")).matches("VALUES (BIGINT '-6',CAST('FRANCE' AS VARCHAR(25)), BIGINT '3', CAST('refully final requests. regular, ironi' AS VARCHAR(152)))");
}
Aggregations