Skip to content

Commit 903f487

Browse files
committed
misc - adding certificate validation test
1 parent 94f1072 commit 903f487

File tree

7 files changed

+501
-12
lines changed

7 files changed

+501
-12
lines changed

src/main/java/org/mariadb/jdbc/plugin/tls/TlsSocketPluginLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.ServiceLoader;
2727
import org.mariadb.jdbc.client.tls.DefaultTlsSocketPlugin;
2828

29-
public class TlsSocketPluginLoader {
29+
public final class TlsSocketPluginLoader {
3030

3131
/**
3232
* Get authentication plugin from type String. Customs authentication plugin can be added

src/main/resources/META-INF/services/org.mariadb.jdbc.plugin.tls.TlsSocketPlugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
# You should have received a copy of the GNU Lesser General Public License along
1717
# with this library; if not, write to Monty Program Ab info@montyprogram.com.
1818

19-
org.mariadb.jdbc.internal.protocol.tls.DefaultTlsSocketPlugin
19+
org.mariadb.jdbc.client.tls.DefaultTlsSocketPlugin

src/test/java/org/mariadb/jdbc/integration/CredentialPluginTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class CredentialPluginTest extends Common {
4343
*/
4444
@BeforeAll
4545
public static void beforeTest() throws SQLException {
46+
Assumptions.assumeTrue(isMariaDBServer());
4647
drop();
4748
boolean useOldNotation = true;
4849
if ((isMariaDBServer() && minVersion(10, 2, 0))
@@ -139,9 +140,7 @@ public void envsIdentityTest() throws Exception {
139140
setEnv(tmpEnv);
140141

141142
assertThrowsContains(
142-
SQLException.class,
143-
() -> createCon("credentialType=ENV&pwdKey=myPwdKey"),
144-
"Access denied");
143+
SQLException.class, () -> createCon("credentialType=ENV&pwdKey=myPwdKey"), "Access denied");
145144
tmpEnv.put("myPwdKey", "!Passw0rd3Works");
146145
setEnv(tmpEnv);
147146

src/test/java/org/mariadb/jdbc/integration/Sha256AuthenticationTest.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public static void drop() throws SQLException {
1818
stmt.execute("DROP USER IF EXISTS 'cachingSha256User'@'%'");
1919
stmt.execute("DROP USER IF EXISTS 'cachingSha256User2'@'%'");
2020
}
21+
// reason is that after nativePassword test, it sometime always return wrong authentication id
22+
// not cached
23+
// !? strange, but mysql server error.
24+
if (haveSsl()) {
25+
try (Connection con = createCon("sslMode=trust")) {}
26+
}
2127
}
2228

2329
@BeforeAll
@@ -62,6 +68,7 @@ private static String checkFileExists(String path) throws IOException {
6268

6369
@Test
6470
public void nativePassword() throws Exception {
71+
Assumptions.assumeTrue(haveSsl());
6572
Assumptions.assumeTrue(
6673
!isWindows && !isMariaDBServer() && rsaPublicKey != null && minVersion(8, 0, 0));
6774
Statement stmt = sharedConn.createStatement();
@@ -104,27 +111,27 @@ public void cachingSha256PluginTest() throws Exception {
104111
}
105112

106113
try (Connection con =
107-
createCon("user=cachingSha256User&password=MySup8rPassw@ord&allowPublicKeyRetrieval")) {
114+
createCon("user=cachingSha256User&password=MySup8rPassw@ord&allowPublicKeyRetrieval")) {
108115
con.isValid(1);
109116
} catch (SQLException sqle) {
110117
// mysql authentication might fail !?
111118
}
112119

113120
Assumptions.assumeTrue(haveSsl());
114121
try (Connection con =
115-
createCon("user=cachingSha256User&password=MySup8rPassw@ord&sslMode=trust")) {
122+
createCon("user=cachingSha256User&password=MySup8rPassw@ord&sslMode=trust")) {
116123
con.isValid(1);
117124
}
118125

119126
try (Connection con =
120-
createCon("user=cachingSha256User&password=MySup8rPassw@ord&allowPublicKeyRetrieval")) {
127+
createCon("user=cachingSha256User&password=MySup8rPassw@ord&allowPublicKeyRetrieval")) {
121128
con.isValid(1);
122129
}
123130

124131
try (Connection con =
125-
createCon(
126-
"user=cachingSha256User&password=MySup8rPassw@ord&serverRsaPublicKeyFile="
127-
+ rsaPublicKey)) {
132+
createCon(
133+
"user=cachingSha256User&password=MySup8rPassw@ord&serverRsaPublicKeyFile="
134+
+ rsaPublicKey)) {
128135
con.isValid(1);
129136
}
130137
}
@@ -151,5 +158,4 @@ public void cachingSha256PluginTestException() throws Exception {
151158
() -> createCon("user=cachingSha256User&password=MySup8rPassw@ord"),
152159
"RSA public key is not available client side");
153160
}
154-
155161
}

0 commit comments

Comments
 (0)