Skip to content

Commit 4d6202a

Browse files
authored
Merge pull request #2753 from dolthub/daylon/auth-fixes
Fixes CTE issue with auth
2 parents 0aac419 + 799705c commit 4d6202a

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

enginetest/enginetests.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,10 +1809,6 @@ func TestUserPrivileges(t *testing.T, harness ClientHarness) {
18091809
}
18101810
}
18111811

1812-
if assertion.Skip {
1813-
t.Skipf("Skipping query %s", assertion.Query)
1814-
}
1815-
18161812
user := assertion.User
18171813
host := assertion.Host
18181814
if user == "" {

enginetest/queries/priv_auth_queries.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ type UserPrivilegeTestAssertion struct {
4343
Expected []sql.Row
4444
ExpectedErr *errors.Kind
4545
ExpectedErrStr string
46-
Skip bool
4746
}
4847

4948
// QuickPrivilegeTest specifically tests privileges on a predefined user (tester@localhost) using predefined tables and
@@ -68,6 +67,7 @@ type UserPrivilegeTestAssertion struct {
6867
// match the non-nil empty row with it, due to the aforementioned distinction.
6968
//
7069
// Statements that are run before every test (the state that all tests start with):
70+
// CREATE USER tester@localhost;
7171
// CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY, v1 BIGINT);
7272
// CREATE TABLE mydb.test2 (pk BIGINT PRIMARY KEY, v1 BIGINT);
7373
// CREATE TABLE otherdb.test (pk BIGINT PRIMARY KEY, v1 BIGINT);
@@ -407,6 +407,7 @@ var UserPrivTests = []UserPrivilegeTest{
407407
Name: "Basic database and table name visibility",
408408
SetUpScript: []string{
409409
"CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY);",
410+
"CREATE TABLE mydb.invis (pk BIGINT PRIMARY KEY);",
410411
"INSERT INTO mydb.test VALUES (1);",
411412
"CREATE USER tester@localhost;",
412413
"CREATE ROLE test_role;",
@@ -516,12 +517,23 @@ var UserPrivTests = []UserPrivilegeTest{
516517
Expected: []sql.Row{{1}},
517518
},
518519
{
519-
Skip: true, // CTEs are seen as different tables than underlying table(s).
520520
User: "tester",
521521
Host: "localhost",
522522
Query: "WITH cte AS (SELECT * FROM mydb.test) SELECT * FROM cte;/*6*/",
523523
Expected: []sql.Row{{1}},
524524
},
525+
{
526+
User: "tester",
527+
Host: "localhost",
528+
Query: "WITH cte AS (SELECT * FROM mydb.test) SELECT * FROM cte JOIN mydb.invis t2 WHERE cte.pk = t2.pk;",
529+
ExpectedErr: sql.ErrTableAccessDeniedForUser,
530+
},
531+
{
532+
User: "tester",
533+
Host: "localhost",
534+
Query: "WITH cte AS (SELECT * FROM mydb.test) SELECT * FROM cte JOIN mydb.test t2 WHERE cte.pk = t2.pk;",
535+
Expected: []sql.Row{{1, 1}},
536+
},
525537
{
526538
User: "tester",
527539
Host: "localhost",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20241111235433-a20a5ab9d7c9
9+
github.com/dolthub/vitess v0.0.0-20241119005402-6a198321d993
1010
github.com/go-kit/kit v0.10.0
1111
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
1212
github.com/gocraft/dbr/v2 v2.7.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE
5858
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
5959
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
6060
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
61-
github.com/dolthub/vitess v0.0.0-20241111235433-a20a5ab9d7c9 h1:s36zDuLPuZRWC0nBCJs2Z8joP19eKEtcsIsuE8K9Kx0=
62-
github.com/dolthub/vitess v0.0.0-20241111235433-a20a5ab9d7c9/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
61+
github.com/dolthub/vitess v0.0.0-20241119005402-6a198321d993 h1:MhD6jHjshx2djyUq/uZxtCyHBYAnE3WshhJDUaO9fD8=
62+
github.com/dolthub/vitess v0.0.0-20241119005402-6a198321d993/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
6363
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
6464
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
6565
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=

sql/planbuilder/cte.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ func (b *Builder) buildWith(inScope *scope, with *ast.With) (outScope *scope) {
4242
outScope = inScope.push()
4343

4444
for _, cte := range with.Ctes {
45-
cte, ok := cte.(*ast.CommonTableExpr)
46-
if !ok {
47-
b.handleErr(sql.ErrUnsupportedFeature.New(fmt.Sprintf("Unsupported type of common table expression %T", cte)))
48-
}
49-
5045
ate := cte.AliasedTableExpr
5146
sq, ok := ate.Expr.(*ast.Subquery)
5247
if !ok {

0 commit comments

Comments
 (0)