feat(ssh): Add BODY placeholder support for SSH endpoints

- Modify ExecuteSSHCommand to capture stdout output
- Update SSH endpoint handling to use needsToReadBody() mechanism
- Add comprehensive test cases for SSH BODY functionality
- Support basic body content, pattern matching, JSONPath, and functions
- Maintain backward compatibility with existing SSH endpoints
This commit is contained in:
YanSH committed 2025-09-23 09:34:33 +08:00
1 parent 5a06a74cc3
commit 25d1e1044e
3 files changed
+110 -8

No files matched your search

+87
View File
@@ -834,6 +834,93 @@ func TestIntegrationEvaluateHealthForSSH(t *testing.T) {
conditions: []Condition{Condition("[STATUS] == 1")},
success: false,
},
{
name: "ssh-body-basic",
endpoint: Endpoint{
Name: "ssh-body-basic",
URL: "ssh://localhost",
SSHConfig: &ssh.Config{
Username: "scenario",
Password: "scenario",
},
Body: "{ \"command\": \"echo 'test-output'\" }",
},
conditions: []Condition{
Condition("[STATUS] == 0"),
Condition("[BODY] == test-output"),
},
success: true,
},
{
name: "ssh-body-pattern",
endpoint: Endpoint{
Name: "ssh-body-pattern",
URL: "ssh://localhost",
SSHConfig: &ssh.Config{
Username: "scenario",
Password: "scenario",
},
Body: "{ \"command\": \"echo 'test-pattern-match'\" }",
},
conditions: []Condition{
Condition("[STATUS] == 0"),
Condition("[BODY] == pat(*pattern*)"),
},
success: true,
},
{
name: "ssh-body-json-path",
endpoint: Endpoint{
Name: "ssh-body-json",
URL: "ssh://localhost",
SSHConfig: &ssh.Config{
Username: "scenario",
Password: "scenario",
},
Body: "{ \"command\": \"echo '{\\\"status\\\": \\\"healthy\\\", \\\"memory\\\": {\\\"used\\\": 512}}'\" }",
},
conditions: []Condition{
Condition("[STATUS] == 0"),
Condition("[BODY].status == healthy"),
Condition("[BODY].memory.used > 500"),
},
success: true,
},
{
name: "ssh-body-functions",
endpoint: Endpoint{
Name: "ssh-body-functions",
URL: "ssh://localhost",
SSHConfig: &ssh.Config{
Username: "scenario",
Password: "scenario",
},
Body: "{ \"command\": \"echo -n '12345'\" }",
},
conditions: []Condition{
Condition("[STATUS] == 0"),
Condition("len([BODY]) == 5"),
Condition("has([BODY]) == true"),
},
success: true,
},
{
name: "ssh-command-fail-with-body",
endpoint: Endpoint{
Name: "ssh-command-fail-body",
URL: "ssh://localhost",
SSHConfig: &ssh.Config{
Username: "scenario",
Password: "scenario",
},
Body: "{ \"command\": \"echo 'error message'; exit 1\" }",
},
conditions: []Condition{
Condition("[STATUS] == 1"),
Condition("[BODY] == pat(*error*)"),
},
success: true,
},
}
for _, scenario := range scenarios {