Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(adapter): password not set in role drop #10130

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions pgxn/neon/control_plane_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,37 +428,32 @@ MergeTable()
hash_seq_init(&status, old_table->role_table);
while ((entry = hash_seq_search(&status)) != NULL)
{
RoleEntry * old;
bool found_old = false;
RoleEntry *to_write = hash_search(
CurrentDdlTable->role_table,
entry->name,
HASH_ENTER,
NULL);

to_write->type = entry->type;
if (entry->password)
to_write->password = entry->password;
to_write->password = entry->password;
strlcpy(to_write->old_name, entry->old_name, NAMEDATALEN);
if (entry->old_name[0] != '\0')
{
bool found_old = false;
RoleEntry *old = hash_search(
CurrentDdlTable->role_table,
entry->old_name,
HASH_FIND,
&found_old);

if (found_old)
{
if (old->old_name[0] != '\0')
strlcpy(to_write->old_name, old->old_name, NAMEDATALEN);
else
strlcpy(to_write->old_name, entry->old_name, NAMEDATALEN);
hash_search(CurrentDdlTable->role_table,
entry->old_name,
HASH_REMOVE,
NULL);
}
}
if (entry->old_name[0] == '\0')
continue;
tristan957 marked this conversation as resolved.
Show resolved Hide resolved

old = hash_search(
CurrentDdlTable->role_table,
entry->old_name,
HASH_FIND,
&found_old);
if (!found_old)
continue;
strlcpy(to_write->old_name, old->old_name, NAMEDATALEN);
hash_search(CurrentDdlTable->role_table,
myrrc marked this conversation as resolved.
Show resolved Hide resolved
entry->old_name,
HASH_REMOVE,
NULL);
}
hash_destroy(old_table->role_table);
}
Expand Down
29 changes: 22 additions & 7 deletions test_runner/regress/test_ddl_forwarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ def ddl_forward_handler(
if request.json is None:
log.info("Received invalid JSON")
return Response(status=400)
json = request.json
json: dict[str, list[str]] = request.json
# Handle roles first
if "roles" in json:
for operation in json["roles"]:
handle_role(dbs, roles, operation)
if "dbs" in json:
for operation in json["dbs"]:
handle_db(dbs, roles, operation)
for operation in json.get("roles", []):
handle_role(dbs, roles, operation)
for operation in json.get("dbs", []):
handle_db(dbs, roles, operation)
return Response(status=200)


Expand Down Expand Up @@ -207,6 +205,23 @@ def test_ddl_forwarding(ddl: DdlForwardingContext):
ddl.wait()
assert ddl.roles == {}

cur.execute("CREATE ROLE bork WITH PASSWORD 'newyork'")
cur.execute("BEGIN")
cur.execute("SAVEPOINT point")
cur.execute("DROP ROLE bork")
cur.execute("COMMIT")
ddl.wait()
assert ddl.roles == {}

cur.execute("CREATE ROLE bork WITH PASSWORD 'oldyork'")
cur.execute("BEGIN")
cur.execute("SAVEPOINT point")
cur.execute("ALTER ROLE bork PASSWORD NULL")
cur.execute("COMMIT")
cur.execute("DROP ROLE bork")
ddl.wait()
assert ddl.roles == {}

cur.execute("CREATE ROLE bork WITH PASSWORD 'dork'")
cur.execute("CREATE DATABASE stork WITH OWNER=bork")
cur.execute("ALTER ROLE bork RENAME TO cork")
Expand Down
Loading