|
36 | 36 | import io.netty.handler.ssl.SslContext; |
37 | 37 | import io.netty.handler.ssl.SslContextBuilder; |
38 | 38 | import io.netty.handler.ssl.util.SelfSignedCertificate; |
| 39 | +import io.r2dbc.spi.R2dbcPermissionDeniedException; |
39 | 40 | import io.r2dbc.spi.ValidationDepth; |
40 | 41 |
|
| 42 | +import org.junit.Assume; |
41 | 43 | import org.junit.jupiter.api.AfterEach; |
42 | 44 | import org.junit.jupiter.api.BeforeAll; |
43 | 45 | import org.junit.jupiter.api.BeforeEach; |
|
52 | 54 | import java.time.Duration; |
53 | 55 |
|
54 | 56 | import static org.assertj.core.api.Assertions.assertThat; |
| 57 | +import static org.junit.Assert.assertThrows; |
55 | 58 |
|
56 | 59 | @ExtendWith(TestContainerExtension.class) |
57 | 60 | public class SslTunnelIntegrationTest { |
@@ -131,6 +134,59 @@ void sslTunnelConnectionTest() { |
131 | 134 | connection.close().block(); |
132 | 135 | } |
133 | 136 |
|
| 137 | + @Test |
| 138 | + void sslDisabledTest() { |
| 139 | + Assume.assumeTrue(TestServerUtil.getServerVersion().getMajor() >= 8); |
| 140 | + |
| 141 | + MySqlConnectionConfiguration configuration = MySqlConnectionConfiguration.builder() |
| 142 | + .host("localhost") |
| 143 | + .port(sslTunnelServer.getLocalPort()) |
| 144 | + .user(TestServerUtil.getUsername()) |
| 145 | + .password(TestServerUtil.getPassword()) |
| 146 | + .database(TestServerUtil.getDatabase()) |
| 147 | + .createDatabaseIfNotExist(true) |
| 148 | + .sslMode(SslMode.DISABLED) |
| 149 | + .build(); |
| 150 | + |
| 151 | + assertThrows(R2dbcPermissionDeniedException.class, () -> MySqlConnectionFactory.from(configuration).create().block()); |
| 152 | + } |
| 153 | + |
| 154 | + @Test |
| 155 | + void sslDisabledInvalidRsaConfig() { |
| 156 | + Assume.assumeTrue(TestServerUtil.getServerVersion().getMajor() >= 8); |
| 157 | + |
| 158 | + MySqlConnectionConfiguration configuration2 = MySqlConnectionConfiguration.builder() |
| 159 | + .host("localhost") |
| 160 | + .port(sslTunnelServer.getLocalPort()) |
| 161 | + .user(TestServerUtil.getUsername()) |
| 162 | + .password(TestServerUtil.getPassword()) |
| 163 | + .database(TestServerUtil.getDatabase()) |
| 164 | + .createDatabaseIfNotExist(true) |
| 165 | + .sslMode(SslMode.DISABLED) |
| 166 | + .serverRSAPublicKeyFile("/path/to/mysql/serverRSAPublicKey.pem") |
| 167 | + .build(); |
| 168 | + |
| 169 | + assertThrows(IllegalArgumentException.class, () -> MySqlConnectionFactory.from(configuration2).create().block()); |
| 170 | + } |
| 171 | + |
| 172 | + @Test |
| 173 | + void sslDisabledValidRsaConfig() { |
| 174 | + Assume.assumeTrue(TestServerUtil.getServerVersion().getMajor() >= 8); |
| 175 | + |
| 176 | + MySqlConnectionConfiguration configuration3 = MySqlConnectionConfiguration.builder() |
| 177 | + .host("localhost") |
| 178 | + .port(sslTunnelServer.getLocalPort()) |
| 179 | + .user(TestServerUtil.getUsername()) |
| 180 | + .password(TestServerUtil.getPassword()) |
| 181 | + .database(TestServerUtil.getDatabase()) |
| 182 | + .createDatabaseIfNotExist(true) |
| 183 | + .sslMode(SslMode.DISABLED) |
| 184 | + .serverRSAPublicKeyFile("/usr/local/mysql/data/public_key.pem") |
| 185 | + .build(); |
| 186 | + |
| 187 | + assertThat(MySqlConnectionFactory.from(configuration3).create().block()).isExactlyInstanceOf(MySqlSimpleConnection.class); |
| 188 | + } |
| 189 | + |
134 | 190 | private static class SslTunnelServer { |
135 | 191 |
|
136 | 192 | private final String remoteHost; |
|
0 commit comments