Repository navigation
Expand file tree
/
Copy pathrun-python-tests-server-mode.yml
More file actions
224 lines (197 loc) · 8.68 KB
/
Copy pathrun-python-tests-server-mode.yml
File metadata and controls
224 lines (197 loc) · 8.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Run Python tests in server mode (data isolation)
# This workflow runs the data-isolation tests with SERVER_MODE=True.
# The main run-python-tests-pg.yml workflow runs everything with
# SERVER_MODE=False, so any test that gates itself on `config.SERVER_MODE`
# (notably web/pgadmin/browser/server_groups/tests/test_sg_data_isolation.py
# and web/pgadmin/browser/server_groups/servers/tests/test_server_data_isolation.py)
# skips itself in CI. That gap allowed the admin-bypass regression in
# 9a76ed8 to ship; this workflow exists so regressions to the centralized
# access-control helpers in web/pgadmin/utils/server_access.py are caught.
#
# Scope is intentionally narrow: one OS, one PG version, only the
# data-isolation modules. Keep it cheap to run on every PR.
on:
push:
branches: [ "master" ]
paths:
- 'web/**'
# Not the message catalogues: a .po change cannot break a build or a
# test, and check-translations already compiles them, which is the
# check that would catch a malformed one.
- '!web/pgadmin/translations/**'
- 'requirements.txt'
- 'Makefile'
- 'tools/setup-python-env.sh'
- '.github/workflows/run-python-tests-server-mode.yml'
pull_request:
branches: [ "master" ]
paths:
- 'web/**'
# Not the message catalogues: a .po change cannot break a build or a
# test, and check-translations already compiles them, which is the
# check that would catch a malformed one.
- '!web/pgadmin/translations/**'
- 'requirements.txt'
- 'Makefile'
- 'tools/setup-python-env.sh'
- '.github/workflows/run-python-tests-server-mode.yml'
workflow_dispatch:
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
jobs:
run-python-tests-server-mode:
runs-on: ubuntu-24.04
env:
PG_VER: 18
steps:
- uses: actions/checkout@v7
with:
# We don't run any authenticated git operations after checkout
# (no push, no submodule fetch, no comment back to the PR), so
# persisting the token in the local git config only widens the
# blast radius of an unrelated step compromise.
persist-credentials: false
- name: Update python version
uses: actions/setup-python@v7
with:
python-version: '3.10'
- name: Setup the PGDG APT repo
# apt-key is deprecated on Ubuntu 24.04+; install the key into
# /etc/apt/keyrings/ and reference it via signed-by= in the
# sources.list entry instead.
run: |
sudo install -d -m 0755 /etc/apt/keyrings
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc \
| sudo gpg --dearmor -o /etc/apt/keyrings/pgdg.gpg
sudo sh -c 'echo "deb [signed-by=/etc/apt/keyrings/pgdg.gpg] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
- name: Uninstall PostgreSQL if already present
run: |
if [ -n "$(ls /etc/postgresql/*/*/postgresql.conf 2>/dev/null)" ]; then
installed_pg_version=$( pg_config --version | cut -d ' ' -f 2 | cut -d '.' -f 1 )
echo "Installed PostgreSQL version: $installed_pg_version"
if [ $installed_pg_version != ${PG_VER} ]; then
sudo pg_dropcluster $installed_pg_version main --stop
sudo apt-get -y remove "postgresql-${installed_pg_version}"
fi
fi
- name: Install platform dependencies
run: |
sudo apt update
sudo apt install -y libpq-dev libffi-dev libssl-dev libkrb5-dev zlib1g-dev postgresql-${PG_VER}
- name: Start PostgreSQL
run: |
sudo su -c "echo local all all trust > /etc/postgresql/${PG_VER}/main/pg_hba.conf"
sudo sed -i "s/port = 543[0-9]/port = 59${PG_VER}/g" /etc/postgresql/${PG_VER}/main/postgresql.conf
sudo su - postgres -c "/usr/lib/postgresql/${PG_VER}/bin/postgres -D /var/lib/postgresql/${PG_VER}/main -c config_file=/etc/postgresql/${PG_VER}/main/postgresql.conf &"
# Bounded readiness wait: 60 attempts × 2s = 120s cap. If PG
# never becomes ready, fail fast with logs rather than hanging
# until the job timeout.
for attempt in $(seq 1 60); do
if sudo runuser -l postgres -c "pg_isready -p 59${PG_VER}" 2>/dev/null; then
break
fi
>&2 echo "Postgres is unavailable (attempt ${attempt}/60) - sleeping for 2 seconds"
sleep 2
if [ "$attempt" -eq 60 ]; then
>&2 echo "Postgres failed to become ready within 120 seconds"
sudo tail -n 200 /var/log/postgresql/postgresql-${PG_VER}-main.log || true
exit 1
fi
done
- name: Install Python dependencies
run: make install-python-testing
- name: Create the test configuration (SERVER_MODE=True)
run: |
mkdir -p var
cat <<EOF > web/config_local.py
from config import *
# Debug mode
DEBUG = True
# App mode — this is the whole point of this workflow.
SERVER_MODE = True
# Log
CONSOLE_LOG_LEVEL = DEBUG
FILE_LOG_LEVEL = DEBUG
DEFAULT_SERVER = '127.0.0.1'
UPGRADE_CHECK_ENABLED = False
LOG_FILE = "$(pwd)/var/pgadmin4.log"
SESSION_DB_PATH = "$(pwd)/var/sessions"
STORAGE_DIR = "$(pwd)/var/storage"
SQLITE_PATH = "$(pwd)/var/pgadmin4.db"
TEST_SQLITE_PATH = "$(pwd)/var/pgadmin4.db"
AZURE_CREDENTIAL_CACHE_DIR = "$(pwd)/var/azurecredentialcache"
EOF
cat <<EOF > web/regression/test_config.json
{
"pgAdmin4_login_credentials": {
"new_password": "NEWPASSWORD",
"login_password": "PASSWORD",
"login_username": "USER@EXAMPLE.COM"
},
"pgAdmin4_test_user_credentials": {
"new_password": "NEWPASSWORD",
"login_password": "PASSWORD",
"login_username": "USER2@EXAMPLE.COM"
},
"pgAdmin4_test_non_admin_credentials": {
"new_password": "NEWPASSWORD",
"login_password": "PASSWORD",
"login_username": "USER3@EXAMPLE.COM"
},
"server_group": 1,
"server_credentials": [
{
"name": "PostgreSQL ${{ env.PG_VER }}",
"comment": "PostgreSQL ${{ env.PG_VER }} Server",
"db_username": "postgres",
"host": "/var/run/postgresql",
"db_password": "postgres",
"db_port": 59${{ env.PG_VER }},
"maintenance_db": "postgres",
"sslmode": "prefer",
"tablespace_path": "/var/lib/postgresql/tablespaces/${{ env.PG_VER }}",
"enabled": true,
"default_binary_paths": {
"pg": "/usr/lib/postgresql/${{ env.PG_VER }}/bin",
"ppas": ""
}
}
],
"server_update_data": [
{
"comment": "This is test update comment"
}
]
}
EOF
- name: Run server-group data isolation tests
run: |
. venv/bin/activate
python web/regression/runtests.py --pkg browser.server_groups.tests --modules test_sg_data_isolation
- name: Run server data isolation tests
run: |
. venv/bin/activate
python web/regression/runtests.py --pkg browser.server_groups.servers.tests --modules test_server_data_isolation
- name: Run SQL Editor unauth-pickle regression test
# Regression guard for the CSRF-only-no-auth chain on
# /sqleditor/close and /sqleditor/.../update_connection: both
# endpoints reach pickle.loads via close_sqleditor_session() /
# check_transaction_status(), so they must require an
# authenticated session. This test is a no-op in DESKTOP mode
# (auto-re-authentication) so it can only run here.
run: |
. venv/bin/activate
python web/regression/runtests.py --pkg tools.sqleditor --modules test_close_requires_auth
- name: Archive server log
if: success() || failure()
uses: actions/upload-artifact@v7
with:
name: server-log-server-mode
path: var/pgadmin4.log
- name: Archive regression log
if: success() || failure()
uses: actions/upload-artifact@v7
with:
name: regression-log-server-mode
path: web/regression/regression.log