Fix check value rather than key in AbstractDataSourceProcessor#checkOther (#15351)

This commit is contained in:
Wenjun Ruan 2023-12-25 10:00:07 +08:00 committed by GitHub
parent 5b6b0ceb31
commit b73194bd35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -40,7 +40,6 @@
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-task-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -92,12 +92,15 @@ public abstract class AbstractDataSourceProcessor implements DataSourceProcessor
if (MapUtils.isEmpty(other)) {
return;
}
if (!Sets.intersection(other.keySet(), POSSIBLE_MALICIOUS_KEYS).isEmpty()) {
throw new IllegalArgumentException("Other params include possible malicious keys.");
}
boolean paramsCheck = other.entrySet().stream().allMatch(p -> PARAMS_PATTER.matcher(p.getValue()).matches());
if (!paramsCheck) {
throw new IllegalArgumentException("datasource other params illegal");
for (Map.Entry<String, String> entry : other.entrySet()) {
if (!PARAMS_PATTER.matcher(entry.getKey()).matches()) {
throw new IllegalArgumentException("datasource other params: " + entry.getKey() + " illegal");
}
}
}

View File

@ -34,7 +34,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
public class TrinoDataSourceProcessorTest {
private TrinoDataSourceProcessor TrinoDatasourceProcessor = new TrinoDataSourceProcessor();
private final TrinoDataSourceProcessor TrinoDatasourceProcessor = new TrinoDataSourceProcessor();
@Test
public void testCreateConnectionParams() {
@ -92,4 +92,17 @@ public class TrinoDataSourceProcessorTest {
Assertions.assertEquals(DataSourceConstants.TRINO_VALIDATION_QUERY,
TrinoDatasourceProcessor.getValidationQuery());
}
@Test
public void testCheckDatasourceParam() {
Map<String, String> others = new HashMap<>();
others.put("SSL", "true");
others.put("SSLKeyStorePassword", "******");
others.put("SSLKeyStorePath", "/home/dolphinscheduler/trino.jks");
TrinoDataSourceParamDTO trinoDataSourceParamDTO = new TrinoDataSourceParamDTO();
trinoDataSourceParamDTO.setDatabase("dwh");
trinoDataSourceParamDTO.setHost("10.11.12.13");
trinoDataSourceParamDTO.setOther(others);
Assertions.assertDoesNotThrow(() -> TrinoDatasourceProcessor.checkDatasourceParam(trinoDataSourceParamDTO));
}
}