Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix broken export-data admin command and add a test for it to CI #11078

Merged
merged 12 commits into from
Oct 18, 2021
Merged
49 changes: 49 additions & 0 deletions .ci/scripts/test_export_data_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

# Test for the export-data admin command
H-Shay marked this conversation as resolved.
Show resolved Hide resolved

set -xe
cd `dirname $0`/../..

echo "--- Install dependencies"

# Install dependencies for this test.
pip install psycopg2 coverage coverage-enable-subprocess

# Install Synapse itself. This won't update any libraries.
pip install -e .

echo "--- Generate the signing key"

# Generate the server's signing key.
python -m synapse.app.homeserver --generate-keys -c .ci/sqlite-config.yaml

echo "--- Prepare test database"

# Make sure the SQLite3 database is using the latest schema and has no pending background update.
scripts-dev/update_database --database-config .ci/sqlite-config.yaml
clokep marked this conversation as resolved.
Show resolved Hide resolved

# Create the PostgreSQL database.
.ci/scripts/postgres_exec.py "CREATE DATABASE synapse"

# Port the SQLite databse to postgres so we can check command works against both
echo "+++ Port SQLite3 databse to postgres"
scripts/synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml

# Run the export-data command on the sqlite test database
python -m synapse.app.admin_cmd -c .ci/sqlite-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
--output-directory /tmp/export_data

# Run the export-data command on postgres database
python -m synapse.app.admin_cmd -c .ci/postgres-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
--output-directory /tmp/export_data2

# Test that the output directories exist and contain the rooms directory
dir="/tmp/export_data/rooms"
dir2="/tmp/export_data2/rooms"
if [ -d "$dir" ] && [ -d "$dir2" ]; then
echo "Command successful, this test passes"
else
echo "No output directories found, this test fails"
exit 1
fi
clokep marked this conversation as resolved.
Show resolved Hide resolved
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,42 @@ jobs:
path: |
/logs/results.tap
/logs/**/*.log*
export-data:
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
needs: linting-done
runs-on: ubuntu-latest
env:
TOP: ${{ github.workspace }}
strategy:
matrix:
include:
- python-version: "3.6"
postgres-version: "9.6"

- python-version: "3.9"
postgres-version: "13"
H-Shay marked this conversation as resolved.
Show resolved Hide resolved

services:
postgres:
image: postgres:${{ matrix.postgres-version }}
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: "postgres"
POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v2
- run: sudo apt-get -qq install xmlsec1
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: .ci/scripts/test_export_data_command.sh

portdb:
if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
Expand Down
1 change: 1 addition & 0 deletions changelog.d/11078.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix broken export-data admin command and add test script checking the command to CI.
8 changes: 2 additions & 6 deletions synapse/app/admin_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,7 @@ def start(config_options):
# a full worker config.
config.worker.worker_app = "synapse.app.admin_cmd"

if (
not config.worker.worker_daemonize
and not config.worker.worker_log_file
and not config.worker.worker_log_config
):
if not config.worker.worker_daemonize and not config.worker.worker_log_config:
# Since we're meant to be run as a "command" let's not redirect stdio
# unless we've actually set log config.
config.logging.no_redirect_stdio = True
Expand Down Expand Up @@ -221,7 +217,7 @@ def start(config_options):

async def run():
with LoggingContext("command"):
_base.start(ss)
await _base.start(ss)
await args.func(ss, args)

_base.start_worker_reactor(
Expand Down
4 changes: 3 additions & 1 deletion synapse/handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ async def export_user_data(self, user_id: str, writer: "ExfiltrationWriter") ->

from_key = events[-1].internal_metadata.after

events = await filter_events_for_client(self.storage, user_id, events)
events = await filter_events_for_client(
self.storage, user_id, events, filter_send_to_client=False
)
clokep marked this conversation as resolved.
Show resolved Hide resolved

writer.write_events(room_id, events)

Expand Down