Skip to content

Commit

Permalink
Chnage obj name to _bbfobj
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharu Goel committed Jan 6, 2025
1 parent c2439fa commit d95f03f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/src/pl_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3857,7 +3857,7 @@ bbf_ProcessUtility(PlannedStmt *pstmt,
{
const char* new_owner = get_obj_role(get_rolespec_name(rolspec));

/* We will not change the owner in the unlikely event that the "_obj" role does not exist */
/* We will not change the owner in the unlikely event that the "_bbfobj" role does not exist */
if (get_role_oid(new_owner, true) != InvalidOid)
{
create_schema->authrole = make_rolespec_node(new_owner);
Expand Down
8 changes: 4 additions & 4 deletions contrib/babelfishpg_tsql/src/rolecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -2821,7 +2821,7 @@ get_obj_role(const char *rolname)
initStringInfo(&rolname_obj);

appendStringInfoString(&rolname_obj, rolname);
appendStringInfoString(&rolname_obj, "_obj");
appendStringInfoString(&rolname_obj, "_bbfobj");

truncate_tsql_identifier(rolname_obj.data);

Expand Down Expand Up @@ -3149,7 +3149,7 @@ change_object_owner_if_db_owner()
/*
* Instead of failing the ownership reassignment in the
* unlikely event that a user that is member of db_owner
* role does not have corresponding "_obj" role, we will
* role does not have corresponding "_bbfobj" role, we will
* silently skip the ownership reassignment
*/
}
Expand Down Expand Up @@ -3201,7 +3201,7 @@ PG_FUNCTION_INFO_V1(bbf_is_role_member);
/*
* The bbf_is_role_memeber function will check if a user (u1) is member of a role (r1):
* - If role is not a member of db_owner, we will check if u1 is member of r1 role
* - If role is a member of db_owner, we will check if u1 is member of r1_obj role
* - If role is a member of db_owner, we will check if u1 is member of r1_bbfobj role
*/
Datum
bbf_is_role_member(PG_FUNCTION_ARGS)
Expand Down Expand Up @@ -3237,7 +3237,7 @@ bbf_is_role_member(PG_FUNCTION_ARGS)
/*
* This helper function will first check if user is member of
* db_owner role. If it is, then we will attempt drop the linked
* "_obj" role. If it is not, this function will do nothing.
* "_bbfobj" role. If it is not, this function will do nothing.
*/
static void
drop_db_owner_related_roles(Oid roleid, const char* rolname)
Expand Down
98 changes: 49 additions & 49 deletions test/JDBC/expected/db_owner-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SELECT r.rolname AS parent_role
FROM pg_auth_members m
JOIN pg_roles r ON (m.roleid = r.oid)
JOIN pg_roles mr ON (m.member = mr.oid)
WHERE mr.rolname = 'dbowner__main_db_dbowner__u1_obj'
WHERE mr.rolname = 'dbowner__main_db_dbowner__u1_bbfobj'
ORDER BY r.rolname;
go
~~START~~
Expand All @@ -23,7 +23,7 @@ go
name
dbowner__main_db_db_owner
dbowner__main_db_dbo
dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__u1_bbfobj
~~END~~


Expand All @@ -43,7 +43,7 @@ dbowner__main_db_db_ddladmin
dbowner__main_db_db_securityadmin
dbowner__main_db_dbowner__r1
dbowner__main_db_dbowner__r2
dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__u2
dbowner__main_db_guest
~~END~~
Expand Down Expand Up @@ -71,21 +71,21 @@ alter login dbowner__temp with password = '123'
go

-- Testing for name clash
create login dbowner__main_db_dbowner__u1_obj with password = '123'
create login dbowner__main_db_dbowner__u1_bbfobj with password = '123'
go
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Cannot create database principal "dbowner__main_db_dbowner__u1_obj" as there already exists a Babelfish internal role with the same name)~~
~~ERROR (Message: Cannot create database principal "dbowner__main_db_dbowner__u1_bbfobj" as there already exists a Babelfish internal role with the same name)~~

use dbowner__main_db
go
create login dbowner__nameclash with password = '123'
go
create user dbowner__u1_obj for login dbowner__nameclash
create user dbowner__u1_bbfobj for login dbowner__nameclash
go
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Cannot create database principal "dbowner__main_db_dbowner__u1_obj" as there already exists a Babelfish internal role with the same name)~~
~~ERROR (Message: Cannot create database principal "dbowner__main_db_dbowner__u1_bbfobj" as there already exists a Babelfish internal role with the same name)~~

