From d572784a5f6e9001c86ad8affd0db2cb67ba77d5 Mon Sep 17 00:00:00 2001 From: Daylon Wilkins Date: Tue, 24 Nov 2026 13:55:53 -0800 Subject: [PATCH] Added branch control tests for statements that change no rows --- testing/go/auth_test.go | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/testing/go/auth_test.go b/testing/go/auth_test.go index 8d4b39a949..2de8b080bf 100644 --- a/testing/go/auth_test.go +++ b/testing/go/auth_test.go @@ -1779,6 +1779,70 @@ func TestAuthTests(t *testing.T) { }, }, }, + { + Name: "Branch Control: Statements that change no rows still require write permission", + SetUpScript: []string{ + `DELETE FROM dolt_branch_control WHERE "user" = '%';`, + "INSERT INTO dolt_branch_control VALUES ('%', '%', 'postgres', '%', 'admin');", + "INSERT INTO dolt_branch_control VALUES ('%', 'main', 'writer', '%', 'write');", + "CREATE USER contributor PASSWORD 'c';", + "CREATE USER writer PASSWORD 'w';", + "CREATE TABLE salary (id INT PRIMARY KEY, amount INT);", + "INSERT INTO salary VALUES (1, 12500);", + "GRANT ALL PRIVILEGES ON SCHEMA public TO contributor, writer;", + "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO contributor, writer;", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "UPDATE salary SET amount = amount WHERE id = 1;", + Username: "contributor", + Password: "c", + ExpectedErr: "does not have the correct permissions on branch `main`", + }, + { + Query: "UPDATE salary SET amount = 12500 WHERE id = 1;", + Username: "contributor", + Password: "c", + ExpectedErr: "does not have the correct permissions on branch `main`", + }, + { + Query: "UPDATE salary SET amount = 777 WHERE id = 1;", + Username: "contributor", + Password: "c", + ExpectedErr: "does not have the correct permissions on branch `main`", + }, + { + Query: "DELETE FROM salary WHERE 1 = 0;", + Username: "contributor", + Password: "c", + ExpectedErr: "does not have the correct permissions on branch `main`", + }, + { + Query: "INSERT INTO salary VALUES (1, 9000) ON CONFLICT (id) DO NOTHING;", + Username: "contributor", + Password: "c", + ExpectedErr: "does not have the correct permissions on branch `main`", + }, + { + Query: "UPDATE salary SET amount = amount WHERE id = 1;", + Username: "writer", + Password: "w", + Expected: []sql.Row{}, + }, + { + Query: "DELETE FROM salary WHERE 1 = 0;", + Username: "writer", + Password: "w", + Expected: []sql.Row{}, + }, + { + Query: "SELECT * FROM salary;", + Username: "contributor", + Password: "c", + Expected: []sql.Row{{1, 12500}}, + }, + }, + }, }) }