diff options
-rw-r--r-- | .dockerignore | 5 | ||||
-rw-r--r-- | Dockerfile | 5 | ||||
-rw-r--r-- | readme.org | 10 | ||||
-rw-r--r-- | src/main.rs | 14 | ||||
-rw-r--r-- | src/parser.rs | 10 | ||||
-rw-r--r-- | tests/server_shell.rs | 22 |
6 files changed, 54 insertions, 12 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..93d2783 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +target/debug/deps +target/debug/build +target/release/deps +target/release/build
\ No newline at end of file @@ -12,12 +12,13 @@ RUN sed -i /etc/ssh/sshd_config \ -e 's/#PermitEmptyPasswords.*/PermitEmptyPasswords yes/' RUN adduser --shell /usr/bin/shackle shukkie && passwd -d shukkie +COPY . /opt/shackle ARG SHELL=target/debug/shackle -COPY ${SHELL} /usr/bin/shackle +RUN cp /opt/shackle/${SHELL} /usr/bin/shackle ENTRYPOINT service ssh start && echo "Ready" && bash -# docker build -t shackle-server --build-arg CHANNEL=release ./ +# docker build -t shackle-server --build-arg SHELL=target/debug/shackle ./ # docker run -it -p 2022:22 shackle-server # ssh -p 2022 shukkie@localhost
\ No newline at end of file @@ -18,12 +18,14 @@ Pijul. - [X] git init of private repo - [X] responds to unknown commands - [X] Isolation of workdir between tests -- [ ] git push - - git upload-pack <argument>, git upload-archive <argument> -- [ ] git fetch - - git receive-pack <argument> +- [ ] git push with git upload-pack <argument> +- [ ] extra args for git upload-pack +- [ ] git fetch with git receive-pack <argument> +- [ ] git archive with git upload-archive <argument> - [ ] git init of shared repos +- [ ] don't quit interactive shell sessions if there's an error - [ ] help command +- [ ] restrict repos to only acceptable paths - [ ] listing of repos - [ ] history (only within same session) - [ ] set repo descriptions diff --git a/src/main.rs b/src/main.rs index 142b4fc..ebbf23a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{io, io::Write}; +use std::{io, io::Write, process}; use thiserror::Error; mod git; @@ -35,6 +35,18 @@ fn main() -> Result<(), ShackleError> { git::init(&repo_name)?; // TODO should report this error differently println!("Successfully created {}.git", repo_name); } + Ok(Command::GitUploadPack(git_dir)) => { + process::Command::new("git") + .args(["upload-pack", &git_dir]) + .spawn()? + .wait()?; + } + Ok(Command::GitReceivePack(git_dir)) => { + process::Command::new("git") + .args(["receive-pack", &git_dir]) + .spawn()? + .wait()?; + } } } Ok(()) diff --git a/src/parser.rs b/src/parser.rs index 2f65180..64ebf5b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -15,6 +15,8 @@ pub enum Command { Whitespace, Exit, GitInit(String), + GitUploadPack(String), + GitReceivePack(String), } impl FromStr for Command { @@ -44,6 +46,14 @@ fn command_parser(input: &str) -> IResult<&str, Command> { ws(tuple((tag("git-init"), multispace1, not_space))), |(_, _, repo_name)| Command::GitInit(repo_name.to_owned()), ), + map( + ws(tuple((tag("git upload-pack"), multispace1, not_space))), + |(_, _, git_dir)| Command::GitUploadPack(git_dir.to_owned()), + ), + map( + ws(tuple((tag("git receive-pack"), multispace1, not_space))), + |(_, _, git_dir)| Command::GitReceivePack(git_dir.to_owned()), + ), ))(input) } diff --git a/tests/server_shell.rs b/tests/server_shell.rs index 323fe5f..3813013 100644 --- a/tests/server_shell.rs +++ b/tests/server_shell.rs @@ -1,6 +1,6 @@ use anyhow::Result; use assert_cmd::{cargo::cargo_bin, Command}; -use get_port::{tcp::TcpPort, Ops}; +use get_port::{tcp::TcpPort, Ops, Range}; use rexpect::session::{spawn_command, PtySession}; use std::{io, path, sync::Once}; use tempfile::TempDir; @@ -45,7 +45,6 @@ fn build_docker_image() -> Result<(), DockerBuildError> { let relative_shell_path = absolute_shell_path.strip_prefix(std::fs::canonicalize(".")?)?; command.args([ "build", - "--quiet", "-t", "shackle-server", "--build-arg", @@ -76,7 +75,15 @@ fn spawn_ssh_server() -> Result<TestContext> { let workdir = tempfile::tempdir()?; - let ssh_port = TcpPort::any("127.0.0.1").unwrap(); + // TODO: Put the used ports in an Arc<BTreeSet> + let ssh_port = TcpPort::in_range( + "127.0.0.1", + Range { + min: 2022, + max: 3022, + }, + ) + .unwrap(); let mut command = std::process::Command::new("docker"); command.args([ @@ -139,9 +146,14 @@ fn git_clone_works_with_an_empty_repo() -> Result<()> { make_new_repo(&c, repo_name)?; Command::new("git") - .arg("clone") - .arg(&format!("shukkie@localhost:2022:{}.git", repo_name)) + .args([ + "clone", + "-v", + "--progress", + &format!("ssh://shukkie@localhost:{}/{}.git", c.ssh_port, repo_name), + ]) .current_dir(&c.workdir) + .timeout(std::time::Duration::from_secs(3)) .assert() .success(); |