Skip to content

Commit

Permalink
misc - adding certificate validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Mar 29, 2021
1 parent 94f1072 commit 903f487
Show file tree
Hide file tree
Showing 7 changed files with 501 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.ServiceLoader;
import org.mariadb.jdbc.client.tls.DefaultTlsSocketPlugin;

public class TlsSocketPluginLoader {
public final class TlsSocketPluginLoader {

/**
* Get authentication plugin from type String. Customs authentication plugin can be added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# You should have received a copy of the GNU Lesser General Public License along
# with this library; if not, write to Monty Program Ab info@montyprogram.com.

org.mariadb.jdbc.internal.protocol.tls.DefaultTlsSocketPlugin
org.mariadb.jdbc.client.tls.DefaultTlsSocketPlugin
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class CredentialPluginTest extends Common {
*/
@BeforeAll
public static void beforeTest() throws SQLException {
Assumptions.assumeTrue(isMariaDBServer());
drop();
boolean useOldNotation = true;
if ((isMariaDBServer() && minVersion(10, 2, 0))
Expand Down Expand Up @@ -139,9 +140,7 @@ public void envsIdentityTest() throws Exception {
setEnv(tmpEnv);

assertThrowsContains(
SQLException.class,
() -> createCon("credentialType=ENV&pwdKey=myPwdKey"),
"Access denied");
SQLException.class, () -> createCon("credentialType=ENV&pwdKey=myPwdKey"), "Access denied");
tmpEnv.put("myPwdKey", "!Passw0rd3Works");
setEnv(tmpEnv);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public static void drop() throws SQLException {
stmt.execute("DROP USER IF EXISTS 'cachingSha256User'@'%'");
stmt.execute("DROP USER IF EXISTS 'cachingSha256User2'@'%'");
}
// reason is that after nativePassword test, it sometime always return wrong authentication id
// not cached
// !? strange, but mysql server error.
if (haveSsl()) {
try (Connection con = createCon("sslMode=trust")) {}
}
}

@BeforeAll
Expand Down Expand Up @@ -62,6 +68,7 @@ private static String checkFileExists(String path) throws IOException {

@Test
public void nativePassword() throws Exception {
Assumptions.assumeTrue(haveSsl());
Assumptions.assumeTrue(
!isWindows && !isMariaDBServer() && rsaPublicKey != null && minVersion(8, 0, 0));
Statement stmt = sharedConn.createStatement();
Expand Down Expand Up @@ -104,27 +111,27 @@ public void cachingSha256PluginTest() throws Exception {
}

try (Connection con =
createCon("user=cachingSha256User&password=MySup8rPassw@ord&allowPublicKeyRetrieval")) {
createCon("user=cachingSha256User&password=MySup8rPassw@ord&allowPublicKeyRetrieval")) {
con.isValid(1);
} catch (SQLException sqle) {
// mysql authentication might fail !?
}

Assumptions.assumeTrue(haveSsl());
try (Connection con =
createCon("user=cachingSha256User&password=MySup8rPassw@ord&sslMode=trust")) {
createCon("user=cachingSha256User&password=MySup8rPassw@ord&sslMode=trust")) {
con.isValid(1);
}

try (Connection con =
createCon("user=cachingSha256User&password=MySup8rPassw@ord&allowPublicKeyRetrieval")) {
createCon("user=cachingSha256User&password=MySup8rPassw@ord&allowPublicKeyRetrieval")) {
con.isValid(1);
}

try (Connection con =
createCon(
"user=cachingSha256User&password=MySup8rPassw@ord&serverRsaPublicKeyFile="
+ rsaPublicKey)) {
createCon(
"user=cachingSha256User&password=MySup8rPassw@ord&serverRsaPublicKeyFile="
+ rsaPublicKey)) {
con.isValid(1);
}
}
Expand All @@ -151,5 +158,4 @@ public void cachingSha256PluginTestException() throws Exception {
() -> createCon("user=cachingSha256User&password=MySup8rPassw@ord"),
"RSA public key is not available client side");
}

}
Loading

0 comments on commit 903f487

Please sign in to comment.