use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testBug20825727.
/**
* Tests fix for BUG#20825727 - CONNECT FAILURE WHEN TRY TO CONNECT SHA USER WITH DIFFERENT CHARSET.
*
* @throws Exception
*/
@Test
public void testBug20825727() throws Exception {
assumeTrue(versionMeetsMinimum(5, 5, 7), "MySQL 5.5.7+ is required to run this test.");
assumeTrue((((MysqlConnection) this.conn).getSession().getServerSession().getCapabilities().getCapabilityFlags() & NativeServerSession.CLIENT_SSL) != 0, "This test requires server with SSL support.");
assumeTrue(supportsTestCertificates(this.stmt), "This test requires the server configured with SSL certificates from ConnectorJ/src/test/config/ssl-test-certs");
Properties props = new Properties();
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(dbUrl, props);
Statement testStmt = testConn.createStatement();
this.rs = testStmt.executeQuery("SELECT @@GLOBAL.HAVE_SSL = 'YES' AS have_ssl");
final boolean sslEnabled = this.rs.next() && this.rs.getBoolean(1);
this.rs = testStmt.executeQuery("SHOW STATUS LIKE '%Rsa_public_key%'");
final boolean rsaEnabled = this.rs.next() && this.rs.getString(1).length() > 0;
System.out.println();
System.out.println("* Testing URL: " + dbUrl + " [SSL enabled: " + sslEnabled + "] [RSA enabled: " + rsaEnabled + "]");
System.out.println("******************************************************************************************************************************" + "*************");
System.out.printf("%-25s : %-25s : %s : %-25s : %-18s : %-18s [%s]%n", "Connection Type", "Auth. Plugin", "pwd ", "Encoding Prop.", "Encoding Value", "Server Encoding", "TstRes");
System.out.println("------------------------------------------------------------------------------------------------------------------------------" + "-------------");
boolean clearTextPluginInstalled = false;
boolean secureAuthChanged = false;
try {
String[] plugins;
// install cleartext plugin if required
this.rs = testStmt.executeQuery("SELECT (PLUGIN_LIBRARY LIKE 'auth_test_plugin%') FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME='cleartext_plugin_server'");
if (!this.rs.next() || !this.rs.getBoolean(1)) {
String ext = System.getProperty(PropertyDefinitions.SYSP_os_name).toUpperCase().indexOf("WINDOWS") > -1 ? ".dll" : ".so";
try {
testStmt.execute("INSTALL PLUGIN cleartext_plugin_server SONAME 'auth_test_plugin" + ext + "'");
} catch (SQLException e) {
if (e.getErrorCode() == MysqlErrorNumbers.ER_CANT_OPEN_LIBRARY) {
assumeTrue(false, "This test requires the server installed with the test package.");
} else {
throw e;
}
}
clearTextPluginInstalled = true;
}
if (testConn.getSession().versionMeetsMinimum(5, 7, 5)) {
// mysql_old_password plugin not supported
plugins = new String[] { "cleartext_plugin_server,-1", "mysql_native_password,0", "sha256_password,2" };
} else if (testConn.getSession().versionMeetsMinimum(5, 6, 6)) {
plugins = new String[] { "cleartext_plugin_server,-1", "mysql_native_password,0", "mysql_old_password,1", "sha256_password,2" };
// temporarily disable --secure-auth mode to allow old format passwords
testStmt.executeUpdate("SET @current_secure_auth = @@global.secure_auth");
testStmt.executeUpdate("SET @@global.secure_auth = off");
secureAuthChanged = true;
} else {
// sha256_password plugin not supported
plugins = new String[] { "cleartext_plugin_server,-1", "mysql_native_password,0", "mysql_old_password,1" };
}
final String simplePwd = "my\tpass word";
final String complexPwd = "my\tp\u00e4ss w\u263ard";
for (String encoding : new String[] { "", "UTF-8", "ISO-8859-1", "US-ASCII" }) {
for (String plugin : plugins) {
String pluginName = plugin.split(",")[0];
int pwdHashingMethod = Integer.parseInt(plugin.split(",")[1]);
String testStep = "";
try {
testStep = "create user";
testBug20825727CreateUser(dbUrl, "testBug20825727", simplePwd, pluginName, pwdHashingMethod);
testStep = "login with simple password";
testBug20825727TestLogin(dbUrl, testConn.getPropertySet().getStringProperty(PropertyKey.characterEncoding).getValue(), sslEnabled, rsaEnabled, "testBug20825727", simplePwd, encoding, pluginName);
testStep = "change password";
testBug20825727ChangePassword(dbUrl, "testBug20825727", complexPwd, pluginName, pwdHashingMethod);
testStep = "login with complex password";
testBug20825727TestLogin(dbUrl, testConn.getPropertySet().getStringProperty(PropertyKey.characterEncoding).getValue(), sslEnabled, rsaEnabled, "testBug20825727", complexPwd, encoding, pluginName);
} catch (SQLException e) {
e.printStackTrace();
fail("Failed at '" + testStep + "' using encoding '" + encoding + "' and plugin '" + pluginName + "'. See also system output for more details.");
} finally {
try {
dropUser(testStmt, "'testBug20825727'@'%'");
} catch (Exception e) {
}
}
}
}
} finally {
if (clearTextPluginInstalled) {
testStmt.executeUpdate("UNINSTALL PLUGIN cleartext_plugin_server");
}
if (secureAuthChanged) {
testStmt.executeUpdate("SET @@global.secure_auth = @current_secure_auth");
}
testStmt.close();
testConn.close();
}
}
use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testBug74711.
/**
* Tests fix for Bug#74711 - FORGOTTEN WORKAROUND FOR BUG#36326.
*
* This test requires a server started with the options '--query_cache_type=1' and '--query_cache_size=N', (N > 0).
*
* @throws Exception
*/
@Test
public void testBug74711() throws Exception {
assumeTrue(((MysqlConnection) this.conn).getSession().getServerSession().isQueryCacheEnabled(), "testBug77411() requires a server supporting a query cache.");
this.rs = this.stmt.executeQuery("SELECT @@global.query_cache_type, @@global.query_cache_size");
this.rs.next();
assumeTrue("ON".equalsIgnoreCase(this.rs.getString(1)) && !"0".equals(this.rs.getString(2)), "testBug77411() requires a server started with the options '--query_cache_type=1' and '--query_cache_size=N', (N > 0).");
boolean useLocTransSt = false;
boolean useElideSetAC = false;
do {
final String testCase = String.format("Case: [LocTransSt: %s, ElideAC: %s ]", useLocTransSt ? "Y" : "N", useElideSetAC ? "Y" : "N");
final Properties props = new Properties();
props.setProperty(PropertyKey.useLocalTransactionState.getKeyName(), Boolean.toString(useLocTransSt));
props.setProperty(PropertyKey.elideSetAutoCommits.getKeyName(), Boolean.toString(useElideSetAC));
Connection testConn = getConnectionWithProps(props);
assertEquals(useLocTransSt, ((JdbcConnection) testConn).getPropertySet().getBooleanProperty(PropertyKey.useLocalTransactionState).getValue().booleanValue(), testCase);
assertEquals(useElideSetAC, ((JdbcConnection) testConn).getPropertySet().getBooleanProperty(PropertyKey.elideSetAutoCommits).getValue().booleanValue(), testCase);
testConn.close();
} while ((useLocTransSt = !useLocTransSt) || (useElideSetAC = !useElideSetAC));
}
use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testBug11237.
/**
* Tests fix for BUG#11237 useCompression=true and LOAD DATA LOCAL INFILE SQL Command
*
* @throws Exception
*/
@Test
public void testBug11237() throws Exception {
assumeTrue(supportsLoadLocalInfile(this.stmt), "This test requires the server started with --local-infile=ON");
this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'max_allowed_packet'");
this.rs.next();
long defaultMaxAllowedPacket = this.rs.getInt(2);
boolean changeMaxAllowedPacket = defaultMaxAllowedPacket < 4 + 1024 * 1024 * 16 - 1;
int requiredSize = 1024 * 1024 * 300;
int fieldLength = 1023;
int loops = requiredSize / 2 / (fieldLength + 1);
File testFile = File.createTempFile("cj-testloaddata", ".dat");
testFile.deleteOnExit();
// TODO: following cleanup doesn't work correctly during concurrent execution of testsuite
// cleanupTempFiles(testFile, "cj-testloaddata");
BufferedOutputStream bOut = new BufferedOutputStream(new FileOutputStream(testFile));
byte[] bytes1 = new byte[fieldLength];
Arrays.fill(bytes1, (byte) 'a');
byte[] bytes2 = new byte[fieldLength];
Arrays.fill(bytes2, (byte) 'b');
byte tab = '\t';
byte nl = '\n';
for (int i = 0; i < loops; i++) {
bOut.write(bytes1);
bOut.write(tab);
bOut.write(bytes2);
bOut.write(nl);
bOut.flush();
}
bOut.close();
createTable("testBug11237", "(field1 VARCHAR(1024), field2 VARCHAR(1024))");
StringBuilder fileNameBuf = null;
if (File.separatorChar == '\\') {
fileNameBuf = new StringBuilder();
String fileName = testFile.getAbsolutePath();
int fileNameLength = fileName.length();
for (int i = 0; i < fileNameLength; i++) {
char c = fileName.charAt(i);
if (c == '\\') {
fileNameBuf.append("/");
} else {
fileNameBuf.append(c);
}
}
} else {
fileNameBuf = new StringBuilder(testFile.getAbsolutePath());
}
Connection conn1 = null;
try {
if (changeMaxAllowedPacket) {
this.stmt.executeUpdate("SET GLOBAL max_allowed_packet=" + 1024 * 1024 * 17);
}
Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.allowLoadLocalInfile.getKeyName(), "true");
props.setProperty(PropertyKey.useCompression.getKeyName(), "true");
conn1 = getConnectionWithProps(props);
Statement stmt1 = conn1.createStatement();
int updateCount = stmt1.executeUpdate("LOAD DATA LOCAL INFILE '" + fileNameBuf.toString() + "' INTO TABLE testBug11237 CHARACTER SET " + CharsetMappingWrapper.getStaticMysqlCharsetForJavaEncoding(((MysqlConnection) this.conn).getPropertySet().getStringProperty(PropertyKey.characterEncoding).getValue(), ((JdbcConnection) conn1).getServerVersion()));
assertTrue(updateCount == loops);
} finally {
if (changeMaxAllowedPacket) {
this.stmt.executeUpdate("SET GLOBAL max_allowed_packet=" + defaultMaxAllowedPacket);
}
if (conn1 != null) {
conn1.close();
}
}
}
use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testBug28150662.
/**
* Tests fix for BUG#28150662, CONNECTOR/J 8 MALFORMED DATABASE URL EXCEPTION WHIT CORRECT URL STRING.
*
* @throws Exception
*/
@Test
public void testBug28150662() throws Exception {
HostInfo hostInfo = mainConnectionUrl.getMainHost();
String user = hostInfo.getUser() == null ? "" : hostInfo.getUser();
String password = hostInfo.getPassword() == null ? "" : hostInfo.getPassword();
List<String> connStr = new ArrayList<>();
connStr.add(dbUrl + "&sessionVariables=sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0&connectionCollation=utf8mb4_unicode_ci&sslMode=DISABLED&allowPublicKeyRetrieval=true");
connStr.add(dbUrl + "&connectionCollation=utf8mb4_unicode_ci&sslMode=DISABLED&allowPublicKeyRetrieval=true&sessionVariables=sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0");
connStr.add(String.format("jdbc:mysql://address=(host=%1$s)(port=%2$d)(sslMode=DISABLED)(allowPublicKeyRetrieval=true)(connectionCollation=utf8mb4_unicode_ci)(sessionVariables=sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0)(user=%3$s)(password=%4$s)/%5$s", getEncodedHostFromTestsuiteUrl(), getPortFromTestsuiteUrl(), user, password, hostInfo.getDatabase()));
connStr.add(String.format("jdbc:mysql://(host=%1$s,port=%2$d,connectionCollation=utf8mb4_unicode_ci,sslMode=DISABLED,allowPublicKeyRetrieval=true,sessionVariables=sql_mode='IGNORE_SPACE%3$sANSI'%3$sFOREIGN_KEY_CHECKS=0,user=%4$s,password=%5$s)/%6$s", getEncodedHostFromTestsuiteUrl(), getPortFromTestsuiteUrl(), "%2C", user, password, hostInfo.getDatabase()));
for (String cs : connStr) {
JdbcConnection c1 = (JdbcConnection) getConnectionWithProps(cs, appendRequiredProperties(null));
assertEquals("utf8mb4_unicode_ci", c1.getPropertySet().getStringProperty(PropertyKey.connectionCollation).getValue());
String foreignKeyChecks = getMysqlVariable(c1, "FOREIGN_KEY_CHECKS");
assertTrue("OFF".equalsIgnoreCase(foreignKeyChecks) || "0".equals(foreignKeyChecks));
assertEquals("sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0", c1.getPropertySet().getStringProperty(PropertyKey.sessionVariables).getValue());
String sqlMode = getMysqlVariable(c1, "sql_mode");
assertTrue(sqlMode.indexOf("ANSI") != -1);
assertTrue(sqlMode.indexOf("IGNORE_SPACE") != -1);
}
}
use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testBug22508715.
/**
* Tests fix for Bug#22508715, SETSESSIONMAXROWS() CALL ON CLOSED CONNECTION RESULTS IN NPE.
*
* @throws Exception
*/
@Test
public void testBug22508715() throws Exception {
Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
Connection con = getConnectionWithProps(props);
con.close();
assertThrows(SQLNonTransientConnectionException.class, "No operations allowed after connection closed.*", () -> {
((JdbcConnection) con).setSessionMaxRows(0);
return null;
});
}
Aggregations