[TD-2794]<fix>: fix authentication failed with changed password
This commit is contained in:
parent
d2e9f8f128
commit
9c037b011c
|
@ -0,0 +1,59 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class AuthenticationTest {
|
||||
|
||||
private static final String host = "master";
|
||||
private static final String user = "root";
|
||||
private static final String password = "123456";
|
||||
private Connection conn;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
stmt.execute("show databases");
|
||||
ResultSet rs = stmt.getResultSet();
|
||||
ResultSetMetaData meta = rs.getMetaData();
|
||||
while (rs.next()) {
|
||||
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||
System.out.print(meta.getColumnLabel(i) + ":" + rs.getString(i) + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import org.junit.Test;
|
|||
import java.sql.*;
|
||||
|
||||
public class RestfulDriverTest {
|
||||
private static final String host = "master";
|
||||
|
||||
@Test
|
||||
public void connect() {
|
||||
|
@ -15,9 +16,9 @@ public class RestfulDriverTest {
|
|||
@Test
|
||||
public void acceptsURL() throws SQLException {
|
||||
Driver driver = new RestfulDriver();
|
||||
boolean isAccept = driver.acceptsURL("jdbc:TAOS-RS://master:6041");
|
||||
boolean isAccept = driver.acceptsURL("jdbc:TAOS-RS://" + host + ":6041");
|
||||
Assert.assertTrue(isAccept);
|
||||
isAccept = driver.acceptsURL("jdbc:TAOS://master:6041");
|
||||
isAccept = driver.acceptsURL("jdbc:TAOS://" + host + ":6041");
|
||||
Assert.assertFalse(isAccept);
|
||||
}
|
||||
|
||||
|
@ -26,6 +27,9 @@ public class RestfulDriverTest {
|
|||
Driver driver = new RestfulDriver();
|
||||
final String url = "";
|
||||
DriverPropertyInfo[] propertyInfo = driver.getPropertyInfo(url, null);
|
||||
for (DriverPropertyInfo prop : propertyInfo) {
|
||||
System.out.println(prop);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
|
||||
import org.junit.*;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
|
@ -10,12 +9,13 @@ import java.util.Random;
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class RestfulJDBCTest {
|
||||
|
||||
private static final String host = "master";
|
||||
private Connection connection;
|
||||
|
||||
@Before
|
||||
public void before() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS-RS://master:6041/restful_test?user=root&password=taosdata");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata");
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -21,4 +21,5 @@ public class SqlSyntaxValidatorTest {
|
|||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("drop database test"));
|
||||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("drop database if exist test"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue