Skip to content

Commit

Permalink
fix: config type validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Dec 6, 2023
1 parent 89ccb26 commit b29111f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [5.0.5] - 2023-12-06

- Validates db config types in `canBeUsed` function


## [5.0.4] - 2023-11-10

- Adds index on `app_id_to_user_id` table to improve performance of get user by id queries
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

version = "5.0.4"
version = "5.0.5"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/supertokens/storage/mysql/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ void handleKillSignalForWhenItHappens() {
}

@Override
public boolean canBeUsed(JsonObject configJson) {
public boolean canBeUsed(JsonObject configJson) throws InvalidConfigException {
return Config.canBeUsed(configJson);
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/io/supertokens/storage/mysql/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
package io.supertokens.storage.mysql.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.gson.JsonObject;
import io.supertokens.pluginInterface.LOG_LEVEL;
import io.supertokens.pluginInterface.exceptions.InvalidConfigException;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.utils.ConfigMapper;
import io.supertokens.storage.mysql.ResourceDistributor;
import io.supertokens.storage.mysql.Start;
import io.supertokens.storage.mysql.output.Logging;
Expand Down Expand Up @@ -103,11 +105,12 @@ private MySQLConfig loadMySQLConfig(JsonObject configJson) throws IOException, I
return config;
}

public static boolean canBeUsed(JsonObject configJson) {
public static boolean canBeUsed(JsonObject configJson) throws InvalidConfigException {
try {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
MySQLConfig config = mapper.readValue(configJson.toString(), MySQLConfig.class);
MySQLConfig config = ConfigMapper.mapConfig(configJson, MySQLConfig.class);
return config.getUser() != null || config.getPassword() != null || config.getConnectionURI() != null;
} catch (InvalidConfigException e) {
throw e;
} catch (Exception e) {
return false;
}
Expand Down

0 comments on commit b29111f

Please sign in to comment.