drop login dbowner__nameclash
go
Expand Down Expand Up @@ -445,7 +445,7 @@ exec sp_rename 'dbowner__s3.dbowner__seq3', 'dbowner__seq3_renamed', 'object'
go

-- psql
-- Procedure/function owners should be dbowner__main_db_dbowner__u1_obj
-- Procedure/function owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT proname,
proowner::regrole
FROM pg_proc
Expand All @@ -455,15 +455,15 @@ ORDER BY proname;
GO
~~START~~
name#!#regrole
dbowner__f1_renamed#!#dbowner__main_db_dbowner__u1_obj
dbowner__f3_renamed#!#dbowner__main_db_dbowner__u1_obj
dbowner__p1_renamed#!#dbowner__main_db_dbowner__u1_obj
dbowner__p3_renamed#!#dbowner__main_db_dbowner__u1_obj
dbowner__trg1_renamed#!#dbowner__main_db_dbowner__u1_obj
dbowner__f1_renamed#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__f3_renamed#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__p1_renamed#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__p3_renamed#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__trg1_renamed#!#dbowner__main_db_dbowner__u1_bbfobj
~~END~~


-- Table owners should be dbowner__main_db_dbowner__u1_obj
-- Table owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT
n.nspname AS schema,
c.relname AS table,
Expand All @@ -485,14 +485,14 @@ ORDER BY n.nspname, c.relkind, c.relname;
GO
~~START~~
name#!#name#!#text#!#name
dbowner__main_db_dbowner__s1#!#dbowner__seq1_renamed#!#sequence#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__idx1dbowner__t1051d92a6c0688536803636483cfc1e78#!#index#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__t11#!#table#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__t1_renamed#!#table#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__v1_renamed#!#view#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s3#!#dbowner__seq3_renamed#!#sequence#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s3#!#dbowner__t3_renamed#!#table#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s3#!#dbowner__v3_renamed#!#view#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__seq1_renamed#!#sequence#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s1#!#dbowner__idx1dbowner__t1051d92a6c0688536803636483cfc1e78#!#index#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s1#!#dbowner__t11#!#table#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s1#!#dbowner__t1_renamed#!#table#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s1#!#dbowner__v1_renamed#!#view#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s3#!#dbowner__seq3_renamed#!#sequence#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s3#!#dbowner__t3_renamed#!#table#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s3#!#dbowner__v3_renamed#!#view#!#dbowner__main_db_dbowner__u1_bbfobj
~~END~~


Expand Down Expand Up @@ -836,15 +836,15 @@ exec sp_droprolemember 'db_owner', 'dbowner__u1' -- dropping again should not th
go

-- Check name clash scenario
create role dbowner__u1_obj
create role dbowner__u1_bbfobj
go
exec sp_addrolemember 'db_owner', 'dbowner__u1'
go
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Internal role "dbowner__main_db_dbowner__u1_obj" could not be created because a role already exists with the same name)~~
~~ERROR (Message: Internal role "dbowner__main_db_dbowner__u1_bbfobj" could not be created because a role already exists with the same name)~~

drop role dbowner__u1_obj
drop role dbowner__u1_bbfobj
go

exec sp_addrolemember 'db_owner', 'dbowner__u1' -- adding again should not throw error
Expand Down Expand Up @@ -1065,7 +1065,7 @@ sys


-- psql
-- Procedure/function owners should be dbowner__main_db_dbowner__u1_obj
-- Procedure/function owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT proname,
proowner::regrole
FROM pg_proc
Expand All @@ -1075,15 +1075,15 @@ ORDER BY proname;
GO
~~START~~
name#!#regrole
dbowner__f1#!#dbowner__main_db_dbowner__u1_obj
dbowner__f3#!#dbowner__main_db_dbowner__u1_obj
dbowner__p1#!#dbowner__main_db_dbowner__u1_obj
dbowner__p3#!#dbowner__main_db_dbowner__u1_obj
dbowner__trg1#!#dbowner__main_db_dbowner__u1_obj
dbowner__f1#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__f3#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__p1#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__p3#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__trg1#!#dbowner__main_db_dbowner__u1_bbfobj
~~END~~


