-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e/standard: test for backup & restore with passphrase (#1369)
Inspired by #1309 (review), this adds tests for backup/restore with a passphrase.
- Loading branch information
Showing
4 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Install PostgreSQL Client | ||
|
||
inputs: | ||
postgres-version: | ||
type: integer | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Install postgres-client v${{ inputs.postgres-version }} | ||
shell: bash | ||
run: > | ||
sudo apt-get update && | ||
sudo apt-get --yes remove --purge 'postgres*' && | ||
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list && | ||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc && | ||
sudo apt-get update && | ||
sudo apt-get --yes install postgresql-client-${{ inputs.postgres-version }} && | ||
printf "Postgres version: $(pg_dump --version): " && | ||
([[ "$(pg_dump --version | cut -d' ' -f3)" = ${{ inputs.postgres-version }}.* ]] && echo OK) || (echo Incorrect && exit 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/bin/bash -eu | ||
set -o pipefail | ||
|
||
serverUrl=http://localhost:8383 | ||
|
||
log() { | ||
if [[ ${testname-} = "" ]]; then | ||
echo "[test/e2e/standard/backup-restore] $*" | ||
else | ||
echo "[test/e2e/standard/backup-restore] [$testname] $*" | ||
fi | ||
} | ||
|
||
backup() { | ||
local contentType="$1" | ||
local postBody="$2" | ||
|
||
backupDir="$(mktemp --directory)" | ||
cd "$backupDir" | ||
|
||
target="backup.zip" | ||
creds="$(echo -n '[email protected]:secret1234' | base64)" | ||
wget \ | ||
--header "X-Forwarded-Proto: https" \ | ||
--header "Content-Type: $contentType" \ | ||
--header="Authorization: Basic $creds" \ | ||
"$serverUrl/v1/backup" \ | ||
--post-data "$postBody" \ | ||
-O "$target" | ||
cd - | ||
} | ||
|
||
if ! curl -s -o /dev/null "$serverUrl"; then | ||
log "Backend is not running - cannot run tests." | ||
exit 1 | ||
fi | ||
|
||
testname=no-passphrase | ||
log "Testing with no passphrase supplied for backup..." | ||
backup text/plain '' | ||
log " Restoring with no passphrase..." | ||
node ./lib/bin/restore.js "$backupDir/$target" | ||
log " Restoring with explicit empty passphrase..." | ||
node ./lib/bin/restore.js "$backupDir/$target" "" | ||
log " Restoring with incorrect passphrase..." | ||
if node ./lib/bin/restore.js "$backupDir/$target" "wrong-passphrase"; then | ||
log " Incorrect passphrase should have been rejected." | ||
exit 1 | ||
fi | ||
|
||
testname=empty-passphrase | ||
log "Testing with empty passphrase supplied for backup..." | ||
backup application/json '{"passphrase":""}' | ||
log " Restoring with no passphrase..." | ||
node ./lib/bin/restore.js "$backupDir/$target" | ||
log " Restoring with explicit empty passphrase..." | ||
node ./lib/bin/restore.js "$backupDir/$target" "" | ||
log " Restoring with incorrect passphrase..." | ||
if node ./lib/bin/restore.js "$backupDir/$target" "wrong-passphrase"; then | ||
log " Incorrect passphrase should have been rejected." | ||
exit 1 | ||
fi | ||
|
||
testname=with-passphrase | ||
log "Testing with explicit passphrase supplied for backup..." | ||
backup application/json '{"passphrase":"megasecret"}' | ||
log " Restoring with correct passphrase..." | ||
node ./lib/bin/restore.js "$backupDir/$target" megasecret | ||
log " Restoring without passphrase..." | ||
if node ./lib/bin/restore.js "$backupDir/$target"; then | ||
log " Missing passphrase should have been rejected." | ||
exit 1 | ||
fi | ||
log " Restoring with empty passphrase..." | ||
if node ./lib/bin/restore.js "$backupDir/$target" ""; then | ||
log " Empty passphrase should have been rejected." | ||
exit 1 | ||
fi | ||
log " Restoring with incorrect passphrase..." | ||
if node ./lib/bin/restore.js "$backupDir/$target" "wrong-passphrase"; then | ||
log " Incorrect passphrase should have been rejected." | ||
exit 1 | ||
fi | ||
|
||
testname= | ||
|
||
log "All checks passed OK." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters