diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java index 15afbdbbe644c31d4c6b183f2e251c5d2c59b84b..c21059d2c3cfad6ac100654a9a7d0d8578b1bbfe 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java @@ -10,6 +10,7 @@ import java.util.Properties; public class AuthenticationTest { + // private static final String host = "127.0.0.1"; private static final String host = "master"; private static final String user = "root"; private static final String password = "123456"; @@ -17,7 +18,20 @@ public class AuthenticationTest { @Test public void test() { - try (Statement stmt = conn.createStatement()) { + // change password + try { + conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata"); + Statement stmt = conn.createStatement(); + stmt.execute("alter user " + user + " pass '" + password + "'"); + stmt.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + // use new to login and execute query + try { + conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password); + Statement stmt = conn.createStatement(); stmt.execute("show databases"); ResultSet rs = stmt.getResultSet(); ResultSetMetaData meta = rs.getMetaData(); @@ -30,28 +44,24 @@ public class AuthenticationTest { } catch (SQLException e) { e.printStackTrace(); } - } - - @Before - public void before() { + // change password back try { - Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); - Properties props = new Properties(); - props.setProperty(TSDBDriver.PROPERTY_KEY_USER, user); - props.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, password); - conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test", props); - } catch (SQLException | ClassNotFoundException e) { + conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password); + Statement stmt = conn.createStatement(); + stmt.execute("alter user " + user + " pass 'taosdata'"); + stmt.close(); + conn.close(); + } catch (SQLException e) { e.printStackTrace(); } + } - @After - public void after() { + @Before + public void before() { try { - if (conn != null) { - conn.close(); - } - } catch (SQLException e) { + Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); + } catch (ClassNotFoundException e) { e.printStackTrace(); } }