Browse Source

add alert script check (#15752)

dev_wenjun_refactorMaster
caishunfeng 8 months ago committed by GitHub
parent
commit
f7358c3e5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      docs/docs/en/guide/alert/script.md
  2. 2
      docs/docs/zh/guide/alert/script.md
  3. 5
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
  4. 10
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java

10
docs/docs/en/guide/alert/script.md

@ -7,11 +7,11 @@ The following shows the `Script` configuration example:
## Parameter Configuration ## Parameter Configuration
| **Parameter** | **Description** | | **Parameter** | **Description** |
|---------------|--------------------------------------------------| |---------------|-------------------------------------------------------------|
| User Params | User defined parameters will pass to the script. | | User Params | User defined parameters will pass to the script. |
| Script Path | The file location path in the server. | | Script Path | The file location path in the server, only support .sh file |
| Type | Support `Shell` script. | | Type | Support `Shell` script. |
### Note ### Note

2
docs/docs/zh/guide/alert/script.md

@ -12,7 +12,7 @@
* 脚本路径 * 脚本路径
> 脚本在服务器上的文件位置 > 脚本在服务器上的文件位置,只支持.sh后缀的文件
* 脚本类型 * 脚本类型

5
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java

@ -69,6 +69,11 @@ public final class ScriptSender {
alertResult.setMessage("shell script not support windows os"); alertResult.setMessage("shell script not support windows os");
return alertResult; return alertResult;
} }
if (!scriptPath.endsWith(".sh")) {
alertResult.setMessage("shell script is invalid, only support .sh file");
return alertResult;
}
// validate script path in case of injections // validate script path in case of injections
File shellScriptFile = new File(scriptPath); File shellScriptFile = new File(scriptPath);
// validate existence // validate existence

10
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java

@ -79,6 +79,16 @@ public class ScriptSenderTest {
Assertions.assertEquals("false", alertResult.getStatus()); Assertions.assertEquals("false", alertResult.getStatus());
} }
@Test
public void testPathError() {
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_PATH, "/usr/sbin/abc");
ScriptSender scriptSender = new ScriptSender(scriptConfig);
AlertResult alertResult;
alertResult = scriptSender.sendScriptAlert("test path NPE", "test content");
Assertions.assertEquals("false", alertResult.getStatus());
Assertions.assertTrue(alertResult.getMessage().contains("shell script is invalid, only support .sh file"));
}
@Test @Test
public void testTypeIsError() { public void testTypeIsError() {
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_TYPE, null); scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_TYPE, null);

Loading…
Cancel
Save