1919import static org .assertj .core .api .Assertions .assertThat ;
2020import static org .junit .jupiter .api .Assertions .assertThrows ;
2121
22- import java .time .Duration ;
23-
2422import org .junit .Assume ;
25- import org .junit .jupiter .api .BeforeAll ;
2623import org .junit .jupiter .api .Test ;
2724import org .junit .jupiter .api .extension .ExtendWith ;
2825
2926import io .asyncer .r2dbc .mysql .constant .SslMode ;
3027import io .asyncer .r2dbc .mysql .internal .util .TestContainerExtension ;
3128import io .asyncer .r2dbc .mysql .internal .util .TestServerUtil ;
3229import io .r2dbc .spi .R2dbcPermissionDeniedException ;
33- import io .r2dbc .spi .ValidationDepth ;
34- import reactor .core .publisher .Mono ;
35- import reactor .test .StepVerifier ;
3630
3731@ ExtendWith (TestContainerExtension .class )
3832public class RsaEncryptionIntegrationTest {
39-
40- @ BeforeAll
41- static void initCachingSha2Password () {
42- // If the server uses caching_sha2_password, the first time a client connects to the server, the
43- // server will require a native SSL connection. So all the SSL tunnel tests should be run after
44- // the caching_sha2_password initialization.
45-
46- MySqlConnectionConfiguration configuration = MySqlConnectionConfiguration .builder ()
47- .host (TestServerUtil .getHost ())
48- .port (TestServerUtil .getPort ())
49- .connectTimeout (Duration .ofSeconds (3 ))
50- .user (TestServerUtil .getUsername ())
51- .password (TestServerUtil .getPassword ())
52- .database (TestServerUtil .getDatabase ())
53- .createDatabaseIfNotExist (true )
54- .build ();
55-
56- MySqlConnectionFactory .from (configuration ).create ()
57- .flatMap (connection -> connection .validate (ValidationDepth .REMOTE )
58- .flatMap (it -> connection .close ().then (Mono .just (it ))))
59- .as (StepVerifier ::create )
60- .expectNext (true )
61- .verifyComplete ();
62- }
6333
6434 @ Test
6535 void sslDisabledTest () {
@@ -74,7 +44,7 @@ void sslDisabledTest() {
7444 .sslMode (SslMode .DISABLED )
7545 .build ();
7646
77- assertThrows (R2dbcPermissionDeniedException .class , () -> MySqlConnectionFactory .from (configuration ));
47+ assertThrows (R2dbcPermissionDeniedException .class , () -> MySqlConnectionFactory .from (configuration ). create () );
7848 }
7949
8050 @ Test
@@ -91,7 +61,7 @@ void sslDisabledInvalidRsaConfig() {
9161 .serverRSAPublicKeyFile ("/path/to/mysql/serverRSAPublicKey.pem" )
9262 .build ();
9363
94- assertThrows (IllegalArgumentException .class , () -> MySqlConnectionFactory .from (configuration2 ));
64+ assertThrows (IllegalArgumentException .class , () -> MySqlConnectionFactory .from (configuration2 ). create () );
9565 }
9666
9767 @ Test
@@ -108,6 +78,6 @@ void sslDisabledValidRsaConfig() {
10878 .serverRSAPublicKeyFile ("/usr/local/mysql/data/public_key.pem" )
10979 .build ();
11080
111- assertThat (MySqlConnectionFactory .from (configuration3 )). isExactlyInstanceOf (MySqlConnectionFactory .class );
81+ assertThat (MySqlConnectionFactory .from (configuration3 ). create (). block ()). isExactlyInstanceOf (MySqlSimpleConnection .class );
11282 }
11383}
0 commit comments