Skip to content

Commit

Permalink
[regression-test](fix) fix case with invalid grammer (#45211) (#45791)
Browse files Browse the repository at this point in the history
Problem Summary:
Defining global variables in a test suite can easily introduce errors,
such as variable conflicts in concurrent scenarios. In #44576 , a method
for detecting global variables was introduced.

That approach conflicts with the function calling like
connect(user=user, password="pwd"). Furthermore, the connect(user=user,
password="pwd") method cannot specify assignments to parameters with
default values; values still need to be assigned according to the order
of parameters. Therefore, modifying these calling method.
  • Loading branch information
shuke987 authored Dec 24, 2024
1 parent aa728ae commit 1c47f5c
Show file tree
Hide file tree
Showing 113 changed files with 274 additions and 274 deletions.
46 changes: 23 additions & 23 deletions regression-test/suites/account_p0/test_alter_user.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ suite("test_alter_user", "account,nonConcurrent") {
sql """alter user test_auth_user2 password_history 0"""
sql """set password for 'test_auth_user2' = password('12345')"""

def result1 = connect(user = 'test_auth_user2', password = '12345', url = context.config.jdbcUrl) {
def result1 = connect('test_auth_user2', '12345', context.config.jdbcUrl) {
sql 'select 1'
}

Expand All @@ -48,7 +48,7 @@ suite("test_alter_user", "account,nonConcurrent") {
sql """alter user test_auth_user2 identified by 'abc12345'"""
exception "Cannot use these credentials for 'test_auth_user2'@'%' because they contradict the password history policy"
}
result1 = connect(user = 'test_auth_user2', password = 'abc123456', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user2', 'abc123456', context.config.jdbcUrl) {
sql 'select 1'
}
sql """set global password_history=0""" // set to disabled
Expand All @@ -58,67 +58,67 @@ suite("test_alter_user", "account,nonConcurrent") {
sql """grant all on *.* to test_auth_user3"""

// login success in multi times
result1 = connect(user = 'test_auth_user3', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user3', '12345', context.config.jdbcUrl) {
sql 'select 1'
}
result1 = connect(user = 'test_auth_user3', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user3', '12345', context.config.jdbcUrl) {
sql 'select 1'
}
result1 = connect(user = 'test_auth_user3', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user3', '12345', context.config.jdbcUrl) {
sql 'select 1'
}
// login failed in 2 times
try {
connect(user = 'test_auth_user3', password = 'wrong', url = context.config.jdbcUrl) {}
connect('test_auth_user3', 'wrong',context.config.jdbcUrl) {}
assertTrue(false. "should not be able to login")
} catch (Exception e) {
assertTrue(e.getMessage().contains("Access denied for user 'test_auth_user3"), e.getMessage())
}
try {
connect(user = 'test_auth_user3', password = 'wrong', url = context.config.jdbcUrl) {}
connect('test_auth_user3', 'wrong', context.config.jdbcUrl) {}
assertTrue(false. "should not be able to login")
} catch (Exception e) {
assertTrue(e.getMessage().contains("Access denied for user 'test_auth_user3"), e.getMessage())
}
// login with correct password but also failed
try {
connect(user = 'test_auth_user3', password = '12345', url = context.config.jdbcUrl) {}
connect('test_auth_user3', '12345', context.config.jdbcUrl) {}
assertTrue(false. "should not be able to login")
} catch (Exception e) {
assertTrue(e.getMessage().contains("Access denied for user 'test_auth_user3'@'%'. Account is blocked for 86400 second(s) (86400 second(s) remaining) due to 2 consecutive failed logins."), e.getMessage())
}

// unlock user and login again
sql """alter user test_auth_user3 account_unlock"""
result1 = connect(user = 'test_auth_user3', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user3', '12345', context.config.jdbcUrl) {
sql 'select 1'
}

// alter PASSWORD_LOCK_TIME
sql """alter user test_auth_user3 PASSWORD_LOCK_TIME 5 SECOND"""
// login failed in 2 times to lock the accout again
try {
connect(user = 'test_auth_user3', password = 'wrong', url = context.config.jdbcUrl) {}
connect('test_auth_user3', 'wrong', context.config.jdbcUrl) {}
assertTrue(false. "should not be able to login")
} catch (Exception e) {
assertTrue(e.getMessage().contains("Access denied for user 'test_auth_user3"), e.getMessage())
}
try {
connect(user = 'test_auth_user3', password = 'wrong', url = context.config.jdbcUrl) {}
connect('test_auth_user3', 'wrong', context.config.jdbcUrl) {}
assertTrue(false. "should not be able to login")
} catch (Exception e) {
assertTrue(e.getMessage().contains("Access denied for user 'test_auth_user3"), e.getMessage())
}
// login with correct password but also failed
try {
connect(user = 'test_auth_user3', password = '12345', url = context.config.jdbcUrl) {}
connect('test_auth_user3', '12345', context.config.jdbcUrl) {}
assertTrue(false. "should not be able to login")
} catch (Exception e) {
assertTrue(e.getMessage().contains("Access denied for user 'test_auth_user3'@'%'. Account is blocked for 5 second(s) (5 second(s) remaining) due to 2 consecutive failed logins."), e.getMessage())
}
// sleep 5 second to unlock account
sleep(5000)
result1 = connect(user = 'test_auth_user3', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user3', '12345', context.config.jdbcUrl) {
sql 'select 1'
}

Expand All @@ -134,20 +134,20 @@ suite("test_alter_user", "account,nonConcurrent") {
}

sql """set password for 'test_auth_user3' = password('Ab1234567^')"""
result1 = connect(user = 'test_auth_user3', password = 'Ab1234567^', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user3', 'Ab1234567^', context.config.jdbcUrl) {
sql 'select 1'
}
sql """set global validate_password_policy=NONE"""

// 5. test expire
sql """create user test_auth_user4 identified by '12345' PASSWORD_EXPIRE INTERVAL 5 SECOND"""
sql """grant all on *.* to test_auth_user4"""
result1 = connect(user = 'test_auth_user4', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user4', '12345', context.config.jdbcUrl) {
sql 'select 1'
}
sleep(6000)
try {
connect(user = 'test_auth_user4', password = '12345', url = context.config.jdbcUrl) {}
connect('test_auth_user4', '12345', context.config.jdbcUrl) {}
assertTrue(false. "should not be able to login")
} catch (Exception e) {
assertTrue(e.getMessage().contains("Your password has expired. To log in you must change it using a client that supports expired passwords."), e.getMessage())
Expand All @@ -157,25 +157,25 @@ suite("test_alter_user", "account,nonConcurrent") {
sql """drop user test_auth_user4"""
sql """create user test_auth_user4 identified by '12345'"""
sql """grant all on *.* to test_auth_user4"""
result1 = connect(user = 'test_auth_user4', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user4', '12345', context.config.jdbcUrl) {
sql 'select 1'
}

// 7. test after expire, reset password
sql """drop user test_auth_user4"""
sql """create user test_auth_user4 identified by '12345' PASSWORD_EXPIRE INTERVAL 5 SECOND"""
sql """grant all on *.* to test_auth_user4"""
result1 = connect(user = 'test_auth_user4', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user4', '12345', context.config.jdbcUrl) {
sql 'select 1'
}
sleep(6000)
sql """set password for 'test_auth_user4' = password('123')"""
result2 = connect(user = 'test_auth_user4', password = '123', url = context.config.jdbcUrl) {
result2 = connect('test_auth_user4', '123', context.config.jdbcUrl) {
sql 'select 1'
}
sleep(6000)
try {
connect(user = 'test_auth_user4', password = '123', url = context.config.jdbcUrl) {}
connect('test_auth_user4', '123', context.config.jdbcUrl) {}
assertTrue(false. "should not be able to login")
} catch (Exception e) {
assertTrue(e.getMessage().contains("Your password has expired. To log in you must change it using a client that supports expired passwords."), e.getMessage())
Expand All @@ -185,19 +185,19 @@ suite("test_alter_user", "account,nonConcurrent") {
sql """drop user test_auth_user4"""
sql """create user test_auth_user4 identified by '12345'"""
sql """grant all on *.* to test_auth_user4"""
result1 = connect(user = 'test_auth_user4', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user4', '12345', context.config.jdbcUrl) {
sql 'select 1'
}
sleep(1000)
result2 = connect(user = 'test_auth_user4', password = '12345', url = context.config.jdbcUrl) {
result2 = connect('test_auth_user4', '12345', context.config.jdbcUrl) {
sql 'select 1'
}

// 9. test user default database privileges
sql """drop user if exists test_auth_user4"""
sql """create user test_auth_user4 identified by '12345'"""
sql """grant SELECT_PRIV on regression_test.* to test_auth_user4"""
result1 = connect(user = 'test_auth_user4', password = '12345', url = context.config.jdbcUrl) {
result1 = connect('test_auth_user4', '12345', context.config.jdbcUrl) {
sql 'select 1'
sql 'use information_schema'
sql 'use mysql'
Expand Down
4 changes: 2 additions & 2 deletions regression-test/suites/account_p0/test_auth_show.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ suite("test_auth_show", "account") {

// With select priv for table, should be able to see db
sql """GRANT SELECT_PRIV ON ${dbName}.${tableName} TO ${user}"""
def result1 = connect(user=user, password="${pwd}", url=url) {
def result1 = connect(user, "${pwd}", url) {
sql """show databases like '${dbName}'"""
}
assertEquals(result1.size(), 1)
sql """REVOKE SELECT_PRIV ON ${dbName}.${tableName} FROM ${user}"""

// With show_view priv for table, should be able to see db
sql """GRANT SHOW_VIEW_PRIV ON ${dbName}.${tableName} TO ${user}"""
def result2 = connect(user=user, password="${pwd}", url=url) {
def result2 = connect(user, "${pwd}", url) {
sql """show databases like '${dbName}'"""
}
assertEquals(result2.size(), 1)
Expand Down
4 changes: 2 additions & 2 deletions regression-test/suites/account_p0/test_grant_priv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ suite("test_grant_priv") {

// test only have select_priv, can not grant to other user
sql """grant select_priv on ${dbName}.* to ${user1}"""
connect(user=user1, password="${pwd}", url=url) {
connect(user1, "${pwd}", url) {
try {
sql """grant select_priv on ${dbName}.* to ${user2}"""
Assert.fail("can not grant to other user");
Expand All @@ -49,7 +49,7 @@ suite("test_grant_priv") {

// test both have select_priv and grant_priv , can grant to other user
sql """grant grant_priv on ${dbName}.* to ${user1}"""
connect(user=user1, password="${pwd}", url=url) {
connect(user1, "${pwd}", url) {
try {
sql """grant select_priv on ${dbName}.* to ${user2}"""
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ suite("test_grant_priv_resource") {

// test only have USAGE_PRIV, can not grant to other user
sql """grant USAGE_PRIV on RESOURCE ${resource1} to ${user1}"""
connect(user=user1, password="${pwd}", url=url) {
connect(user1, "${pwd}", url) {
try {
sql """grant USAGE_PRIV on RESOURCE ${resource1} to ${user2}"""
Assert.fail("can not grant to other user");
Expand All @@ -44,7 +44,7 @@ suite("test_grant_priv_resource") {

// test both have USAGE_PRIV and grant_priv , can grant to other user
sql """grant grant_priv on RESOURCE * to ${user1}"""
connect(user=user1, password="${pwd}", url=url) {
connect(user1, "${pwd}", url) {
try {
sql """grant USAGE_PRIV on RESOURCE ${resource1} to ${user2}"""
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ suite("test_grant_priv_workload") {

// test only have USAGE_PRIV, can not grant to other user
sql """grant USAGE_PRIV on WORKLOAD GROUP ${workload1} to ${user1}"""
connect(user=user1, password="${pwd}", url=url) {
connect(user1, "${pwd}", url) {
try {
sql """grant USAGE_PRIV on WORKLOAD GROUP ${workload1} to ${user2}"""
Assert.fail("can not grant to other user");
Expand All @@ -44,7 +44,7 @@ suite("test_grant_priv_workload") {

// test both have USAGE_PRIV and grant_priv , can grant to other user
sql """grant grant_priv on WORKLOAD GROUP ${workload1} to ${user1}"""
connect(user=user1, password="${pwd}", url=url) {
connect(user1, "${pwd}", url) {
try {
sql """grant USAGE_PRIV on WORKLOAD GROUP ${workload1} to ${user2}"""
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,41 @@ suite("test_nereids_authentication", "query") {

def tokens = context.config.jdbcUrl.split('/')
def url=tokens[0] + "//" + tokens[2] + "/" + dbName + "?"
def result = connect(user=user, password='Doris_123456', url=url) {
def result = connect(user, 'Doris_123456', url) {
sql "SELECT * FROM ${tableName1}"
}
assertEquals(result.size(), 0)

connect(user=user, password='Doris_123456', url=url) {
connect(user, 'Doris_123456', url) {
test {
sql "SELECT * FROM ${tableName2}"
exception "denied"
}
}

connect(user=user, password='Doris_123456', url=url) {
connect(user, 'Doris_123456', url) {
test {
sql "SELECT count(*) FROM ${tableName2}"
exception "denied"
}
}

connect(user=user, password='Doris_123456', url=url) {
connect(user, 'Doris_123456', url) {
test {
sql "SELECT * FROM ${tableName1}, ${tableName2} WHERE ${tableName1}.`key` = ${tableName2}.`key`"
exception "denied"
}
}

sql "GRANT SELECT_PRIV ON internal.${dbName}.${tableName2} TO ${user}"
connect(user=user, password='Doris_123456', url=url) {
connect(user, 'Doris_123456', url) {
sql "SELECT * FROM ${tableName2}"
}
assertEquals(result.size(), 0)
connect(user=user, password='Doris_123456', url=url) {
connect(user, 'Doris_123456', url) {
sql "SELECT count(*) FROM ${tableName2}"
}
connect(user=user, password='Doris_123456', url=url) {
connect(user, 'Doris_123456', url) {
sql "SELECT * FROM ${tableName1}, ${tableName2} WHERE ${tableName1}.`key` = ${tableName2}.`key`"
}
assertEquals(result.size(), 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ suite("test_nereids_row_policy") {
def url=tokens[0] + "//" + tokens[2] + "/" + dbName + "?"

def assertQueryResult = { size ->
def result1 = connect(user=user, password='123abc!@#', url=url) {
def result1 = connect(user, '123abc!@#', url) {
sql "set enable_nereids_planner = false"
sql "SELECT * FROM ${tableName}"
}
def result2 = connect(user=user, password='123abc!@#', url=url) {
def result2 = connect(user, '123abc!@#', url) {
sql "set enable_nereids_planner = true"
sql "set enable_fallback_to_original_planner = false"
sql "SELECT * FROM ${tableName}"
}
connect(user=user, password='123abc!@#', url=url) {
connect(user, '123abc!@#', url) {
sql "set enable_nereids_planner = true"
sql "set enable_fallback_to_original_planner = false"
test {
Expand Down
4 changes: 2 additions & 2 deletions regression-test/suites/account_p0/test_role.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ suite("test_role", "account") {
sql """GRANT SELECT_PRIV ON ${context.config.defaultDb} TO ROLE '${role}'"""
sql """GRANT SELECT_PRIV ON ${dbName} TO ROLE '${role}'"""
sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}' DEFAULT ROLE '${role}'"""
def result1 = connect(user=user, password="${pwd}", url=context.config.jdbcUrl) {
def result1 = connect(user, "${pwd}", context.config.jdbcUrl) {
sql "show databases like '${dbName}'"
}
assertEquals(result1.size(), 1)

sql """REVOKE SELECT_PRIV ON ${dbName} FROM ROLE '${role}'"""
def result2 = connect(user=user, password="${pwd}", url=context.config.jdbcUrl) {
def result2 = connect(user, "${pwd}", context.config.jdbcUrl) {
sql "show databases like '${dbName}'"
}
assertEquals(result2.size(), 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ suite("test_admin_copy_tablet_auth","p0,auth") {
try_sql("DROP USER ${user}")
sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}'"""
sql """grant select_priv on regression_test to ${user}"""
connect(user=user, password="${pwd}", url=context.config.jdbcUrl) {
connect(user, "${pwd}", context.config.jdbcUrl) {
try {
sql "ADMIN COPY TABLET 10010 PROPERTIES('backend_id' = '10001');"
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ suite("test_alter_policy_auth","p0,auth") {
try_sql("DROP USER ${user}")
sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}'"""
sql """grant select_priv on regression_test to ${user}"""
connect(user=user, password="${pwd}", url=context.config.jdbcUrl) {
connect(user, "${pwd}", context.config.jdbcUrl) {
try {
sql """
ALTER STORAGE POLICY has_test_policy_to_alter PROPERTIES("cooldown_datetime" = "2023-06-08 00:00:00");
Expand Down
4 changes: 2 additions & 2 deletions regression-test/suites/auth_p0/test_alter_view_auth.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ suite("test_alter_view_auth","p0,auth") {
"""
sql """grant select_priv on regression_test to ${user}"""
sql """create view ${dbName}.${viewName} as select * from ${dbName}.${tableName};"""
connect(user=user, password="${pwd}", url=context.config.jdbcUrl) {
connect(user, "${pwd}", context.config.jdbcUrl) {
try {
sql "alter view ${dbName}.${viewName} as select * from ${dbName}.${tableName};"
} catch (Exception e) {
Expand All @@ -51,7 +51,7 @@ suite("test_alter_view_auth","p0,auth") {
}
}
sql """grant Alter_priv on ${dbName}.${viewName} to ${user}"""
connect(user=user, password="${pwd}", url=context.config.jdbcUrl) {
connect(user, "${pwd}", context.config.jdbcUrl) {
try {
sql "alter view ${dbName}.${viewName} as select * from ${dbName}.${tableName};"
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ suite("test_cancel_alter_system_auth","p0,auth") {
try_sql("DROP USER ${user}")
sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}'"""
sql """grant select_priv on regression_test to ${user}"""
connect(user=user, password="${pwd}", url=context.config.jdbcUrl) {
connect(user, "${pwd}", context.config.jdbcUrl) {
try {
sql "CANCEL DECOMMISSION BACKEND 'id1';"
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ suite("test_create_policy_auth","p0,auth") {
try_sql("DROP USER ${user}")
sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}'"""
sql """grant select_priv on regression_test to ${user}"""
connect(user=user, password="${pwd}", url=context.config.jdbcUrl) {
connect(user, "${pwd}", context.config.jdbcUrl) {
try {
sql "CREATE ROW POLICY test_create_policy_auth ON test.table1 AS RESTRICTIVE TO test USING (c1 = 'a');"
} catch (Exception e) {
Expand Down
Loading

0 comments on commit 1c47f5c

Please sign in to comment.