Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests #25

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,21 @@ jobs:
- uses: actions/checkout@v4
- name: Check for lints
run: cargo clippy -- -D warnings

integration:
name: Integration tests
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
include:
- os: windows-latest
windows: true
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Run integration tests
run: ./tests/sign-and-verify.sh
if: ${{ ! matrix.windows }}
- name: Run integration tests
run: ".\\tests\\sign-and-verify-win.bat"
if: ${{ matrix.windows }}
3 changes: 3 additions & 0 deletions examples/key_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[tokio::main]
#[cfg(windows)]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// This is only used for integration tests on Windows:
std::fs::File::create("server-started")?;
// ^ You can remove this line
KeyStorageAgent::new()
.listen(NamedPipeListener::new(r"\\.\pipe\agent".into())?)
.await?;
Expand Down
26 changes: 26 additions & 0 deletions tests/sign-and-verify-win.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
rem del /F /Q Cargo.toml.sig id_rsa id_rsa.pub agent.pub

cmd /c "START /b cargo run --example key_storage"

@echo off
:waitloop
IF EXIST "server-started" GOTO waitloopend
rem timeout doesn't work in github actions so introduce delay some other way
rem see https://stackoverflow.com/a/75054929
ping localhost >nul
goto waitloop
:waitloopend
@echo on

ssh-keygen -t rsa -f id_rsa -N ""
set SSH_AUTH_SOCK=\\.\pipe\agent
ssh-add id_rsa
ssh-add -L | tee agent.pub

ssh-keygen -Y sign -f agent.pub -n file < Cargo.toml > Cargo.toml.sig
if %errorlevel% neq 0 exit /b %errorlevel%

ssh-keygen -Y check-novalidate -n file -f agent.pub -s Cargo.toml.sig < Cargo.toml
if %errorlevel% neq 0 exit /b %errorlevel%

rem del /F /Q Cargo.toml.sig id_rsa id_rsa.pub agent.pub
22 changes: 22 additions & 0 deletions tests/sign-and-verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -euxo pipefail

rm -rf ssh-agent.sock Cargo.toml.sig id_rsa id_rsa.pub agent.pub

cargo run --example key_storage &

while [ ! -e ssh-agent.sock ]; do
echo "Waiting for ssh-agent.sock"
sleep 1
done

ssh-keygen -t rsa -f id_rsa -N ""
export SSH_AUTH_SOCK=ssh-agent.sock
ssh-add id_rsa
ssh-add -L | tee agent.pub
ssh-keygen -Y sign -f agent.pub -n file < Cargo.toml > Cargo.toml.sig
ssh-keygen -Y check-novalidate -n file -f agent.pub -s Cargo.toml.sig < Cargo.toml

rm -rf ssh-agent.sock Cargo.toml.sig id_rsa id_rsa.pub agent.pub

Loading