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

feat: Add tests for git-crypt compatibility and fake secrets #6

Merged
merged 10 commits into from
Nov 13, 2024
Merged
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.git* export-ignore

*.test.secrets eol=lf filter=git-crypt diff=git-crypt
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.o
git-crypt
git-crypt.exe

.vscode/*
Binary file added tests/fake.test.secrets
Binary file not shown.
Binary file added tests/key.gitcrypt
Binary file not shown.
22 changes: 21 additions & 1 deletion tests/linux/basic-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -e

REPO_HOME="$PWD"
# Export the built git-crypt binary to PATH
export PATH="$PWD:$PATH"

Expand Down Expand Up @@ -124,3 +124,23 @@ else
fi

echo "::notice:: ✅ Passed worktree test"

echo "test compatibility with git-crypt 0.7.0..."

# move to original repo
cd "$REPO_HOME"

# clean git changes
git reset --hard

git crypt unlock "./tests/key.gitcrypt"
# check if tests/fake.test.secrets is decrypted

if xxd "./tests/fake.test.secrets" | grep -q 'GITCRYPT'; then
echo "fake.test.secrets is encrypted"
exit 1
else
echo "fake.test.secrets is decrypted"
echo "::notice:: ✅ Passed 0.7.0 compatibility test"
fi

24 changes: 23 additions & 1 deletion tests/windows/basic-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $ErrorActionPreference = "Stop"
# Export the built git-crypt.exe to PATH
$env:PATH = "$PWD;" + $env:PATH

$REPO_HOME = "$PWD"
# Create a temporary directory for testing
$TEMP_DIR = [System.IO.Path]::GetTempPath()
$TEST_DIR = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
Expand Down Expand Up @@ -126,8 +127,29 @@ try {

Write-Host "::notice:: ✅ Passed worktree test"

# Test compatibility with git-crypt 0.7.0
Write-Host "Testing compatibility with git-crypt 0.7.0..."

Push-Location "$REPO_HOME"

git reset --hard

git crypt unlock ".\tests\key.gitcrypt"

# Check if the test file is properly decrypted
$testFilePath = ".\tests\fake.test.secrets"
$bytes = [System.IO.File]::ReadAllBytes($testFilePath)[0..8]
$headerString = [System.Text.Encoding]::ASCII.GetString($bytes)

if ($headerString -eq "`0GITCRYPT") {
Write-Error "fake.test.secrets is still encrypted"
exit 1
} else {
Write-Host "fake.test.secrets is decrypted"
Write-Host "::notice:: ✅ Passed 0.7.0 compatibility test"
}

} finally {
Pop-Location
Remove-Item -Recurse -Force $TEST_DIR
}

Loading