Skip to content

Commit

Permalink
Add column size validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jnmt committed Sep 24, 2024
1 parent b25bc82 commit b04a069
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/src/main/java/com/scalar/db/common/error/CoreError.java
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,12 @@ public enum CoreError implements ScalarDbError {
"ScalarDB Transparent Data Encryption is not enabled. To use ScalarDB Transparent Data Encryption, you must enable it. Note that this feature is supported only in the ScalarDB Enterprise edition",
"",
""),
INVALID_VARIABLE_KEY_COLUMN_SIZE(
Category.USER_ERROR,
"0144",
"The variable key column size must be greater than or equal to 64",
"",
""),

//
// Errors for the concurrency error category
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,13 @@ public JdbcConfig(DatabaseConfig databaseConfig) {
oracleVariableKeyColumnSize =
getInt(
databaseConfig.getProperties(),
MYSQL_VARIABLE_KEY_COLUMN_SIZE,
ORACLE_VARIABLE_KEY_COLUMN_SIZE,
DEFAULT_VARIABLE_KEY_COLUMN_SIZE);

if (mysqlVariableKeyColumnSize < 64 || oracleVariableKeyColumnSize < 64) {
throw new IllegalArgumentException(CoreError.INVALID_VARIABLE_KEY_COLUMN_SIZE.buildMessage());
}

if (databaseConfig.getProperties().containsKey(TABLE_METADATA_SCHEMA)) {
logger.warn(
"The configuration property \""
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/java/com/scalar/db/storage/jdbc/JdbcConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,28 @@ public void constructor_PropertiesWithTableMetadataSchemaGiven_ShouldLoadProperl
assertThat(config.getPassword().get()).isEqualTo(ANY_PASSWORD);
assertThat(config.getMetadataSchema()).isEqualTo(ANY_METADATA_SCHEMA);
}

@Test
public void
constructor_PropertiesWithSmallKeyColumnSizeGiven_ShouldThrowIllegalArgumentException() {
// Arrange
Properties props1 = new Properties();
props1.setProperty(DatabaseConfig.CONTACT_POINTS, ANY_JDBC_URL);
props1.setProperty(DatabaseConfig.USERNAME, ANY_USERNAME);
props1.setProperty(DatabaseConfig.PASSWORD, ANY_PASSWORD);
props1.setProperty(DatabaseConfig.STORAGE, JDBC_STORAGE);
props1.setProperty(JdbcConfig.MYSQL_VARIABLE_KEY_COLUMN_SIZE, "32");
Properties props2 = new Properties();
props2.setProperty(DatabaseConfig.CONTACT_POINTS, ANY_JDBC_URL);
props2.setProperty(DatabaseConfig.USERNAME, ANY_USERNAME);
props2.setProperty(DatabaseConfig.PASSWORD, ANY_PASSWORD);
props2.setProperty(DatabaseConfig.STORAGE, JDBC_STORAGE);
props2.setProperty(JdbcConfig.ORACLE_VARIABLE_KEY_COLUMN_SIZE, "32");

// Act Assert
assertThatThrownBy(() -> new JdbcConfig(new DatabaseConfig(props1)))
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> new JdbcConfig(new DatabaseConfig(props2)))
.isInstanceOf(IllegalArgumentException.class);
}
}

0 comments on commit b04a069

Please sign in to comment.