bowenliang123 commented on code in PR #5656:
URL: https://github.com/apache/kyuubi/pull/5656#discussion_r1387893579
##########
extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/RangerSparkExtensionSuite.scala:
##########
@@ -1240,4 +1240,70 @@ class HiveCatalogRangerSparkExtensionSuite extends
RangerSparkExtensionSuite {
}
}
}
+
+ test("Table Command location privilege") {
+ val db1 = defaultDb
+ val table1 = "table1"
+ val table2 = "table2"
+ withSingleCallEnabled {
+ withTempDir { path =>
+ withCleanTmpResources(Seq((s"$db1.$table1", "table"),
(s"$db1.$table2", "table"))) {
+ interceptContains[AccessControlException](doAs(
+ someone,
+ sql(
+ s"""
+ |CREATE TABLE IF NOT EXISTS $db1.$table1(id int, scope int)
+ |LOCATION '$path'""".stripMargin)))(
+ s"does not have [create] privilege on [$db1/$table1]")
+ doAs(
+ admin,
+ sql(
+ s"""
+ |CREATE TABLE IF NOT EXISTS $db1.$table1(id int, scope int)
+ |LOCATION '$path'""".stripMargin))
+ interceptContains[AccessControlException](
+ doAs(
+ someone,
+ sql(
+ s"""
+ |CREATE TABLE $db1.$table2
+ |LIKE $db1.$table1
+ |LOCATION '$path'
+ |""".stripMargin)))(
+ s"does not have [select] privilege on [$db1/$table1], " +
+ s"[create] privilege on [$db1/$table2], " +
+ s"[write] privilege on [[$path, $path/]]")
+ if (!isSparkV35OrGreater) {
+ interceptContains[AccessControlException](
+ doAs(
+ someone,
+ sql(
+ s"""
+ |CREATE TABLE $db1.$table2
+ |LOCATION '$path'
+ |AS
+ |SELECT * FROM $db1.$table1
+ |""".stripMargin)))(
+ s"does not have [select] privilege on
[$db1/$table1/id,$db1/$table1/scope], " +
+ s"[create] privilege on [$db1/$table2/id,$db1/$table2/scope],
" +
+ s"[write] privilege on [[$path, $path/]]")
+ } else {
+ interceptContains[AccessControlException](
+ doAs(
+ someone,
+ sql(
+ s"""
+ |CREATE TABLE $db1.$table2
+ |LOCATION '$path'
+ |AS
+ |SELECT * FROM $db1.$table1
+ |""".stripMargin)))(
+ s"does not have [select] privilege on
[$db1/$table1/id,$db1/$table1/scope], " +
+ s"[create] privilege on [$db1/$table2/id,$db1/$table2/scope],
" +
+ s"[write] privilege on [[file://$path, file://$path/]]")
+ }
+ }
Review Comment:
```suggestion
interceptContains[AccessControlException](
doAs(
someone,
sql(
s"""
|CREATE TABLE $db1.$table2
|LOCATION '$path'
|AS
|SELECT * FROM $db1.$table1
|""".stripMargin))) {
if (isSparkV35OrGreater) {
s"does not have [select] privilege on
[$db1/$table1/id,$db1/$table1/scope], " +
s"[create] privilege on
[$db1/$table2/id,$db1/$table2/scope], " +
s"[write] privilege on [[file://$path, file://$path/]]"
} else {
s"does not have [select] privilege on
[$db1/$table1/id,$db1/$table1/scope], " +
s"[create] privilege on
[$db1/$table2/id,$db1/$table2/scope], " +
s"[write] privilege on [[$path, $path/]]"
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]