-- Table owners should be dbowner__main_db_dbowner__u1_obj
-- Table owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT
n.nspname AS schema,
c.relname AS table,
Expand All @@ -1105,18 +1105,18 @@ ORDER BY n.nspname, c.relkind, c.relname;
GO
~~START~~
name#!#name#!#text#!#name
dbowner__main_db_dbowner__s1#!#dbowner__seq1#!#sequence#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__idx1dbowner__t1051d92a6c0688536803636483cfc1e78#!#index#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__t1#!#table#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__t11#!#table#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__v1#!#view#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s3#!#dbowner__seq3#!#sequence#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s3#!#dbowner__t3#!#table#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s3#!#dbowner__v3#!#view#!#dbowner__main_db_dbowner__u1_obj
dbowner__main_db_dbowner__s1#!#dbowner__seq1#!#sequence#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s1#!#dbowner__idx1dbowner__t1051d92a6c0688536803636483cfc1e78#!#index#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s1#!#dbowner__t1#!#table#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s1#!#dbowner__t11#!#table#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s1#!#dbowner__v1#!#view#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s3#!#dbowner__seq3#!#sequence#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s3#!#dbowner__t3#!#table#!#dbowner__main_db_dbowner__u1_bbfobj
dbowner__main_db_dbowner__s3#!#dbowner__v3#!#view#!#dbowner__main_db_dbowner__u1_bbfobj
~~END~~


-- Schemas owner should be dbowner__main_db_dbowner__u1_obj except for dbowner__main_db_dbowner__sch_u2 and dbowner__main_db_dbowner__sch_db_owner
-- Schemas owner should be dbowner__main_db_dbowner__u1_bbfobj except for dbowner__main_db_dbowner__sch_u2 and dbowner__main_db_dbowner__sch_db_owner
SELECT
r.rolname AS schema_owner,
ns.nspname
Expand All @@ -1132,8 +1132,8 @@ ORDER BY ns.nspname;
GO
~~START~~
name#!#name
dbowner__main_db_dbowner__u1_obj#!#dbowner__main_db_dbowner__s1
dbowner__main_db_dbowner__u1_obj#!#dbowner__main_db_dbowner__s3
dbowner__main_db_dbowner__u1_bbfobj#!#dbowner__main_db_dbowner__s1
dbowner__main_db_dbowner__u1_bbfobj#!#dbowner__main_db_dbowner__s3
dbowner__main_db_db_owner#!#dbowner__main_db_dbowner__sch_db_owner
dbowner__main_db_dbowner__u2#!#dbowner__main_db_dbowner__sch_u2
~~END~~
Expand Down Expand Up @@ -1294,7 +1294,7 @@ int
create schema dbowner__sch_u1 authorization dbowner__u1
go

-- Schema owners should be dbowner__main_db_dbowner__u1_obj
-- Schema owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT
r.rolname AS schema_owner,
ns.nspname
Expand All @@ -1310,7 +1310,7 @@ ORDER BY ns.nspname;
GO
~~START~~
varchar#!#varchar
dbowner__main_db_dbowner__u1_obj#!#dbowner__main_db_dbowner__sch_u1
dbowner__main_db_dbowner__u1_bbfobj#!#dbowner__main_db_dbowner__sch_u1
~~END~~


Expand Down Expand Up @@ -1342,7 +1342,7 @@ go

-- psql
-- Before anything, let's check if internal role linking/delinking got reverted as expected
SELECT rolname FROM pg_roles WHERE rolname = 'dbowner__main_db_dbowner__u1_obj'; -- "_obj" role should not exist
SELECT rolname FROM pg_roles WHERE rolname = 'dbowner__main_db_dbowner__u1_bbfobj'; -- "_bbfobj" role should not exist
go
~~START~~
name
Expand Down Expand Up @@ -1939,7 +1939,7 @@ void


-- psql
-- Check if dropping user, also drops the linked "_obj" role
-- Check if dropping user, also drops the linked "_bbfobj" role
select rolname from pg_authid where rolname like 'dbowner__test_db_%' order by rolname;
go
~~START~~
Expand All @@ -1952,9 +1952,9 @@ dbowner__test_db_db_owner
dbowner__test_db_db_securityadmin
dbowner__test_db_dbo
dbowner__test_db_dbowner__test_db_dbowner__u1
dbowner__test_db_dbowner__test_db_dbowner__u1_obj
dbowner__test_db_dbowner__test_db_dbowner__u1_bbfobj
dbowner__test_db_dbowner__test_db_dbowner__u2
dbowner__test_db_dbowner__test_db_dbowner__u2_obj
dbowner__test_db_dbowner__test_db_dbowner__u2_bbfobj
dbowner__test_db_guest
~~END~~

