Skip to content

Commit

Permalink
Fix is_srvrolemember output for login same as specified server role
Browse files Browse the repository at this point in the history
Earlier is_srvrolemember was returning 1 for login same as specified server role.

With this commit, now it will return expected output.

Signed-off-by: ANJU BHARTI <[email protected]>
  • Loading branch information
ANJU BHARTI committed Dec 20, 2024
1 parent d2a2789 commit ca727c8
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions contrib/babelfishpg_tsql/sql/babelfishpg_tsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,9 @@ BEGIN

ELSIF role = 'public' COLLATE sys.database_default THEN
RETURN 1;

ELSEIF role = login THEN
RETURN 0;

ELSIF role COLLATE sys.database_default IN ('sysadmin', 'securityadmin', 'dbcreator') THEN
has_role = (pg_has_role(login::TEXT, role::TEXT, 'MEMBER')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,9 @@ BEGIN

ELSIF role = 'public' COLLATE sys.database_default THEN
RETURN 1;

ELSEIF role = login THEN
RETURN 0;

ELSIF role COLLATE sys.database_default IN ('sysadmin', 'securityadmin', 'dbcreator') THEN
has_role = (pg_has_role(login::TEXT, role::TEXT, 'MEMBER')
Expand Down
25 changes: 25 additions & 0 deletions test/JDBC/expected/dbcreator_role-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ int
~~END~~


select is_srvrolemember('dbcreator','dbcreator')
go
~~START~~
int
0
~~END~~


select is_srvrolemember('sysadmin','sysadmin')
go
~~START~~
int
0
~~END~~


-- should return NULL for invalid login
select is_srvrolemember('l1', 'l1')
go
~~START~~
int
<NULL>
~~END~~


alter login dbcreator_login1 with password='123'
go

Expand Down
8 changes: 8 additions & 0 deletions test/JDBC/expected/securityadmin_role-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ int
~~END~~


select is_srvrolemember('securityadmin','securityadmin')
go
~~START~~
int
0
~~END~~


alter login securityadmin_login1 with password='123'
go

Expand Down
25 changes: 25 additions & 0 deletions test/JDBC/expected/single_db/dbcreator_role-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ int
~~END~~


select is_srvrolemember('dbcreator','dbcreator')
go
~~START~~
int
0
~~END~~


select is_srvrolemember('sysadmin','sysadmin')
go
~~START~~
int
0
~~END~~


-- should return NULL for invalid login
select is_srvrolemember('l1', 'l1')
go
~~START~~
int
<NULL>
~~END~~


alter login dbcreator_login1 with password='123'
go

Expand Down
10 changes: 10 additions & 0 deletions test/JDBC/input/dbcreator_role-vu-verify.mix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ go
select is_srvrolemember('dbcreator', 'securityadmin')
go

select is_srvrolemember('dbcreator','dbcreator')
go

select is_srvrolemember('sysadmin','sysadmin')
go

-- should return NULL for invalid login
select is_srvrolemember('l1', 'l1')
go

alter login dbcreator_login1 with password='123'
go

Expand Down
3 changes: 3 additions & 0 deletions test/JDBC/input/securityadmin_role-vu-verify.mix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ go
select is_srvrolemember('securityadmin', 'sysadmin')
go

select is_srvrolemember('securityadmin','securityadmin')
go

alter login securityadmin_login1 with password='123'
go

Expand Down

0 comments on commit ca727c8

Please sign in to comment.