refactor: migrate TestSudoCommand to key-based authentication

- Disable password authentication by setting PASSWORD_ACCESS to false in TestSudoCommand
- Remove the use of direct password authentication in favor of key-based authentication in TestSudoCommand

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy 2025-04-27 09:24:52 +08:00
parent ff79cee470
commit 0d02cbb190
No known key found for this signature in database

View File

@ -930,8 +930,8 @@ func TestSudoCommand(t *testing.T) {
Env: map[string]string{ Env: map[string]string{
"USER_NAME": "testuser", "USER_NAME": "testuser",
"USER_PASSWORD": "testpass", "USER_PASSWORD": "testpass",
"PASSWORD_ACCESS": "true", // Enable password authentication "PASSWORD_ACCESS": "false", // Enable password authentication
"SUDO_ACCESS": "true", // Optional: grant sudo access "SUDO_ACCESS": "true", // Optional: grant sudo access
"PUBLIC_KEY": string(pubKey), "PUBLIC_KEY": string(pubKey),
}, },
// Wait for the SSH port (2222) to be listening // Wait for the SSH port (2222) to be listening
@ -976,7 +976,6 @@ func TestSudoCommand(t *testing.T) {
Host: []string{host}, Host: []string{host},
Username: "testuser", // Use the configured username Username: "testuser", // Use the configured username
Port: port.Int(), // Use the mapped port Port: port.Int(), // Use the mapped port
Password: "testpass", // Use the configured password
KeyPath: "./tests/.ssh/id_rsa", KeyPath: "./tests/.ssh/id_rsa",
Script: []string{ Script: []string{
`sudo su - -c "whoami"`, `sudo su - -c "whoami"`,