2020import org .apache .hadoop .conf .Configuration ;
2121import org .junit .jupiter .api .AfterEach ;
2222import org .junit .jupiter .api .BeforeEach ;
23- import org .junit .jupiter .api .Disabled ;
2423import org .junit .jupiter .api .Test ;
2524import org .junit .jupiter .api .extension .ExtendWith ;
2625import org .mockito .junit .jupiter .MockitoExtension ;
4039import static org .junit .jupiter .api .Assertions .assertTrue ;
4140
4241@ ExtendWith (MockitoExtension .class )
43- @ Disabled
4442public class RangerKMSDBTest {
4543 private static final String PROPERTY_PREFIX = "ranger.ks." ;
4644 private static final String DB_DIALECT = "jpa.jdbc.dialect" ;
@@ -72,21 +70,17 @@ public class RangerKMSDBTest {
7270 public void setUp () throws Exception {
7371 conf = new Configuration ();
7472
75- // Set basic database properties required for RangerKMSDB constructor
7673 conf .set (PROPERTY_PREFIX + DB_DIALECT , "org.eclipse.persistence.platform.database.H2Platform" );
7774 conf .set (PROPERTY_PREFIX + DB_DRIVER , "org.h2.Driver" );
7875 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:h2:mem:testdb" );
7976 conf .set (PROPERTY_PREFIX + DB_USER , "test" );
8077 conf .set (PROPERTY_PREFIX + DB_PASSWORD , "test" );
8178
82- // Save original system properties
8379 originalSystemProperties = new Properties ();
8480 originalSystemProperties .putAll (System .getProperties ());
8581
86- // Create temporary files for testing
8782 createTempFiles ();
8883
89- // Get private method and field using reflection
9084 updateDBSSLURLMethod = RangerKMSDB .class .getDeclaredMethod ("updateDBSSLURL" );
9185 updateDBSSLURLMethod .setAccessible (true );
9286
@@ -96,10 +90,8 @@ public void setUp() throws Exception {
9690
9791 @ AfterEach
9892 public void tearDown () {
99- // Restore original system properties
10093 System .setProperties (originalSystemProperties );
10194
102- // Clean up temporary files
10395 cleanupTempFiles ();
10496
10597 if (rangerKMSDB != null ) {
@@ -117,25 +109,21 @@ public org.apache.ranger.kms.dao.DaoManager getDaoManager() {
117109 }
118110 };
119111
120- // Should not throw exception
121112 assertDoesNotThrow (() -> updateDBSSLURLMethod .invoke (rangerKMSDB ));
122113 }
123114
124115 @ Test
125116 public void testUpdateDBSSLURL_NoSSLEnabledProperty () throws Exception {
126- // Don't set DB_SSL_ENABLED property
127117 createRangerKMSDBWithoutSSL ();
128118
129119 String originalUrl = conf .get (PROPERTY_PREFIX + DB_URL );
130120 updateDBSSLURLMethod .invoke (rangerKMSDB );
131121
132- // URL should remain unchanged
133122 assertEquals (originalUrl , conf .get (PROPERTY_PREFIX + DB_URL ));
134123 }
135124
136125 @ Test
137126 public void testUpdateDBSSLURL_MySQLSSLEnabled_NoQueryParams () throws Exception {
138- // Setup MySQL configuration
139127 conf .set (PROPERTY_PREFIX + DB_DIALECT , "mysql" );
140128 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:mysql://localhost:3306/ranger" );
141129 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -157,7 +145,6 @@ public void testUpdateDBSSLURL_MySQLSSLEnabled_NoQueryParams() throws Exception
157145
158146 @ Test
159147 public void testUpdateDBSSLURL_MySQLSSLEnabled_WithQueryParams () throws Exception {
160- // Setup MySQL configuration with existing query parameters
161148 conf .set (PROPERTY_PREFIX + DB_DIALECT , "mysql" );
162149 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:mysql://localhost:3306/ranger?charset=utf8" );
163150 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -166,13 +153,11 @@ public void testUpdateDBSSLURL_MySQLSSLEnabled_WithQueryParams() throws Exceptio
166153 updateDBSSLURLMethod .invoke (rangerKMSDB );
167154
168155 String updatedUrl = conf .get (PROPERTY_PREFIX + DB_URL );
169- // Should not modify URL if it already has query parameters
170156 assertEquals ("jdbc:mysql://localhost:3306/ranger?charset=utf8" , updatedUrl );
171157 }
172158
173159 @ Test
174160 public void testUpdateDBSSLURL_MySQLSSLDisabled () throws Exception {
175- // Setup MySQL configuration with SSL disabled
176161 conf .set (PROPERTY_PREFIX + DB_DIALECT , "mysql" );
177162 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:mysql://localhost:3306/ranger" );
178163 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "false" );
@@ -186,7 +171,6 @@ public void testUpdateDBSSLURL_MySQLSSLDisabled() throws Exception {
186171
187172 @ Test
188173 public void testUpdateDBSSLURL_PostgreSQLSSLEnabled_WithCertificateFile () throws Exception {
189- // Setup PostgreSQL configuration
190174 conf .set (PROPERTY_PREFIX + DB_DIALECT , "postgresql" );
191175 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:postgresql://localhost:5432/ranger" );
192176 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -203,7 +187,6 @@ public void testUpdateDBSSLURL_PostgreSQLSSLEnabled_WithCertificateFile() throws
203187
204188 @ Test
205189 public void testUpdateDBSSLURL_PostgreSQLSSLEnabled_WithVerification_NoCertFile () throws Exception {
206- // Setup PostgreSQL configuration
207190 conf .set (PROPERTY_PREFIX + DB_DIALECT , "postgresql" );
208191 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:postgresql://localhost:5432/ranger" );
209192 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -220,7 +203,6 @@ public void testUpdateDBSSLURL_PostgreSQLSSLEnabled_WithVerification_NoCertFile(
220203
221204 @ Test
222205 public void testUpdateDBSSLURL_PostgreSQLSSLEnabled_NoVerification () throws Exception {
223- // Setup PostgreSQL configuration
224206 conf .set (PROPERTY_PREFIX + DB_DIALECT , "postgresql" );
225207 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:postgresql://localhost:5432/ranger" );
226208 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -237,7 +219,6 @@ public void testUpdateDBSSLURL_PostgreSQLSSLEnabled_NoVerification() throws Exce
237219
238220 @ Test
239221 public void testUpdateDBSSLURL_PostgreSQLSSLDisabled () throws Exception {
240- // Setup PostgreSQL configuration with SSL disabled
241222 conf .set (PROPERTY_PREFIX + DB_DIALECT , "postgresql" );
242223 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:postgresql://localhost:5432/ranger" );
243224 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "false" );
@@ -247,13 +228,11 @@ public void testUpdateDBSSLURL_PostgreSQLSSLDisabled() throws Exception {
247228 updateDBSSLURLMethod .invoke (rangerKMSDB );
248229
249230 String updatedUrl = conf .get (PROPERTY_PREFIX + DB_URL );
250- // PostgreSQL URL should not be modified when SSL is disabled
251231 assertEquals (originalUrl , updatedUrl );
252232 }
253233
254234 @ Test
255235 public void testUpdateDBSSLURL_OracleDatabase () throws Exception {
256- // Setup Oracle configuration (should not modify URL)
257236 conf .set (PROPERTY_PREFIX + DB_DIALECT , "oracle" );
258237 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:oracle:thin:@localhost:1521:ranger" );
259238 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -263,13 +242,11 @@ public void testUpdateDBSSLURL_OracleDatabase() throws Exception {
263242 updateDBSSLURLMethod .invoke (rangerKMSDB );
264243
265244 String updatedUrl = conf .get (PROPERTY_PREFIX + DB_URL );
266- // Oracle URL should not be modified
267245 assertEquals (originalUrl , updatedUrl );
268246 }
269247
270248 @ Test
271249 public void testUpdateDBSSLURL_KeystoreAndTruststoreSetup () throws Exception {
272- // Setup MySQL configuration with SSL verification and keystore/truststore
273250 conf .set (PROPERTY_PREFIX + DB_DIALECT , "mysql" );
274251 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:mysql://localhost:3306/ranger" );
275252 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -284,7 +261,6 @@ public void testUpdateDBSSLURL_KeystoreAndTruststoreSetup() throws Exception {
284261 createRangerKMSDBWithoutSSL ();
285262 updateDBSSLURLMethod .invoke (rangerKMSDB );
286263
287- // Verify system properties are set
288264 assertEquals (tempKeystore .getAbsolutePath (), System .getProperty ("javax.net.ssl.keyStore" ));
289265 assertEquals ("keystore-password" , System .getProperty ("javax.net.ssl.keyStorePassword" ));
290266 assertEquals (tempTruststore .getAbsolutePath (), System .getProperty ("javax.net.ssl.trustStore" ));
@@ -293,7 +269,6 @@ public void testUpdateDBSSLURL_KeystoreAndTruststoreSetup() throws Exception {
293269
294270 @ Test
295271 public void testUpdateDBSSLURL_OneWaySSL () throws Exception {
296- // Setup MySQL configuration with 1-way SSL (should not set keystore)
297272 conf .set (PROPERTY_PREFIX + DB_DIALECT , "mysql" );
298273 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:mysql://localhost:3306/ranger" );
299274 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -307,15 +282,12 @@ public void testUpdateDBSSLURL_OneWaySSL() throws Exception {
307282 createRangerKMSDBWithoutSSL ();
308283 updateDBSSLURLMethod .invoke (rangerKMSDB );
309284
310- // Verify keystore is not set for 1-way SSL
311285 assertNull (System .getProperty ("javax.net.ssl.keyStore" ));
312- // But truststore should still be set
313286 assertEquals (tempTruststore .getAbsolutePath (), System .getProperty ("javax.net.ssl.trustStore" ));
314287 }
315288
316289 @ Test
317290 public void testUpdateDBSSLURL_NonExistentKeystoreFile () throws Exception {
318- // Setup configuration with non-existent keystore file
319291 conf .set (PROPERTY_PREFIX + DB_DIALECT , "mysql" );
320292 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:mysql://localhost:3306/ranger" );
321293 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -327,13 +299,11 @@ public void testUpdateDBSSLURL_NonExistentKeystoreFile() throws Exception {
327299 createRangerKMSDBWithoutSSL ();
328300 updateDBSSLURLMethod .invoke (rangerKMSDB );
329301
330- // Should not set system property for non-existent file
331302 assertNull (System .getProperty ("javax.net.ssl.keyStore" ));
332303 }
333304
334305 @ Test
335306 public void testUpdateDBSSLURL_EmptyKeystoreProperty () throws Exception {
336- // Setup configuration with empty keystore property
337307 conf .set (PROPERTY_PREFIX + DB_DIALECT , "mysql" );
338308 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:mysql://localhost:3306/ranger" );
339309 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -344,13 +314,11 @@ public void testUpdateDBSSLURL_EmptyKeystoreProperty() throws Exception {
344314 createRangerKMSDBWithoutSSL ();
345315 updateDBSSLURLMethod .invoke (rangerKMSDB );
346316
347- // Should not set system property for empty keystore
348317 assertNull (System .getProperty ("javax.net.ssl.keyStore" ));
349318 }
350319
351320 @ Test
352321 public void testUpdateDBSSLURL_VariousBooleanValues () throws Exception {
353- // Test various boolean value formats
354322 String [] trueValues = {"true" , "TRUE" , "True" };
355323 String [] falseValues = {"false" , "FALSE" , "False" , "" , null , "invalid" };
356324
@@ -392,7 +360,6 @@ public void testUpdateDBSSLURL_VariousBooleanValues() throws Exception {
392360
393361 @ Test
394362 public void testUpdateDBSSLURL_SQLServerDatabase () throws Exception {
395- // Test SQL Server (should not modify URL for SSL)
396363 conf .set (PROPERTY_PREFIX + DB_DIALECT , "sqlserver" );
397364 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:sqlserver://localhost:1433;database=ranger" );
398365 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -402,13 +369,11 @@ public void testUpdateDBSSLURL_SQLServerDatabase() throws Exception {
402369 updateDBSSLURLMethod .invoke (rangerKMSDB );
403370
404371 String updatedUrl = conf .get (PROPERTY_PREFIX + DB_URL );
405- // SQL Server URL should not be modified
406372 assertEquals (originalUrl , updatedUrl );
407373 }
408374
409375 @ Test
410376 public void testUpdateDBSSLURL_PostgreSQLSSLRequired () throws Exception {
411- // Setup PostgreSQL configuration with SSL required
412377 conf .set (PROPERTY_PREFIX + DB_DIALECT , "postgresql" );
413378 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:postgresql://localhost:5432/ranger" );
414379 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -425,7 +390,6 @@ public void testUpdateDBSSLURL_PostgreSQLSSLRequired() throws Exception {
425390
426391 @ Test
427392 public void testUpdateDBSSLURL_ComplexScenario () throws Exception {
428- // Test complex scenario with multiple properties set
429393 conf .set (PROPERTY_PREFIX + DB_DIALECT , "mysql" );
430394 conf .set (PROPERTY_PREFIX + DB_URL , "jdbc:mysql://localhost:3306/ranger" );
431395 conf .set (PROPERTY_PREFIX + DB_SSL_ENABLED , "true" );
@@ -445,7 +409,6 @@ public void testUpdateDBSSLURL_ComplexScenario() throws Exception {
445409 assertTrue (updatedUrl .contains ("requireSSL=false" ));
446410 assertTrue (updatedUrl .contains ("verifyServerCertificate=false" ));
447411
448- // System properties should not be set when verification is false
449412 assertNull (System .getProperty ("javax.net.ssl.keyStore" ));
450413 assertNull (System .getProperty ("javax.net.ssl.trustStore" ));
451414 }
@@ -455,7 +418,6 @@ private void createTempFiles() throws IOException {
455418 tempTruststore = File .createTempFile ("test-truststore" , ".jks" );
456419 tempCertificate = File .createTempFile ("test-cert" , ".pem" );
457420
458- // Write some dummy content to make files readable
459421 Files .write (tempKeystore .toPath (), "dummy content" .getBytes ());
460422 Files .write (tempTruststore .toPath (), "dummy content" .getBytes ());
461423 Files .write (tempCertificate .toPath (), "dummy content" .getBytes ());
@@ -476,7 +438,6 @@ private void cleanupTempFiles() {
476438 private void createRangerKMSDBWithoutSSL () {
477439 try {
478440 rangerKMSDB = new RangerKMSDB (conf ) {
479- // Override to prevent actual DB connection
480441 @ Override
481442 public org .apache .ranger .kms .dao .DaoManager getDaoManager () {
482443 return null ;
0 commit comments