From 9761556033c1faaae37f995ba557c47f9f3c357f Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Sat, 25 Mar 2023 12:35:11 +0200 Subject: Identify where the current code needs the dirs to exist --- Cargo.lock | 35 +++++++++++++++++++++++------------ Cargo.toml | 4 ++-- Dockerfile | 2 ++ readme.org | 1 + src/lib.rs | 2 ++ src/main.rs | 9 ++++++++- tests/server_shell.rs | 12 +++++++++++- 7 files changed, 49 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b98bff4..d2341fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,6 +182,15 @@ dependencies = [ "instant", ] +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +dependencies = [ + "num-traits", +] + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -341,12 +350,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "nix" version = "0.25.1" @@ -374,13 +377,18 @@ dependencies = [ ] [[package]] -name = "nom" -version = "7.1.3" +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + +[[package]] +name = "num-traits" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "memchr", - "minimal-lexical", + "autocfg", ] [[package]] @@ -420,8 +428,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" dependencies = [ "difflib", + "float-cmp", "itertools", + "normalize-line-endings", "predicates-core", + "regex", ] [[package]] @@ -583,8 +594,8 @@ dependencies = [ "get-port", "git2", "nix 0.26.2", - "nom", "once_cell", + "predicates", "rexpect", "rustyline", "shlex", diff --git a/Cargo.toml b/Cargo.toml index 1e98b29..be75def 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,6 @@ edition = "2021" clap = { version = "4.1.8", features = ["derive"] } git2 = { version = "0.16.1", default-features = false, features = ["vendored-libgit2"] } nix = { version = "0.26.2", default-features = false, features = ["user"] } -nom = "7.1.3" -rexpect = "0.5.0" rustyline = { version = "11.0.0", default-features = false } shlex = "1.1.0" thiserror = "1.0.38" @@ -19,8 +17,10 @@ user-info = { path = "user-info" } [dev-dependencies] anyhow = "1.0.69" assert_cmd = "2.0.8" +predicates = "2.1.5" # match the version in assert_cmd get-port = "4.0.0" once_cell = "1.17.1" tempfile = "3.4.0" +rexpect = "0.5.0" [workspace] diff --git a/Dockerfile b/Dockerfile index 7688ca1..a743200 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,8 @@ RUN sed -i /etc/ssh/sshd_config \ -e 's/#PermitEmptyPasswords.*/PermitEmptyPasswords yes/' RUN adduser --shell /usr/bin/shackle shukkie && passwd -d shukkie +RUN mkdir -p /home/shukkie/git/shukkie && chown -R shukkie:shukkie /home/shukkie/git +RUN git init --bare /home/shukkie/disallowed.git && chown -R shukkie:shukkie /home/shukkie/disallowed.git COPY . /opt/shackle ARG SHELL=target/debug/shackle diff --git a/readme.org b/readme.org index 3674200..6d1e388 100644 --- a/readme.org +++ b/readme.org @@ -38,6 +38,7 @@ Pijul. ** Post-MVP +- [ ] functions correctly when the git path isn't created yet - [ ] git archive with git upload-archive - [ ] git config management around protected branches - [ ] move a repo to a different group diff --git a/src/lib.rs b/src/lib.rs index 595e3ec..5e33302 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,4 +41,6 @@ pub enum ShackleError { UserReadError, #[error("Path is not accessible")] InvalidDirectory, + #[error("`{0}`")] + CustomError(String), } diff --git a/src/main.rs b/src/main.rs index 4333866..d7a633f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,14 @@ struct Args { command: Option, } -fn main() -> Result<(), ShackleError> { +fn main() { + if let Err(e) = main_inner() { + eprintln!("{}", e); + std::process::exit(1); + } +} + +fn main_inner() -> Result<(), ShackleError> { let args = Args::parse(); match args.command { Some(user_input) => { diff --git a/tests/server_shell.rs b/tests/server_shell.rs index 756c5a8..ea01791 100644 --- a/tests/server_shell.rs +++ b/tests/server_shell.rs @@ -219,7 +219,17 @@ fn git_clone_can_not_target_repo_outside_allowed_paths() -> Result<()> { let c = spawn_ssh_server()?; clone_git_repo(&c, "/home/shukkie/disallowed.git") .failure() - .stdout("Path is not accessible"); + .stderr(predicates::str::contains("Path is not accessible")); + + Ok(()) +} + +#[test] +fn git_clone_can_not_target_repo_outside_allowed_paths_where_path_doesnt_exist() -> Result<()> { + let c = spawn_ssh_server()?; + clone_git_repo(&c, "/home/shukkie/disallowed-doesnt-exist.git") + .failure() + .stderr(predicates::str::contains("Path is not accessible")); Ok(()) } -- cgit v1.2.3