From 2a9824fba4456a71517480103ac00fbd4d5af49b Mon Sep 17 00:00:00 2001 From: veeso Date: Sat, 26 Oct 2024 11:31:09 +0200 Subject: [PATCH] fix: test is sync and send --- .github/workflows/coverage.yml | 7 ++----- .github/workflows/linux.yml | 13 +++++-------- CHANGELOG.md | 7 +++++++ Cargo.toml | 3 ++- README.md | 4 ++-- src/lib.rs | 4 ++-- src/ssh/commons.rs | 2 +- src/ssh/mod.rs | 12 ++++++------ src/ssh/scp.rs | 21 +++++++++++++++++++++ src/ssh/sftp.rs | 21 +++++++++++++++++++++ 10 files changed, 69 insertions(+), 25 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index b50bbc9..6784a48 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -16,15 +16,12 @@ jobs: - name: Setup containers run: docker compose -f "tests/docker-compose.yml" up -d --build - name: Setup nightly toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: toolchain: nightly override: true - name: Run tests (nightly) - uses: actions-rs/cargo@v1 - with: - command: test - args: --lib --no-default-features --features find,github-actions,with-containers --no-fail-fast + run: cargo test --lib --no-default-features --features find,github-actions,with-containers --no-fail-fast env: RUST_LOG: trace CARGO_INCREMENTAL: "0" diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 4ed4af4..22b5f47 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -15,7 +15,7 @@ jobs: run: sudo apt update && sudo apt install -y libssh2-1-dev libssl-dev - name: Setup containers run: docker compose -f "tests/docker-compose.yml" up -d --build - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable override: true @@ -24,14 +24,11 @@ jobs: run: cargo build --all-features - name: Build (unsecure) run: cargo build --no-default-features - - name: Run tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --no-default-features --features find,github-actions,with-containers --no-fail-fast - env: - RUST_LOG: trace - name: Format run: cargo fmt --all -- --check - name: Clippy run: cargo clippy --features find -- -Dwarnings + - name: Run tests + run: cargo test --all-features --features find,github-actions,with-containers + env: + RUST_LOG: trace diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b9e1e..01bde8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog - [Changelog](#changelog) + - [0.5.0](#050) - [0.4.1](#041) - [0.4.0](#040) - [0.3.1](#031) @@ -16,6 +17,12 @@ --- +## 0.5.0 + +Released on 26/102/2024 + +- `SshKeyStorage` must be `Sync` and `Send` + ## 0.4.1 Released on 07/10/2024 diff --git a/Cargo.toml b/Cargo.toml index 9a6971d..c5680e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,8 @@ license = "MIT" name = "remotefs-ssh" readme = "README.md" repository = "https://github.com/remotefs-rs/remotefs-rs-ssh" -version = "0.4.1" +version = "0.5.0" +rust-version = "1.71.1" [dependencies] chrono = "^0.4" diff --git a/README.md b/README.md index a77078a..a73a234 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@

~ Remotefs SSH client ~

Developed by @veeso

-

Current version: 0.4.1 (07/10/2024)

+

Current version: 0.5.0 (26/10/2024)

RemoteResult { // parse configuration let ssh_config = Config::try_from(opts)?; diff --git a/src/ssh/mod.rs b/src/ssh/mod.rs index 5261ad2..c354921 100644 --- a/src/ssh/mod.rs +++ b/src/ssh/mod.rs @@ -22,7 +22,7 @@ use stream::{SftpReadStream, SftpWriteStream}; // -- Ssh key storage /// This trait must be implemented in order to use ssh keys for authentication for sftp/scp. -pub trait SshKeyStorage { +pub trait SshKeyStorage: Send + Sync { /// Return RSA key path from host and username fn resolve(&self, host: &str, username: &str) -> Option; } @@ -30,14 +30,14 @@ pub trait SshKeyStorage { // -- key method /// Ssh key method. -/// Defined by `MethodType` (see ssh2 docs) and the list of supported algorithms. +/// Defined by [`MethodType`] (see ssh2 docs) and the list of supported algorithms. pub struct KeyMethod { pub(crate) method_type: MethodType, algos: Vec, } impl KeyMethod { - /// Instantiates a new `KeyMethod` + /// Instantiates a new [`KeyMethod`] pub fn new(method_type: MethodType, algos: &[String]) -> Self { Self { method_type, @@ -77,7 +77,7 @@ impl From<&[u8]> for SshAgentIdentity { impl SshAgentIdentity { /// Check if the provided public key matches the identity /// - /// If `All` is provided, this method will always return `true` + /// If [`SshAgentIdentity::All`] is provided, this method will always return `true` pub(crate) fn pubkey_matches(&self, blob: &[u8]) -> bool { match self { SshAgentIdentity::All => true, @@ -94,7 +94,7 @@ impl SshAgentIdentity { /// You may specify some options that can be in conflict (e.g. `port` and `Port` parameter in ssh configuration). /// In these cases, the resolution is performed in this order (from highest, to lower priority): /// -/// 1. SshOpts attribute (e.g. `port` or `username`) +/// 1. [`SshOpts`] attribute (e.g. `port` or `username`) /// 2. Ssh configuration /// /// This applies also to ciphers and key exchange methods. @@ -123,7 +123,7 @@ pub struct SshOpts { } impl SshOpts { - /// Initialize SshOpts. + /// Initialize [`SshOpts`]. /// You must define the host you want to connect to. /// Host may be resolved by ssh configuration, if specified. /// diff --git a/src/ssh/scp.rs b/src/ssh/scp.rs index c55076f..7e8e574 100644 --- a/src/ssh/scp.rs +++ b/src/ssh/scp.rs @@ -1447,6 +1447,27 @@ mod test { .is_err()); } + fn is_send(_send: T) {} + + fn is_sync(_sync: T) {} + + #[test] + fn test_should_be_sync() { + let client = ScpFs::new( + SshOpts::new("sftp").key_storage(Box::new(ssh_mock::MockSshKeyStorage::default())), + ); + + is_sync(client); + } + + #[test] + fn test_should_be_send() { + let client = ScpFs::new( + SshOpts::new("sftp").key_storage(Box::new(ssh_mock::MockSshKeyStorage::default())), + ); + is_send(client); + } + // -- test utils #[cfg(feature = "with-containers")] diff --git a/src/ssh/sftp.rs b/src/ssh/sftp.rs index 98139d7..0b9ca28 100644 --- a/src/ssh/sftp.rs +++ b/src/ssh/sftp.rs @@ -1234,6 +1234,27 @@ mod test { .is_err()); } + fn is_send(_send: T) {} + + fn is_sync(_sync: T) {} + + #[test] + fn test_should_be_sync() { + let client = SftpFs::new( + SshOpts::new("sftp").key_storage(Box::new(ssh_mock::MockSshKeyStorage::default())), + ); + + is_sync(client); + } + + #[test] + fn test_should_be_send() { + let client = SftpFs::new( + SshOpts::new("sftp").key_storage(Box::new(ssh_mock::MockSshKeyStorage::default())), + ); + is_send(client); + } + // -- test utils #[cfg(feature = "with-containers")]