Skip to content

Commit

Permalink
Added tests for BABEL-5119
Browse files Browse the repository at this point in the history
Signed-off-by: P Aswini Kumar <[email protected]>
  • Loading branch information
P Aswini Kumar committed Sep 4, 2024
1 parent cf4ed3d commit 6a92b33
Show file tree
Hide file tree
Showing 2 changed files with 350 additions and 0 deletions.
218 changes: 218 additions & 0 deletions test/JDBC/expected/BABEL-5119.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
-- tsql
CREATE DATABASE BABEL5119_1
GO

USE BABEL5119_1
GO
CREATE TABLE t1(a int)
INSERT INTO t1 VALUES(1)
GO
~~ROW COUNT: 1~~

CREATE VIEW v1 AS SELECT 1
GO
CREATE PROCEDURE p1 AS SELECT 1
GO

CREATE LOGIN login_babel5119_1 WITH PASSWORD = '12345678'
CREATE LOGIN login_babel5119_2 WITH PASSWORD = '12345678'
ALTER authorization on database::BABEL5119_1 TO login_babel5119_1
GO
-- terminate-tsql-conn

-- tsql user=login_babel5119_1 password=12345678
-- Checking crossdb for sys views
USE BABEL5119_1
GO

SELECT name FROM BABEL5119_1.sys.databases
UNION
SELECT name FROM master.sys.databases
GO
~~START~~
varchar
msdb
tempdb
master
babel5119_1
~~END~~


SELECT name FROM BABEL5119_1.sys.views
UNION
SELECT name FROM master.sys.views
GO
~~START~~
varchar
~~END~~


SELECT name FROM BABEL5119_1.sys.procedures
UNION
SELECT name FROM master.sys.procedures
GO
~~START~~
varchar
sp_dropserver
sp_testlinkedserver
sp_addlinkedserver
sp_addlinkedsrvlogin
xp_instance_regread
xp_qv
sp_enum_oledb_providers
sp_droplinkedsrvlogin
~~END~~


-- Checking crossdb for information_schema_tsql
SELECT * FROM BABEL5119_1.information_schema_tsql.tables
UNION
SELECT * FROM master.information_schema_tsql.tables
GO
~~START~~
nvarchar#!#nvarchar#!#varchar#!#varchar
babel5119_1#!#dbo#!#v1#!#VIEW
babel5119_1#!#dbo#!#t1#!#BASE TABLE
~~END~~


SELECT TABLE_NAME, COLUMN_NAME FROM BABEL5119_1.information_schema_tsql.columns
UNION
SELECT TABLE_NAME, COLUMN_NAME FROM master.information_schema_tsql.columns
GO
~~START~~
nvarchar#!#nvarchar
sysdatabases#!#cmptlevel
sysdatabases#!#version
sysdatabases#!#category
sysdatabases#!#status2
t1#!#a
sysdatabases#!#mode
sysdatabases#!#filename
sysdatabases#!#name
sysdatabases#!#status
sysdatabases#!#reserved
v1#!#?column?
sysdatabases#!#crdate
sysdatabases#!#dbid
sysdatabases#!#sid
~~END~~


SELECT TABLE_NAME, VIEW_DEFINITION FROM BABEL5119_1.information_schema_tsql.views
UNION
SELECT TABLE_NAME, VIEW_DEFINITION FROM master.information_schema_tsql.views
GO
~~START~~
nvarchar#!#nvarchar
v1#!#CREATE VIEW v1 AS SELECT 1
~~END~~


-- General crossdb queries
USE master
GO
CREATE TABLE t2(a int)
INSERT INTO t2 VALUES(1)
GO
~~ROW COUNT: 1~~

CREATE VIEW v2 AS SELECT 1
GO
CREATE PROCEDURE p2 AS SELECT 1
GO

USE BABEL5119_1
GO

SELECT tb_1.*, tb_2.* FROM BABEL5119_1.dbo.t1 tb_1, master.guest.t2 tb_2
GO
~~START~~
int#!#int
1#!#1
~~END~~


SELECT vw_1.*, vw_2.* FROM BABEL5119_1.dbo.v1 vw_1, master.guest.v2 vw_2
GO
~~START~~
int#!#int
1#!#1
~~END~~


-- Using crossdb query data
CREATE TABLE #tmp_db_ars(replica_id uniqueidentifier, group_id uniqueidentifier, replica_server_name sysname)
INSERT INTO #tmp_db_ars select replica_id, group_id, replica_server_name from master.sys.availability_replicas
GO

CREATE TABLE #tmp_db_ars2(v VARCHAR(MAX))
INSERT INTO #tmp_db_ars2 SELECT name FROM BABEL5119_1.sys.databases UNION SELECT name FROM master.sys.databases
GO
~~ROW COUNT: 4~~


CREATE TABLE #tmp_db_ars3(v VARCHAR(MAX))
INSERT INTO #tmp_db_ars3 SELECT TABLE_NAME FROM BABEL5119_1.information_schema_tsql.tables UNION SELECT TABLE_NAME FROM master.information_schema_tsql.tables
GO
~~ROW COUNT: 2~~


SELECT CAST(has_dbaccess(dtb.name) AS bit) AS [IsAccessible] FROM master.sys.databases AS dtb WHERE (dtb.name='BABEL5119_1')
GO
~~START~~
bit
1
~~END~~


-- terminate-tsql-conn user=login_babel5119_1 password=12345678

-- tsql user=login_babel5119_2 password=12345678
-- Checking the permissions after alter
USE BABEL5119_1
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_1" under the current security context)~~

