Skip to content

Commit

Permalink
Throw error when invalid fields
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek3255 committed Feb 23, 2024
1 parent c3673f9 commit dedf48a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/main/java/io/supertokens/storage/postgresql/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +98,6 @@
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLTransactionRollbackException;
Expand All @@ -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();
Expand Down Expand Up @@ -2788,7 +2784,7 @@ public Set<String> getValidFieldsInConfig() {
}

@Override
public ArrayList<ConfigFieldInfo> getConfigFieldsInfo() {
public ArrayList<ConfigFieldInfo> getConfigFieldsInfo() throws InvalidConfigException {
return PostgreSQLConfig.getConfigFieldsInfo();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static Set<String> getValidFields() {
return validFields;
}

public static ArrayList<ConfigFieldInfo> getConfigFieldsInfo() {
public static ArrayList<ConfigFieldInfo> getConfigFieldsInfo() throws InvalidConfigException {
ArrayList<ConfigFieldInfo> result = new ArrayList<ConfigFieldInfo>();

for (String fieldId : PostgreSQLConfig.getValidFields()) {
Expand All @@ -175,18 +175,22 @@ public static ArrayList<ConfigFieldInfo> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { "../" };
Expand Down

0 comments on commit dedf48a

Please sign in to comment.