mirror of
https://github.com/TwiN/gatus.git
synced 2026-02-14 17:32:28 +00:00
feat(client): Add ssh private-key support (#1390)
* feat(endpoint): Add ssh key support Fixes #1257 * test(config): Add tests for private key config --------- Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
@@ -511,26 +511,40 @@ func TestEndpoint_ValidateAndSetDefaultsWithSSH(t *testing.T) {
|
||||
name string
|
||||
username string
|
||||
password string
|
||||
privateKey string
|
||||
expectedErr error
|
||||
}{
|
||||
{
|
||||
name: "fail when has no user",
|
||||
name: "fail when has no user but has password",
|
||||
username: "",
|
||||
password: "password",
|
||||
expectedErr: ssh.ErrEndpointWithoutSSHUsername,
|
||||
},
|
||||
{
|
||||
name: "fail when has no password",
|
||||
username: "username",
|
||||
password: "",
|
||||
expectedErr: ssh.ErrEndpointWithoutSSHPassword,
|
||||
name: "fail when has no user but has private key",
|
||||
username: "",
|
||||
privateKey: "-----BEGIN",
|
||||
expectedErr: ssh.ErrEndpointWithoutSSHUsername,
|
||||
},
|
||||
{
|
||||
name: "success when all fields are set",
|
||||
name: "fail when has no password or private key",
|
||||
username: "username",
|
||||
password: "",
|
||||
privateKey: "",
|
||||
expectedErr: ssh.ErrEndpointWithoutSSHAuth,
|
||||
},
|
||||
{
|
||||
name: "success when username and password are set",
|
||||
username: "username",
|
||||
password: "password",
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
name: "success when username and private key are set",
|
||||
username: "username",
|
||||
privateKey: "-----BEGIN",
|
||||
expectedErr: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, scenario := range scenarios {
|
||||
@@ -539,8 +553,9 @@ func TestEndpoint_ValidateAndSetDefaultsWithSSH(t *testing.T) {
|
||||
Name: "ssh-test",
|
||||
URL: "https://example.com",
|
||||
SSHConfig: &ssh.Config{
|
||||
Username: scenario.username,
|
||||
Password: scenario.password,
|
||||
Username: scenario.username,
|
||||
Password: scenario.password,
|
||||
PrivateKey: scenario.privateKey,
|
||||
},
|
||||
Conditions: []Condition{Condition("[STATUS] == 0")},
|
||||
}
|
||||
@@ -1605,7 +1620,7 @@ func TestEndpoint_HideUIFeatures(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if tt.checkConditions {
|
||||
hasConditions := result.ConditionResults != nil && len(result.ConditionResults) > 0
|
||||
hasConditions := len(result.ConditionResults) > 0
|
||||
if hasConditions != tt.expectConditions {
|
||||
t.Errorf("Expected conditions=%v, got conditions=%v (actual: %v)", tt.expectConditions, hasConditions, result.ConditionResults)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user