Skip to content

Commit 6554b54

Browse files
committed
refactor: inline setup_ssh_key function into environment module
The setup_ssh_key function was only used in one place (src/e2e/environment.rs), so it has been inlined into the setup_ssh_credentials method for simplicity. Changes: - Inline setup_ssh_key logic into setup_ssh_credentials method - Remove unused import and add required anyhow::Context import - Delete src/e2e/tasks/setup_ssh_key.rs module file - Update src/e2e/tasks/mod.rs to remove module reference - Maintain all original functionality including error handling and logging All tests and linters pass after refactoring.
1 parent 90329e6 commit 6554b54

File tree

3 files changed

+34
-67
lines changed

3 files changed

+34
-67
lines changed

src/e2e/environment.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
//! The environment ensures each test runs in isolation with its own
2121
//! temporary resources and configuration.
2222
23+
use anyhow::Context;
2324
use tempfile::TempDir;
2425
use tracing::{info, warn};
2526

2627
use crate::config::{Config, InstanceName, SshCredentials};
2728
use crate::container::Services;
2829

29-
use super::tasks::setup_ssh_key::setup_ssh_key;
30-
3130
/// Errors that can occur during test environment creation and initialization
3231
#[derive(Debug, thiserror::Error)]
3332
pub enum TestEnvironmentError {
@@ -288,9 +287,41 @@ impl TestEnvironment {
288287
let temp_ssh_key = temp_dir.path().join(SSH_PRIVATE_KEY_FILENAME);
289288
let temp_ssh_pub_key = temp_dir.path().join(SSH_PUBLIC_KEY_FILENAME);
290289

291-
setup_ssh_key(project_root, temp_dir)
290+
// Copy SSH private key from fixtures to temp directory
291+
let fixtures_ssh_key = project_root.join("fixtures/testing_rsa");
292+
293+
std::fs::copy(&fixtures_ssh_key, &temp_ssh_key)
294+
.context("Failed to copy SSH private key to temporary directory")
295+
.map_err(|e| TestEnvironmentError::SshKeySetupError { source: e })?;
296+
297+
// Copy SSH public key from fixtures to temp directory
298+
let fixtures_ssh_pub_key = project_root.join("fixtures/testing_rsa.pub");
299+
300+
std::fs::copy(&fixtures_ssh_pub_key, &temp_ssh_pub_key)
301+
.context("Failed to copy SSH public key to temporary directory")
292302
.map_err(|e| TestEnvironmentError::SshKeySetupError { source: e })?;
293303

304+
// Set proper permissions on the SSH key (600)
305+
#[cfg(unix)]
306+
{
307+
use std::os::unix::fs::PermissionsExt;
308+
let mut perms = std::fs::metadata(&temp_ssh_key)
309+
.context("Failed to get SSH key metadata")
310+
.map_err(|e| TestEnvironmentError::SshKeySetupError { source: e })?
311+
.permissions();
312+
perms.set_mode(0o600);
313+
std::fs::set_permissions(&temp_ssh_key, perms)
314+
.context("Failed to set SSH key permissions")
315+
.map_err(|e| TestEnvironmentError::SshKeySetupError { source: e })?;
316+
}
317+
318+
info!(
319+
operation = "ssh_key_setup",
320+
private_location = %temp_ssh_key.display(),
321+
public_location = %temp_ssh_pub_key.display(),
322+
"SSH keys copied to temporary location"
323+
);
324+
294325
Ok(SshCredentials::new(
295326
temp_ssh_key,
296327
temp_ssh_pub_key,

src/e2e/tasks/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! ### Infrastructure-agnostic tasks (can be used with both containers and VMs):
1212
//! - `run_configure_command` - Infrastructure configuration via Ansible and playbook execution
1313
//! - `run_deployment_validation` - Deployment validation and testing
14-
//! - `setup_ssh_key` - SSH key generation and setup
1514
//! - `run_test_command` - Deployment validation and testing
1615
//!
1716
//! ### Container-specific tasks (`container` submodule):
@@ -32,5 +31,4 @@ pub mod preflight_cleanup;
3231
pub mod run_configure_command;
3332
pub mod run_deployment_validation;
3433
pub mod run_test_command;
35-
pub mod setup_ssh_key;
3634
pub mod virtual_machine;

src/e2e/tasks/setup_ssh_key.rs

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)