From dedf48a0861d623b36766d703bfc91f2bf9ad2dc Mon Sep 17 00:00:00 2001 From: Prateek Surana Date: Fri, 23 Feb 2024 16:57:17 +0530 Subject: [PATCH] Throw error when invalid fields --- .../io/supertokens/storage/postgresql/Start.java | 8 ++------ .../storage/postgresql/config/PostgreSQLConfig.java | 12 ++++++++---- .../postgresql/test/PostgresSQLConfigTest.java | 5 +++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/supertokens/storage/postgresql/Start.java b/src/main/java/io/supertokens/storage/postgresql/Start.java index b5c2a62e..8c245a76 100644 --- a/src/main/java/io/supertokens/storage/postgresql/Start.java +++ b/src/main/java/io/supertokens/storage/postgresql/Start.java @@ -18,8 +18,6 @@ package io.supertokens.storage.postgresql; import ch.qos.logback.classic.Logger; - -import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.zaxxer.hikari.pool.HikariPool; @@ -100,7 +98,6 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; - import java.sql.Connection; import java.sql.SQLException; import java.sql.SQLTransactionRollbackException; @@ -120,8 +117,7 @@ public class Start // SaaS. If the core is not running in SuperTokens SaaS, this array has no effect. private static String[] PROTECTED_DB_CONFIG = new String[]{"postgresql_connection_pool_size", "postgresql_connection_uri", "postgresql_host", "postgresql_port", "postgresql_user", "postgresql_password", - "postgresql_database_name", "postgresql_table_schema", "postgresql_idle_connection_timeout", - "postgresql_minimum_idle_connections"}; + "postgresql_database_name", "postgresql_table_schema"}; private static final Object appenderLock = new Object(); public static boolean silent = false; private ResourceDistributor resourceDistributor = new ResourceDistributor(); @@ -2788,7 +2784,7 @@ public Set getValidFieldsInConfig() { } @Override - public ArrayList getConfigFieldsInfo() { + public ArrayList getConfigFieldsInfo() throws InvalidConfigException { return PostgreSQLConfig.getConfigFieldsInfo(); } diff --git a/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java b/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java index 2c2dd69b..2180d9ea 100644 --- a/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java +++ b/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java @@ -159,7 +159,7 @@ public static Set getValidFields() { return validFields; } - public static ArrayList getConfigFieldsInfo() { + public static ArrayList getConfigFieldsInfo() throws InvalidConfigException { ArrayList result = new ArrayList(); for (String fieldId : PostgreSQLConfig.getValidFields()) { @@ -175,18 +175,22 @@ public static ArrayList getConfigFieldsInfo() { : ""; boolean isDifferentAcrossTenants = true; - String type = "string"; + String type = null; Class fieldType = field.getType(); - if (fieldType == java.lang.String.class || fieldType == char.class) { + if (fieldType == String.class) { type = "string"; } else if (fieldType == boolean.class) { type = "boolean"; - } else if (fieldType == byte.class || fieldType == short.class || fieldType == int.class || fieldType == long.class || fieldType == float.class || fieldType == double.class) { + } else if (fieldType == int.class || fieldType == long.class || fieldType == Integer.class) { type = "number"; } + if (type == null) { + throw new InvalidConfigException("Unsupported field type: " + fieldType.getName()); + } + result.add(new ConfigFieldInfo(name, description, isDifferentAcrossTenants, type)); } catch (NoSuchFieldException e) { diff --git a/src/test/java/io/supertokens/storage/postgresql/test/PostgresSQLConfigTest.java b/src/test/java/io/supertokens/storage/postgresql/test/PostgresSQLConfigTest.java index 09b3d3ec..ee23eb0e 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/PostgresSQLConfigTest.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/PostgresSQLConfigTest.java @@ -54,6 +54,11 @@ public void beforeEach() { Utils.reset(); } + @Test + public void testAllConfigAreReturnedCorrectly() throws Exception { + PostgreSQLConfig.getConfigFieldsInfo(); + } + @Test public void testMatchConfigPropertiesDescription() throws Exception { String[] args = { "../" };