-- terminate-tsql-conn user=login_babel5119_2 password=12345678

-- tsql
ALTER authorization on database::BABEL5119_1 TO login_babel5119_2
GO
-- terminate-tsql-conn

-- tsql user=login_babel5119_1 password=12345678
USE BABEL5119_1
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: The server principal "login_babel5119_1" is not able to access the database "babel5119_1" under the current security context)~~

-- terminate-tsql-conn user=login_babel5119_1 password=12345678

-- tsql user=login_babel5119_2 password=12345678
USE BABEL5119_1
GO
INSERT INTO t1 VALUES(1)
GO
~~ROW COUNT: 1~~

-- terminate-tsql-conn user=login_babel5119_2 password=12345678

-- tsql
USE master
GO
DROP TABLE guest.t2
GO
DROP VIEW guest.v2
GO
DROP PROCEDURE guest.p2
GO
DROP LOGIN login_babel5119_1
GO
DROP LOGIN login_babel5119_2
GO
DROP DATABASE BABEL5119_1
GO
132 changes: 132 additions & 0 deletions test/JDBC/input/BABEL-5119.mix
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
-- tsql
CREATE DATABASE BABEL5119_1
GO

USE BABEL5119_1
GO
CREATE TABLE t1(a int)
INSERT INTO t1 VALUES(1)
GO
CREATE VIEW v1 AS SELECT 1
GO
CREATE PROCEDURE p1 AS SELECT 1
GO

CREATE LOGIN login_babel5119_1 WITH PASSWORD = '12345678'
CREATE LOGIN login_babel5119_2 WITH PASSWORD = '12345678'
ALTER authorization on database::BABEL5119_1 TO login_babel5119_1
GO
-- terminate-tsql-conn

-- tsql user=login_babel5119_1 password=12345678
-- Checking crossdb for sys views
USE BABEL5119_1
GO

SELECT name FROM BABEL5119_1.sys.databases
UNION
SELECT name FROM master.sys.databases
GO

SELECT name FROM BABEL5119_1.sys.views
UNION
SELECT name FROM master.sys.views
GO

SELECT name FROM BABEL5119_1.sys.procedures
UNION
SELECT name FROM master.sys.procedures
GO

-- Checking crossdb for information_schema_tsql
SELECT * FROM BABEL5119_1.information_schema_tsql.tables
UNION
SELECT * FROM master.information_schema_tsql.tables
GO

SELECT TABLE_NAME, COLUMN_NAME FROM BABEL5119_1.information_schema_tsql.columns
UNION
SELECT TABLE_NAME, COLUMN_NAME FROM master.information_schema_tsql.columns
GO

SELECT TABLE_NAME, VIEW_DEFINITION FROM BABEL5119_1.information_schema_tsql.views
UNION
SELECT TABLE_NAME, VIEW_DEFINITION FROM master.information_schema_tsql.views
GO

-- General crossdb queries
USE master
GO
CREATE TABLE t2(a int)
INSERT INTO t2 VALUES(1)
GO
CREATE VIEW v2 AS SELECT 1
GO
CREATE PROCEDURE p2 AS SELECT 1
GO

USE BABEL5119_1
GO

SELECT tb_1.*, tb_2.* FROM BABEL5119_1.dbo.t1 tb_1, master.guest.t2 tb_2
GO

SELECT vw_1.*, vw_2.* FROM BABEL5119_1.dbo.v1 vw_1, master.guest.v2 vw_2
GO

-- Using crossdb query data
CREATE TABLE #tmp_db_ars(replica_id uniqueidentifier, group_id uniqueidentifier, replica_server_name sysname)
INSERT INTO #tmp_db_ars select replica_id, group_id, replica_server_name from master.sys.availability_replicas
GO

CREATE TABLE #tmp_db_ars2(v VARCHAR(MAX))
INSERT INTO #tmp_db_ars2 SELECT name FROM BABEL5119_1.sys.databases UNION SELECT name FROM master.sys.databases
GO

CREATE TABLE #tmp_db_ars3(v VARCHAR(MAX))
INSERT INTO #tmp_db_ars3 SELECT TABLE_NAME FROM BABEL5119_1.information_schema_tsql.tables UNION SELECT TABLE_NAME FROM master.information_schema_tsql.tables
GO

SELECT CAST(has_dbaccess(dtb.name) AS bit) AS [IsAccessible] FROM master.sys.databases AS dtb WHERE (dtb.name='BABEL5119_1')
GO

-- terminate-tsql-conn user=login_babel5119_1 password=12345678

-- Checking the permissions after alter
-- tsql user=login_babel5119_2 password=12345678
USE BABEL5119_1
GO
-- terminate-tsql-conn user=login_babel5119_2 password=12345678

-- tsql
ALTER authorization on database::BABEL5119_1 TO login_babel5119_2
GO
-- terminate-tsql-conn

-- tsql user=login_babel5119_1 password=12345678
USE BABEL5119_1
GO
-- terminate-tsql-conn user=login_babel5119_1 password=12345678

-- tsql user=login_babel5119_2 password=12345678
USE BABEL5119_1
GO
INSERT INTO t1 VALUES(1)
GO
-- terminate-tsql-conn user=login_babel5119_2 password=12345678

-- tsql
USE master
GO
DROP TABLE guest.t2
GO
DROP VIEW guest.v2
GO
DROP PROCEDURE guest.p2
GO
DROP LOGIN login_babel5119_1
GO
DROP LOGIN login_babel5119_2
GO
DROP DATABASE BABEL5119_1
GO

0 comments on commit 6a92b33

Please sign in to comment.