use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestColumnMask method testReferenceInUsingClause.
@Test
public void testReferenceInUsingClause() {
accessControl.reset();
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "orders"), "orderkey", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "IF(orderkey = 1, -orderkey)"));
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "lineitem"), "orderkey", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "IF(orderkey = 1, -orderkey)"));
assertThat(assertions.query("SELECT count(*) FROM orders JOIN lineitem USING (orderkey)")).matches("VALUES BIGINT '6'");
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestColumnMask method testSqlInjection.
@Test
public void testSqlInjection() {
accessControl.reset();
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "nation"), "name", USER, new ViewExpression(USER, Optional.of(CATALOG), Optional.of("tiny"), "(SELECT name FROM region WHERE regionkey = 0)"));
assertThat(assertions.query("WITH region(regionkey, name) AS (VALUES (0, 'ASIA'))" + "SELECT name FROM nation ORDER BY name LIMIT 1")).matches(// if sql-injection would work then query would return ASIA
"VALUES CAST('AFRICA' AS VARCHAR(25))");
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestColumnMask method testMultipleMasksOnDifferentColumns.
@Test
public void testMultipleMasksOnDifferentColumns() {
accessControl.reset();
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "orders"), "custkey", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "-custkey"));
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "orders"), "orderstatus", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "'X'"));
assertThat(assertions.query("SELECT custkey, orderstatus FROM orders WHERE orderkey = 1")).matches("VALUES (BIGINT '-370', 'X')");
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestColumnMask method testCoercibleType.
@Test
public void testCoercibleType() {
accessControl.reset();
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "orders"), "clerk", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "CAST(clerk AS VARCHAR(5))"));
assertThat(assertions.query("SELECT clerk FROM orders WHERE orderkey = 1")).matches("VALUES CAST('Clerk' AS VARCHAR(15))");
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestColumnMask method testMultipleMasksOnSameColumn.
@Test
public void testMultipleMasksOnSameColumn() {
accessControl.reset();
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "orders"), "custkey", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "-custkey"));
accessControl.columnMask(new QualifiedObjectName(CATALOG, "tiny", "orders"), "custkey", USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "custkey * 2"));
assertThat(assertions.query("SELECT custkey FROM orders WHERE orderkey = 1")).matches("VALUES BIGINT '-740'");
}
Aggregations