Expand Down
26 changes: 13 additions & 13 deletions test/JDBC/input/db_owner-vu-verify.mix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SELECT r.rolname AS parent_role
FROM pg_auth_members m
JOIN pg_roles r ON (m.roleid = r.oid)
JOIN pg_roles mr ON (m.member = mr.oid)
WHERE mr.rolname = 'dbowner__main_db_dbowner__u1_obj'
WHERE mr.rolname = 'dbowner__main_db_dbowner__u1_bbfobj'
ORDER BY r.rolname;
go

Expand Down Expand Up @@ -41,13 +41,13 @@ alter login dbowner__temp with password = '123'
go

-- Testing for name clash
create login dbowner__main_db_dbowner__u1_obj with password = '123'
create login dbowner__main_db_dbowner__u1_bbfobj with password = '123'
go
use dbowner__main_db
go
create login dbowner__nameclash with password = '123'
go
create user dbowner__u1_obj for login dbowner__nameclash
create user dbowner__u1_bbfobj for login dbowner__nameclash
go
drop login dbowner__nameclash
go
Expand Down Expand Up @@ -252,7 +252,7 @@ exec sp_rename 'dbowner__s3.dbowner__seq3', 'dbowner__seq3_renamed', 'object'
go

-- psql
-- Procedure/function owners should be dbowner__main_db_dbowner__u1_obj
-- Procedure/function owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT proname,
proowner::regrole
FROM pg_proc
Expand All @@ -261,7 +261,7 @@ OR pronamespace::regnamespace::text = 'dbowner__main_db_dbowner__s3'
ORDER BY proname;
GO

-- Table owners should be dbowner__main_db_dbowner__u1_obj
-- Table owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT
n.nspname AS schema,
c.relname AS table,
Expand Down Expand Up @@ -518,11 +518,11 @@ exec sp_droprolemember 'db_owner', 'dbowner__u1' -- dropping again should not th
go

-- Check name clash scenario
create role dbowner__u1_obj
create role dbowner__u1_bbfobj
go
exec sp_addrolemember 'db_owner', 'dbowner__u1'
go
drop role dbowner__u1_obj
drop role dbowner__u1_bbfobj
go

exec sp_addrolemember 'db_owner', 'dbowner__u1' -- adding again should not throw error
Expand Down Expand Up @@ -596,7 +596,7 @@ select name from sys.database_principals order by name
go

-- psql
-- Procedure/function owners should be dbowner__main_db_dbowner__u1_obj
-- Procedure/function owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT proname,
proowner::regrole
FROM pg_proc
Expand All @@ -605,7 +605,7 @@ OR pronamespace::regnamespace::text = 'dbowner__main_db_dbowner__s3'
ORDER BY proname;
GO

-- Table owners should be dbowner__main_db_dbowner__u1_obj
-- Table owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT
n.nspname AS schema,
c.relname AS table,
Expand All @@ -626,7 +626,7 @@ AND c.relkind IN ('r', 'v', 'm', 'i', 'S', 's', 'f')
ORDER BY n.nspname, c.relkind, c.relname;
GO

-- Schemas owner should be dbowner__main_db_dbowner__u1_obj except for dbowner__main_db_dbowner__sch_u2 and dbowner__main_db_dbowner__sch_db_owner
-- Schemas owner should be dbowner__main_db_dbowner__u1_bbfobj except for dbowner__main_db_dbowner__sch_u2 and dbowner__main_db_dbowner__sch_db_owner
SELECT
r.rolname AS schema_owner,
ns.nspname
Expand Down Expand Up @@ -687,7 +687,7 @@ go
create schema dbowner__sch_u1 authorization dbowner__u1
go

-- Schema owners should be dbowner__main_db_dbowner__u1_obj
-- Schema owners should be dbowner__main_db_dbowner__u1_bbfobj
SELECT
r.rolname AS schema_owner,
ns.nspname
Expand All @@ -711,7 +711,7 @@ go

-- psql
-- Before anything, let's check if internal role linking/delinking got reverted as expected
SELECT rolname FROM pg_roles WHERE rolname = 'dbowner__main_db_dbowner__u1_obj'; -- "_obj" role should not exist
SELECT rolname FROM pg_roles WHERE rolname = 'dbowner__main_db_dbowner__u1_bbfobj'; -- "_bbfobj" role should not exist
go

SELECT r.rolname AS parent_role
Expand Down Expand Up @@ -1056,7 +1056,7 @@ SELECT pg_sleep(1);
GO


-- Check if dropping user, also drops the linked "_obj" role
-- Check if dropping user, also drops the linked "_bbfobj" role
-- psql
select rolname from pg_authid where rolname like 'dbowner__test_db_%' order by rolname;
go
Expand Down

0 comments on commit d95f03f

Please sign in to comment.