Skip to content

Commit f126cac

Browse files
authored
Merge pull request #361 from databendlabs/fix/encode-pass-test
fix: testEncodePass
2 parents e87a655 + 60187a0 commit f126cac

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,16 +506,29 @@ public void testSelectWithClusterKey() throws SQLException {
506506

507507
@Test(groups = "IT")
508508
public void testEncodePass() throws SQLException {
509-
try (Connection conn = Utils.createConnection()) {
510-
conn.createStatement().execute("create user if not exists 'u01' identified by 'mS%aFRZW*GW';");
511-
conn.createStatement().execute("GRANT ALL PRIVILEGES ON default.* TO 'u01'@'%'");
509+
try (Connection conn = Utils.createConnection();
510+
Statement stmt = conn.createStatement()) {
511+
stmt.execute("drop user if exists u01");
512+
stmt.execute("drop role if exists test_role");
513+
stmt.execute("create role test_role");
514+
stmt.execute("grant all PRIVILEGES ON default.* to role test_role");
515+
stmt.execute("create user u01 identified by 'mS%aFRZW*GW' with default_role='test_role'");
516+
stmt.execute("grant role test_role to u01");
512517
Properties p = new Properties();
513518
p.setProperty("user", "u01");
514519
p.setProperty("password", "mS%aFRZW*GW");
515-
try(Connection conn2 = Utils.createConnection("default", p)) {
516-
conn2.createStatement().execute("select 1");
520+
try (Connection conn2 = Utils.createConnection("default", p);
521+
Statement stmt2 = conn2.createStatement()) {
522+
stmt2.execute("select 1");
523+
}
524+
} finally {
525+
try (Connection cleanupConn = Utils.createConnection();
526+
Statement cleanupStmt = cleanupConn.createStatement()) {
527+
cleanupStmt.execute("drop user if exists u01");
528+
cleanupStmt.execute("drop role if exists test_role");
529+
} catch (SQLException ignore) {
530+
// ignore cleanup failure
517531
}
518-
conn.createStatement().execute("drop user if exists 'u01'");
519532
}
520533
}
521534

0 commit comments

Comments
 (0)