Skip to content

Commit

Permalink
fix: test is sync and send
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Oct 26, 2024
1 parent ac2533a commit 2a9824f
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 25 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

- [Changelog](#changelog)
- [0.5.0](#050)
- [0.4.1](#041)
- [0.4.0](#040)
- [0.3.1](#031)
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<p align="center">~ Remotefs SSH client ~</p>

<p align="center">Developed by <a href="https://veeso.github.io/" target="_blank">@veeso</a></p>
<p align="center">Current version: 0.4.1 (07/10/2024)</p>
<p align="center">Current version: 0.5.0 (26/10/2024)</p>

<p align="center">
<a href="https://opensource.org/licenses/MIT"
Expand Down Expand Up @@ -82,7 +82,7 @@ First of all, add `remotefs-ssh` to your project dependencies:

```toml
remotefs = "0.3"
remotefs-ssh = "^0.4"
remotefs-ssh = "^0.5"
```

these features are supported:
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//! First of all you need to add **remotefs** and the client to your project dependencies:
//!
//! ```toml
//! remotefs = "^0.2"
//! remotefs-ssh = "^0.3"
//! remotefs = "^0.3"
//! remotefs-ssh = "^0.5"
//! ```
//!
//! these features are supported:
Expand Down
2 changes: 1 addition & 1 deletion src/ssh/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::SshAgentIdentity;

// -- connect

/// Establish connection with remote server and in case of success, return the generated `Session`
/// Establish connection with remote server and in case of success, return the generated [`Session`]
pub fn connect(opts: &SshOpts) -> RemoteResult<Session> {
// parse configuration
let ssh_config = Config::try_from(opts)?;
Expand Down
12 changes: 6 additions & 6 deletions src/ssh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ 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<PathBuf>;
}

// -- 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<String>,
}

impl KeyMethod {
/// Instantiates a new `KeyMethod`
/// Instantiates a new [`KeyMethod`]
pub fn new(method_type: MethodType, algos: &[String]) -> Self {
Self {
method_type,
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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.
///
Expand Down
21 changes: 21 additions & 0 deletions src/ssh/scp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,27 @@ mod test {
.is_err());
}

fn is_send<T: Send>(_send: T) {}

fn is_sync<T: 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")]
Expand Down
21 changes: 21 additions & 0 deletions src/ssh/sftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,27 @@ mod test {
.is_err());
}

fn is_send<T: Send>(_send: T) {}

fn is_sync<T: 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")]
Expand Down

0 comments on commit 2a9824f

Please sign in to comment.