1717
1818package io .supertokens .storage .postgresql .test ;
1919
20+ import com .fasterxml .jackson .databind .ObjectMapper ;
21+ import com .fasterxml .jackson .dataformat .yaml .YAMLFactory ;
2022import com .google .gson .JsonObject ;
2123import io .supertokens .ProcessState ;
2224import io .supertokens .session .Session ;
3436import org .junit .rules .TestRule ;
3537
3638import java .io .File ;
39+ import java .io .IOException ;
3740
3841import static org .junit .Assert .assertEquals ;
3942import static org .junit .Assert .assertNotNull ;
@@ -318,10 +321,14 @@ public void testAddingSchemaWorks() throws Exception {
318321
319322 @ Test
320323 public void testValidConnectionURI () throws Exception {
324+ final ObjectMapper mapper = new ObjectMapper (new YAMLFactory ());
325+ PostgreSQLConfig userConfig = mapper .readValue (new File ("../config.yaml" ), PostgreSQLConfig .class );
326+ String hostname = userConfig .getHostName ();
321327 {
322328 String [] args = { "../" };
323329
324- Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://root:root@localhost:5432/supertokens" );
330+ Utils .setValueInConfig ("postgresql_connection_uri" ,
331+ "postgresql://root:root@" + hostname + ":5432/supertokens" );
325332 Utils .commentConfigValue ("postgresql_password" );
326333 Utils .commentConfigValue ("postgresql_user" );
327334 Utils .commentConfigValue ("postgresql_port" );
@@ -341,7 +348,7 @@ public void testValidConnectionURI() throws Exception {
341348 Utils .reset ();
342349 String [] args = { "../" };
343350
344- Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://root:root@localhost /supertokens" );
351+ Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://root:root@" + hostname + " /supertokens" );
345352 Utils .commentConfigValue ("postgresql_password" );
346353 Utils .commentConfigValue ("postgresql_user" );
347354 Utils .commentConfigValue ("postgresql_port" );
@@ -361,7 +368,7 @@ public void testValidConnectionURI() throws Exception {
361368 Utils .reset ();
362369 String [] args = { "../" };
363370
364- Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://localhost :5432/supertokens" );
371+ Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://" + hostname + " :5432/supertokens" );
365372 Utils .commentConfigValue ("postgresql_port" );
366373 Utils .commentConfigValue ("postgresql_host" );
367374 Utils .commentConfigValue ("postgresql_database_name" );
@@ -379,7 +386,7 @@ public void testValidConnectionURI() throws Exception {
379386 Utils .reset ();
380387 String [] args = { "../" };
381388
382- Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://root@localhost :5432/supertokens" );
389+ Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://root@" + hostname + " :5432/supertokens" );
383390 Utils .commentConfigValue ("postgresql_user" );
384391 Utils .commentConfigValue ("postgresql_port" );
385392 Utils .commentConfigValue ("postgresql_host" );
@@ -398,7 +405,7 @@ public void testValidConnectionURI() throws Exception {
398405 Utils .reset ();
399406 String [] args = { "../" };
400407
401- Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://root:root@localhost :5432" );
408+ Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://root:root@" + hostname + " :5432" );
402409 Utils .commentConfigValue ("postgresql_password" );
403410 Utils .commentConfigValue ("postgresql_user" );
404411 Utils .commentConfigValue ("postgresql_port" );
@@ -417,6 +424,9 @@ public void testValidConnectionURI() throws Exception {
417424
418425 @ Test
419426 public void testInvalidConnectionURI () throws Exception {
427+ final ObjectMapper mapper = new ObjectMapper (new YAMLFactory ());
428+ PostgreSQLConfig userConfig = mapper .readValue (new File ("../config.yaml" ), PostgreSQLConfig .class );
429+ String hostname = userConfig .getHostName ();
420430 {
421431 String [] args = { "../" };
422432
@@ -439,7 +449,7 @@ public void testInvalidConnectionURI() throws Exception {
439449 String [] args = { "../" };
440450
441451 Utils .setValueInConfig ("postgresql_connection_uri" ,
442- "postgresql://root:wrongPassword@localhost :5432/supertokens" );
452+ "postgresql://root:wrongPassword@" + hostname + " :5432/supertokens" );
443453 Utils .commentConfigValue ("postgresql_password" );
444454 Utils .commentConfigValue ("postgresql_user" );
445455 Utils .commentConfigValue ("postgresql_port" );
@@ -459,11 +469,14 @@ public void testInvalidConnectionURI() throws Exception {
459469
460470 @ Test
461471 public void testValidConnectionURIAttributes () throws Exception {
472+ final ObjectMapper mapper = new ObjectMapper (new YAMLFactory ());
473+ PostgreSQLConfig userConfig = mapper .readValue (new File ("../config.yaml" ), PostgreSQLConfig .class );
474+ String hostname = userConfig .getHostName ();
462475 {
463476 String [] args = { "../" };
464477
465478 Utils .setValueInConfig ("postgresql_connection_uri" ,
466- "postgresql://root:root@localhost :5432/supertokens?key1=value1" );
479+ "postgresql://root:root@" + hostname + " :5432/supertokens?key1=value1" );
467480
468481 TestingProcessManager .TestingProcess process = TestingProcessManager .start (args );
469482 assertNotNull (process .checkOrWaitForEvent (ProcessState .PROCESS_STATE .STARTED ));
@@ -478,9 +491,8 @@ public void testValidConnectionURIAttributes() throws Exception {
478491 Utils .reset ();
479492 String [] args = { "../" };
480493
481- Utils .setValueInConfig ("postgresql_connection_uri" ,
482- "postgresql://root:root@localhost:5432/supertokens?key1=value1&allowPublicKeyRetrieval=false&key2"
483- + "=value2" );
494+ Utils .setValueInConfig ("postgresql_connection_uri" , "postgresql://root:root@" + hostname
495+ + ":5432/supertokens?key1=value1&allowPublicKeyRetrieval=false&key2" + "=value2" );
484496
485497 TestingProcessManager .TestingProcess process = TestingProcessManager .start (args );
486498 assertNotNull (process .checkOrWaitForEvent (ProcessState .PROCESS_STATE .STARTED ));
@@ -492,14 +504,17 @@ public void testValidConnectionURIAttributes() throws Exception {
492504 }
493505 }
494506
495- public static void checkConfig (PostgreSQLConfig config ) {
507+ public static void checkConfig (PostgreSQLConfig config ) throws IOException {
508+ final ObjectMapper mapper = new ObjectMapper (new YAMLFactory ());
509+ PostgreSQLConfig userConfig = mapper .readValue (new File ("../config.yaml" ), PostgreSQLConfig .class );
510+ String hostname = userConfig .getHostName ();
496511 assertEquals ("Config getAttributes did not match default" , config .getConnectionAttributes (),
497512 "allowPublicKeyRetrieval=true" );
498513 assertEquals ("Config getSchema did not match default" , config .getConnectionScheme (), "postgresql" );
499514 assertEquals ("Config connectionPoolSize did not match default" , config .getConnectionPoolSize (), 10 );
500515 assertEquals ("Config databaseName does not match default" , config .getDatabaseName (), "supertokens" );
501516 assertEquals ("Config keyValue table does not match default" , config .getKeyValueTable (), "key_value" );
502- assertEquals ("Config hostName does not match default " , config .getHostName (), "localhost" );
517+ assertEquals ("Config hostName does not match default " , config .getHostName (), hostname );
503518 assertEquals ("Config port does not match default" , config .getPort (), 5432 );
504519 assertEquals ("Config sessionInfoTable does not match default" , config .getSessionInfoTable (), "session_info" );
505520 assertEquals ("Config user does not match default" , config .getUser (), "root" );
0 commit comments