From f378cc7c955da6eb028f7a662a343e20085fbc6a Mon Sep 17 00:00:00 2001 From: PeterTheOne Date: Sun, 1 Nov 2026 02:47:07 +0100 Subject: [PATCH 1/8] getusers.php: member list as JSON over the internal TLS listener (sync v2) The member list now comes from the membership system's members.php (PPOE/admidio-addons) instead of the encrypted adm_names.php of the old, shut-down membership system. Settings in the new configuration file sync-secrets.php (release root, like constants.php): members_url (https only), members_token (Authorization: Bearer) and members_cafile, the only trust anchor (verify_peer and verify_peer_name on, no redirects, 20 s timeout, HTTP 200 required). The whole document is validated (a non-empty list of rows with exactly id, uuid, name, lo, paid; positive ids, UUIDs, no id or uuid twice); anything else fails closed as before. ppmembers stores the uuid. mb.php links profiles by user_uuid (validated as a UUID before it goes into the href); closed.php and new.php show the member id as text. membership_decrypt() is removed. deploy/: pgacc_members_url, pgacc_members_token, pgacc_members_cert (empty by default) fill shared/sync-secrets.php (root:pgacc 0640) and /etc/pgacc/members-tls.crt; pgacc-deploy links sync-secrets.php and refuses archives that contain one. Tests: the membership stub serves JSON and requires the token; new GetUsersTest cases for the refused fetches (certificate, name, cafile only, 500, redirect, 403), every kind of malformed list, the settings, the UUID check and the links; http-import checks the links on the member-fee page, the ledger and the voucher form (red against the old pages). The reference is re-recorded for the links and the stub path. Co-Authored-By: Claude Opus 5.5 --- .dockerignore | 1 + .gitignore | 1 + CHANGELOG.md | 19 ++ README.md | 12 +- UPGRADING.md | 40 +++ closed.php | 6 +- compose.dev.yaml | 5 +- compose.test.yaml | 15 +- deploy/README.md | 61 +++- deploy/ansible/inventory.example.yml | 9 +- deploy/ansible/playbook.yml | 65 +++- deploy/deploy.sh | 8 +- functions.php | 8 +- getusers.php | 182 ++++++----- mb.php | 16 +- new.php | 2 +- scripts/release.sh | 2 +- tests/README.md | 33 +- tests/coverage/merge.php | 4 +- tests/fixtures/mcrypt/generate-vectors.php | 32 -- tests/fixtures/mcrypt/vectors.json | 30 -- tests/http-import.php | 27 +- tests/http-receipts.php | 7 +- tests/mutation/README.md | 2 +- tests/mutation/targets/import-checks.php | 78 ++++- tests/mutation/targets/listing-columns.php | 2 +- tests/mutation/targets/output-escaping.php | 8 +- tests/mutation/targets/receipt-crypto.php | 17 +- tests/mutation/targets/sql-injection.php | 4 +- tests/php-runtime.Dockerfile | 6 +- tests/reference/compose.yaml | 2 +- tests/reference/membership/adm_names.b64 | 1 - tests/reference/membership/adm_names.tsv | 35 --- tests/reference/membership/flow.json | 34 ++ tests/reference/membership/flow.tsv | 34 -- tests/reference/membership/generate.php | 32 -- tests/reference/membership/members.json | 37 +++ tests/reference/membership/server.php | 137 ++++---- .../php85/http/edit-view-with-receipt.txt | 4 +- tests/reference/php85/http/mb-admin.txt | 28 +- tests/reference/php85/membership-stub.txt | 20 +- .../php85/sql/import-bawag-again.sql | 4 +- tests/reference/php85/sql/import-bawag.sql | 4 +- .../php85/sql/import-form-unitone.sql | 4 +- tests/reference/php85/sql/import-form.sql | 4 +- .../php85/sql/import-latin9-handkassa.sql | 4 +- tests/reference/php85/sql/import-paypal.sql | 4 +- .../php85/sql/import-rejected-files.sql | 4 +- .../reference/php85/sql/import-sparkasse.sql | 4 +- .../php85/sql/import-unknown-account.sql | 4 +- tests/reference/php85/sql/mb-admin.sql | 4 +- .../reference/runtime/reference-constants.php | 5 +- tests/release-vendor-check.php | 10 - tests/runtime/test-constants.php | 4 +- tests/runtime/test-sync-secrets.php | 13 + tests/unit/CryptoTest.php | 20 +- tests/unit/GetUsersTest.php | 297 +++++++++++------- tests/unit/ImportMemberMatchTest.php | 22 +- tests/unit/MembershipStub.php | 11 + 59 files changed, 868 insertions(+), 620 deletions(-) delete mode 100644 tests/reference/membership/adm_names.b64 delete mode 100644 tests/reference/membership/adm_names.tsv create mode 100644 tests/reference/membership/flow.json delete mode 100644 tests/reference/membership/flow.tsv delete mode 100644 tests/reference/membership/generate.php create mode 100644 tests/reference/membership/members.json create mode 100644 tests/runtime/test-sync-secrets.php diff --git a/.dockerignore b/.dockerignore index 2131a370..f615e9a3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ .git .github constants.php +sync-secrets.php files proxy vendor diff --git a/.gitignore b/.gitignore index e1517ec0..a7c3e3ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ constants.php +/sync-secrets.php vendor/ build/ tests/mutation/results/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d3f789a..e2a1144e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,25 @@ on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Changed +- **Behaviour change**: the member list (`getusers.php`; the member-fee page, + the bank import, saving a member voucher) comes from the membership + system's `members.php` as JSON over its internal TLS listener instead of + the encrypted `adm_names.php` of the old membership system. New + configuration file `sync-secrets.php` (release root, like + `constants.php`) with `members_url` (https only), `members_token` (sent as + `Authorization: Bearer`) and `members_cafile` (the only trust anchor); + with `deploy/` the variables `pgacc_members_url`, `pgacc_members_token` + and `pgacc_members_cert` (empty by default, so the member list is off and + those pages fail with "Mitgliederliste nicht konfiguriert!"), and + `pgacc-deploy` links `shared/sync-secrets.php` into each release. The + fetch requires a verified certificate, no redirect and HTTP 200, and + refuses the whole list if a row is malformed or a member id or uuid + appears twice (fail closed as before). The member list stores each + member's uuid; the member-fee page links profiles by `user_uuid`, the + ledger listing and the voucher form show the member id as text instead of + a link. `membership_decrypt()` is removed. See + [UPGRADING.md](UPGRADING.md), "Member list from the membership system". + - **Deployment change** (for the next major release): the web server's document root is now `public/` of the release, not the release root ([UPGRADING.md](UPGRADING.md), "Document root `public/`"; issue #80). diff --git a/README.md b/README.md index 509b45b8..aa93eb81 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,10 @@ Core concepts: - **Public reports**: annual report (Rechenschaftsbericht), transactions and spendings pages, donation lists. - **Import**: bank statement CSV import (BAWAG format). -- **Membership integration**: `getusers.php` fetches member names from the - membership system, `mbapi.php` exports membership payments. +- **Membership integration**: `getusers.php` fetches the member list from + the membership system as JSON over its internal TLS listener with a token + (settings in `sync-secrets.php`, [deploy/README.md](deploy/README.md), + "Member list"); `mbapi.php` exports membership payments. ## Requirements @@ -53,7 +55,7 @@ Provisioning a Debian 13 host and deploying releases with scripts: ```php 'https://192.0.2.20:8443/members.php', // https only + 'members_token' => '<64 hex characters, the same as on the membership system>', + 'members_cafile' => '/etc/pgacc/members-tls.crt', // its certificate, the only trust anchor +]; +``` + +- Without them the pages that need the list stop with "Mitgliederliste + nicht konfiguriert!" (fail closed, as for any failed fetch). +- The fetch verifies the certificate and its name or address against + `members_cafile` only, sends `Authorization: Bearer `, follows no + redirects, times out after 20 seconds and needs HTTP 200. The list must be + valid as a whole (`[{"id": int, "uuid": string, "name": string, "lo": + int|null, "paid": 0|1}]`, exactly these fields, a positive id and a UUID + per member, none twice); otherwise "Daten von Mitgliederverwaltung + ungültig!" and nothing is loaded. Names are UTF-8 as sent (no more + ISO-8859-15 conversion or backslash unescaping). `lo` is mapped to the + organizations as before (44 and unknown roles or none: 10). +- The member list now also holds each member's `uuid`. The member-fee page + links a member's profile by `user_uuid` (the membership system opens + profiles by uuid only); the ledger listing and the voucher form show the + member id as plain text instead of a link. +- `$datakey` in `constants.php` is now used only by the membership export + `mbapi.php`. + ## Document root `public/` (deployment change) This release changes how pgacc is deployed; it is meant for a major release. diff --git a/closed.php b/closed.php index 2de0f695..1151ce60 100644 --- a/closed.php +++ b/closed.php @@ -262,11 +262,7 @@ function page_listing_line($line, $action = "edit") if (listing_column_hidden($tabc++)) { echo emptytag("td"); } else { - if ($make_csv) { - echo tag("td", $line["member"] == 't' ? $line["member_id"] : 'Nein'); - } else { - echo tag_raw("td", $line["member"] == 't' ? '' . $line["member_id"] . '' : 'Nein'); - } + echo tag("td", $line["member"] == 't' ? $line["member_id"] : 'Nein'); } if (listing_column_hidden($tabc++)) { echo emptytag("td"); diff --git a/compose.dev.yaml b/compose.dev.yaml index abf9bd05..1aad14e1 100644 --- a/compose.dev.yaml +++ b/compose.dev.yaml @@ -9,7 +9,8 @@ # directories vendor/ and files/ when they are missing. constants.php is not # mounted (its mount point would be an empty file in the checkout): the # include_path of tests/dev/php.ini resolves "constants.php" to the test -# constants first, so a local constants.php is never read. +# constants first, so a local constants.php is never read (likewise +# "sync-secrets.php", tests/runtime/test-sync-secrets.php). services: # Copies the image's vendor/ into the dev-vendor volume on every # "tests/dev.sh up", so it always matches the image. @@ -38,6 +39,7 @@ services: - dev-vendor:/app/vendor:ro - ./tests/dev/php.ini:/usr/local/etc/php/conf.d/zz-pgacc-dev.ini:ro - ./tests/runtime/test-constants.php:/opt/pgacc-dev/constants.php:ro + - ./tests/runtime/test-sync-secrets.php:/opt/pgacc-dev/sync-secrets.php:ro # Long-running test client: tests/dev.sh runs the tests in it with # "docker compose exec" (no container start per test). @@ -48,6 +50,7 @@ services: - dev-vendor:/app/vendor:ro - ./tests/dev/php.ini:/usr/local/etc/php/conf.d/zz-pgacc-dev.ini:ro - ./tests/runtime/test-constants.php:/opt/pgacc-dev/constants.php:ro + - ./tests/runtime/test-sync-secrets.php:/opt/pgacc-dev/sync-secrets.php:ro volumes: dev-vendor: {} diff --git a/compose.test.yaml b/compose.test.yaml index 28df6d83..8eef343f 100644 --- a/compose.test.yaml +++ b/compose.test.yaml @@ -57,13 +57,14 @@ services: working_dir: /app # Local membership-system stub (tests/reference/membership/): getusers() - # fetches https://mitglieder.piratenpartei.at/adm_api/adm_names.php, which - # this alias resolves to inside the internal test network, so the import - # and member pages never reach the real service. Serves the synthetic, - # encrypted member list for tests/runtime/test-constants.php's $datakey over - # HTTPS with the synthetic certificate of the application image, whose test - # CA that image trusts (tests/php-runtime.Dockerfile). The image is built - # with the application service. + # fetches the members_url of tests/runtime/test-sync-secrets.php + # (https://mitglieder.piratenpartei.at/members.php), which this alias + # resolves to inside the internal test network, so the import and member + # pages never reach a real service. Serves the synthetic JSON member list + # for that file's members_token over HTTPS with the synthetic certificate + # of the application image, signed by the test CA that is the file's + # members_cafile (tests/php-runtime.Dockerfile). The image is built with + # the application service. membership: image: pgacc-test-application${PGACC_TEST_SUFFIX:-} pull_policy: never diff --git a/deploy/README.md b/deploy/README.md index 12c7d946..8bf1c310 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -47,6 +47,9 @@ Settings (inventory variables, see | `pgacc_backup_keep_days` | `7` | Days the nightly dumps are kept. | | `pgacc_disable_sshd` | `true` | Stops and disables the SSH server (`ssh.service`, `ssh.socket`): the host is administered through the container runtime. Set it to `false` if Ansible connects over SSH to the host itself. | | `pgacc_extra_hosts` | `[]` | Entries for `/etc/hosts` (list of `{ip, names}`), kept in a block marked by Ansible; see "Membership system". Nothing is written while the list is empty. | +| `pgacc_members_url` | `''` (off) | URL of the membership system's member list (`https://:/members.php`; see "Member list"). Empty: no member list, so the member-fee page, the bank import and saving member vouchers fail with "Mitgliederliste nicht konfiguriert!". | +| `pgacc_members_token` | `''` | The token for that URL (64 hex characters, `openssl rand -hex 32`, the same as on the membership system); required with `pgacc_members_url`. Keep it in a vault. | +| `pgacc_members_cert` | `''` | The membership system's listener certificate (PEM), written to `/etc/pgacc/members-tls.crt`: the only trust anchor of the fetch; required with `pgacc_members_url`. | | `pgacc_fresh_install` | `false` | Pass `-e pgacc_fresh_install=true` once to create the database (see below). | Defaults: time zone UTC and dumps kept 7 days (the settings above); uploads @@ -60,6 +63,7 @@ What it sets up: | Users | `pgacc` runs PHP (the PHP-FPM pool) and is the database role. `pgacc-deploy` owns the releases and may run `systemctl reload php8.5-fpm.service` with sudo, nothing else. Both are system users without a login shell. | | Layout | `/srv/pgacc/releases/v/` and the symlink `/srv/pgacc/current` belong to `pgacc-deploy`; PHP can read them but not write. `/srv/pgacc/shared/files/` (receipts) belongs to `pgacc` (mode 0700). `/srv/pgacc/shared/constants.php` is `root:pgacc` 0640: PHP reads it, nobody but root writes it. PHP errors go to `/var/log/pgacc/php-error.log` (rotated weekly). | | `constants.php` | Created only if there is none, with a random `$key` and a random placeholder `$datakey` (replace it with the key shared with the membership system). The playbook prints a notice when it creates one. An existing file is never changed (only its owner and mode). | +| Sync settings | `/srv/pgacc/shared/sync-secrets.php` (`root:pgacc` 0640), created if there is none; on every run its member list settings are set from `pgacc_members_url` and `pgacc_members_token` (`members_cafile`: `/etc/pgacc/members-tls.crt` from `pgacc_members_cert`; all empty while `pgacc_members_url` is empty, and the certificate removed). | | PHP-FPM | Pool `pgacc` (socket `/run/php/pgacc-fpm.sock`, `display_errors` off, errors logged); Debian's default pool `www` is removed. `90-pgacc.ini`: `expose_php` off, `cgi.fix_pathinfo=0`, time zone, 20M uploads, 256M memory. `allow_url_fopen` stays on (Debian's default): `getusers.php` fetches the member list over HTTPS. Reloaded only when this configuration changes. | | nginx | Port 80, `server_name _`, document root `/srv/pgacc/current/public` (only `public/` is served; the code, `constants.php` and `files/` are in the release root, see [UPGRADING.md](../UPGRADING.md), "Document root `public/`"), PHP with the resolved release path (`$realpath_root`) and `SERVER_NAME` set to the request's `Host` (the proxy must pass the public host name; `index.php` redirects to it). The short page addresses the application links to (`/donations`, `/kdonations`, `/spendings`, `/wk`, `/transactions`, `/vreport`, `/tinyreport`, each with an optional query string) are rewritten to `index.php?action=`. Only the trusted proxies and the host itself may connect, so `X-Forwarded-Proto` is trusted only from them. Allow list: only `/`, `index.php`, `mbapi.php`, `style.css`, `js/*.js`, `icons/*.png` and the short page addresses are served, anything else answers 404; as a second line of defence dot files and backup, editor and dump copies (names ending in `~`, `.bak`, `.orig`, `.save`, `.swp`, `.sql`, `.tar.gz` and the like, or with something after `.php`, such as `constants.php.bak`) answer 403. Caching: the static files (`style.css`, `js/*.js`, `icons/*.png`) get `Cache-Control: no-cache`, so browsers revalidate them on every use (ETag/`Last-Modified`, a 304 if unchanged) and pick up a deploy on the next page view; the asset URLs are not versioned yet. PHP responses get `Cache-Control: private, no-store` unless the application sets its own Cache-Control, which is kept (the application sets none at present); pages after login hold personal and financial data. The default site is disabled. | | Database | PostgreSQL 18 with the `en_US.UTF-8` locale generated (the collation of the existing installation). A normal run never creates or changes a database. Only with `-e pgacc_fresh_install=true`: role `pgacc` (peer authentication over the local socket, no password) and the database `accounting` owned by it (UTF-8, `en_US.UTF-8`), with `pgcrypto` and [tests/fixtures/schema.sql](../tests/fixtures/schema.sql); `CONNECT` revoked from `PUBLIC`. It refuses if `accounting` exists already, with or without tables. | @@ -202,10 +206,11 @@ runtime), give the full path, as the `PATH` there may not include download is intact, not who built it.** Signed archives or build attestations are a later step. 3. The archive may only contain files and directories under - `pgacc-/`, no `..`, and no `constants.php` or `files/`, and must - have `public/index.php` and `vendor/autoload.php`. It is unpacked into - `releases/v/`, with `constants.php` and `files` linked to - `shared/` in the release root (outside the document root `public/`). + `pgacc-/`, no `..`, and no `constants.php`, `sync-secrets.php` or + `files/`, and must have `public/index.php` and `vendor/autoload.php`. It + is unpacked into `releases/v/`, with `constants.php`, + `sync-secrets.php` and `files` linked to `shared/` in the release root + (outside the document root `public/`). 4. Database migrations: none. pgacc has no migration mechanism; the database or configuration steps of a release are in [UPGRADING.md](../UPGRADING.md) and are done by hand. @@ -231,23 +236,48 @@ change) is refused, see [UPGRADING.md](../UPGRADING.md), "Document root ## Membership system -pgacc fetches the member list from the membership system over verified HTTPS -(the fixed URL in `getusers.php`), and the membership system calls pgacc's -`mbapi.php`. So the host must resolve the membership system's public name and -reach it over HTTPS with a certificate valid for that name (Debian's CA -bundle), and the membership system must resolve pgacc's public name and reach -it. +pgacc fetches the member list from the membership system's internal +listener (below), and the membership system calls pgacc's `mbapi.php`, so +the membership system must resolve pgacc's public name and reach it. -If the internal DNS does not resolve the public name and the public address -is not reachable from inside (no hairpin NAT), point the name at the reverse -proxy in `/etc/hosts` with `pgacc_extra_hosts` and allow outgoing HTTPS from -the host to the proxy: +`pgacc_extra_hosts` adds `/etc/hosts` entries for names the internal DNS +does not resolve (e.g. pgacc's own public name, pointed at the reverse +proxy): ```yaml pgacc_extra_hosts: - { ip: 192.0.2.1, names: [members.example.org] } ``` +### Member list (`getusers.php`) + +The member-fee page, the bank import and saving a voucher with a member part +load the member list from the membership system's `members.php` over its +internal TLS listener +(`[{"id": int, "uuid": string, "name": string, "lo": int|null, "paid": 0|1}]`). +The public name resolves to the proxy, so the URL uses the membership +system's internal address, for which its certificate is made. Settings in +the inventory (the token in a vault): + +```yaml +pgacc_members_url: https://192.0.2.20:8443/members.php # its internal address +pgacc_members_token: "<64 hex characters, the same as on the membership system>" +pgacc_members_cert: | # its listener certificate + -----BEGIN CERTIFICATE----- + ... + -----END CERTIFICATE----- +``` + +`getusers.php` sends `Authorization: Bearer `, verifies the +certificate and its name or address against `members_cafile` only (not the +system's CAs), follows no redirects, waits at most 20 seconds and accepts +only HTTP 200 with a valid list: every row with exactly these fields, a +positive id and a UUID that no other row has. Otherwise the list is not +loaded and the page stops with an error (fail closed); without the settings +the error is "Mitgliederliste nicht konfiguriert!". A new token: set the new +`pgacc_members_token` here and on the membership system in the same run. +Allow outgoing TCP to the membership system's port in the firewall. + ## Staging A staging host must not call the live membership system and must use @@ -256,5 +286,4 @@ synthetic data only. ## Fixed in the code The database name (`pg_connect("dbname=accounting")` in `index.php` and -`mbapi.php`) and the membership URL (`getusers.php`) are fixed in the code, -so they are not settings here. +`mbapi.php`) is fixed in the code, so it is not a setting here. diff --git a/deploy/ansible/inventory.example.yml b/deploy/ansible/inventory.example.yml index 1038a14e..875581ee 100644 --- a/deploy/ansible/inventory.example.yml +++ b/deploy/ansible/inventory.example.yml @@ -27,8 +27,13 @@ all: # pgacc_timezone: UTC # pgacc_backup_keep_days: 7 # pgacc_disable_sshd: true - # /etc/hosts entries, e.g. when the internal DNS does not resolve the - # membership system's public name: point it at the reverse proxy (see + # /etc/hosts entries for names the internal DNS does not resolve (see # README.md, "Membership system"). Empty by default: nothing is written. # pgacc_extra_hosts: # - { ip: 192.0.2.1, names: [members.example.org] } + # The member list of the membership system (README.md, "Member list"). + # Off while pgacc_members_url is empty (the default); keep the token in + # a vault. + # pgacc_members_url: https://192.0.2.20:8443/members.php + # pgacc_members_token: "{{ vault_pgacc_members_token }}" + # pgacc_members_cert: "{{ lookup('ansible.builtin.file', 'members-tls.crt') }}" diff --git a/deploy/ansible/playbook.yml b/deploy/ansible/playbook.yml index 6b0f8e7e..d430f643 100644 --- a/deploy/ansible/playbook.yml +++ b/deploy/ansible/playbook.yml @@ -50,11 +50,15 @@ - pgacc_backup_keep_days | default(7) | int > 0 - pgacc_extra_hosts | default([]) | rejectattr('ip', 'defined') | list | length == 0 - pgacc_extra_hosts | default([]) | rejectattr('names', 'defined') | list | length == 0 + - pgacc_members_url | default('') == '' or pgacc_members_url is match('^https://[A-Za-z0-9.:/_-]+$') + - pgacc_members_url | default('') == '' or pgacc_members_token | default('') is match('^[0-9a-f]{64}$') + - pgacc_members_url | default('') == '' or 'BEGIN CERTIFICATE' in pgacc_members_cert | default('') fail_msg: >- Needs Debian 13 and pgacc_trusted_proxies: the addresses or CIDR ranges of the TLS-terminating reverse proxy (X-Forwarded-Proto is trusted only from them). pgacc_extra_hosts entries need ip and - names. + names. pgacc_members_url: empty or an https:// URL, then + pgacc_members_token (64 hex characters) and pgacc_members_cert (PEM). # --- Packages: PostgreSQL from apt.postgresql.org, PHP from packages.sury.org @@ -191,6 +195,65 @@ group: pgacc mode: "0640" + # --- Sync settings (deploy/README.md, "Membership system"): + # sync-secrets.php holds the member list settings of getusers.php; it is + # linked into each release like constants.php. The settings come from the + # inventory on every run. + + - name: Create the configuration directory + ansible.builtin.file: + path: /etc/pgacc + state: directory + mode: "0755" + + - name: Create sync-secrets.php if there is none + ansible.builtin.shell: | + set -eu + umask 077 + printf '%s\n' ' ''," " 'members_token' => ''," " 'members_cafile' => ''," \ + '];' >/srv/pgacc/shared/sync-secrets.php.new + mv /srv/pgacc/shared/sync-secrets.php.new /srv/pgacc/shared/sync-secrets.php + args: + creates: /srv/pgacc/shared/sync-secrets.php + + # The certificate of the membership system's internal listener: the only + # trust anchor of getusers.php (members_cafile). + - name: Install the certificate of the membership system (pgacc_members_cert) + ansible.builtin.copy: + dest: /etc/pgacc/members-tls.crt + content: "{{ pgacc_members_cert }}" + mode: "0644" + when: pgacc_members_url | default('') != '' + + - name: Remove the certificate of the membership system while the member list is off + ansible.builtin.file: + path: /etc/pgacc/members-tls.crt + state: absent + when: pgacc_members_url | default('') == '' + + - name: Set the member list settings in sync-secrets.php + ansible.builtin.lineinfile: + path: /srv/pgacc/shared/sync-secrets.php + regexp: "^ '{{ item.key }}' => " + line: " '{{ item.key }}' => {{ item.value }}," + insertbefore: '^\];$' + # Only in check mode, where the file may not exist yet. + create: true + owner: root + group: pgacc + mode: "0640" + loop: + - { key: members_url, value: "'{{ pgacc_members_url | default('') }}'" } + - { key: members_token, value: "'{{ pgacc_members_token | default('') if pgacc_members_url | default('') != '' else '' }}'" } + - { key: members_cafile, value: "'{{ '/etc/pgacc/members-tls.crt' if pgacc_members_url | default('') != '' else '' }}'" } + loop_control: + label: "{{ item.key }}" + no_log: true + # --- PHP-FPM, nginx, deploy command - name: Configure PHP diff --git a/deploy/deploy.sh b/deploy/deploy.sh index ce56e6e9..07a771ef 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -91,15 +91,17 @@ if [ ! -d "$release" ]; then die "the .sha256 file must have one line for $name.tar.gz" (cd "$work" && sha256sum -c --strict --quiet "$name.tar.gz.sha256") || die "checksum mismatch" - # Only files and directories, all under $name/, no "..", no constants.php or files/. + # Only files and directories, all under $name/, no "..", no constants.php, sync-secrets.php or files/. tar -tvzf "$archive" | cut -c1 | grep -qv '^[-d]$' && die "the archive has entries other than files and directories" tar -tzf "$archive" | awk -v p="$name/" 'index($0, p) != 1 || /(^|\/)\.\.(\/|$)/ || $0 == p "constants.php" || - $0 == p "files" || index($0, p "files/") == 1 { bad = 1 } END { exit !bad }' && - die "the archive has entries outside $name/, with '..', or a constants.php or files/" + $0 == p "sync-secrets.php" || $0 == p "files" || index($0, p "files/") == 1 { bad = 1 } END { exit !bad }' && + die "the archive has entries outside $name/, with '..', or a constants.php, sync-secrets.php or files/" tar -xzf "$archive" -C "$work" --no-same-owner --no-same-permissions [ -f "$work/$name/public/index.php" ] && [ -f "$work/$name/vendor/autoload.php" ] || die "the archive has no public/index.php or vendor/autoload.php" ln -s "$root/shared/constants.php" "$work/$name/constants.php" + # A dangling link before the playbook created it: the member list cannot be loaded. + ln -s "$root/shared/sync-secrets.php" "$work/$name/sync-secrets.php" ln -s "$root/shared/files" "$work/$name/files" mv "$work/$name" "$release" created=true diff --git a/functions.php b/functions.php index 4c8e0a75..5f3b2f19 100644 --- a/functions.php +++ b/functions.php @@ -1158,7 +1158,7 @@ function receipt_v2_send($receipt) } } -// Membership-system exchange (getusers.php, mbapi.php): key and IV. +// Membership export (mbapi.php): key and IV. function membership_cipher_params($datakey) { return [md5($datakey), md5(md5($datakey))]; @@ -1170,12 +1170,6 @@ function membership_encrypt($datakey, $data) return rijndael256_encrypt($cipherKey, $data, $iv); } -function membership_decrypt($datakey, $data) -{ - [$cipherKey, $iv] = membership_cipher_params($datakey); - return rijndael256_decrypt($cipherKey, $data, $iv); -} - /* * Login sessions. users.cookie (an integer column) holds a random nonce that * every login replaces and logout clears. The pp_pgacc_login cookie is an diff --git a/getusers.php b/getusers.php index 95a23bd1..bb070435 100644 --- a/getusers.php +++ b/getusers.php @@ -19,10 +19,6 @@ function getusers_query($query) return $error; } -// Loads the member list of the membership system into ppmembers, a -// temporary table of this connection (other requests neither see nor replace -// it). Returns null, or the error message for the page (the cause of a failed -// fetch goes to the error log); the caller decides how to stop. // An error of getUsers(), logged once (a failed fetch logs its cause instead). function getusers_failed($message) { @@ -30,90 +26,136 @@ function getusers_failed($message) return $message; } -function getUsers() +// True if $uuid is a UUID (8-4-4-4-12 hex digits), the form of Admidio's +// user_uuid. Checked before a uuid is stored or put into a link. +function member_uuid_valid($uuid) { - global $datakey,$dbconn; - // Certificate verification stays on (PHP defaults). The member list is - // replaced only by a complete, valid response, in one transaction; on any - // error the connection's previous list (if any) stays as it was. Redirects are not - // followed (a 3xx is an error), so the list never comes from another host or - // over plain HTTP. ignore_errors: an HTTP error status is checked here - // instead of raising a warning. - $context = stream_context_create(['http' => ['ignore_errors' => true, 'follow_location' => 0, 'timeout' => 20]]); + return is_string($uuid) && preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/Di', $uuid) === 1; +} + +// The member list settings of the configuration $file (sync-secrets.php in +// the release root, resolved like the include of constants.php): +// ['members_url' => 'https://...', 'members_token' => non-empty string, +// 'members_cafile' => the membership system's certificate], or null if the +// file is missing or one of them is missing, empty or (the URL) not https. +function getusers_config($file) +{ + $config = stream_resolve_include_path($file) === false ? null : include $file; + foreach (['members_url', 'members_token', 'members_cafile'] as $name) { + if (!is_string($config[$name] ?? null) || $config[$name] === '') { + return null; + } + } + if (strncmp($config['members_url'], 'https://', 8) !== 0) { + return null; + } + return $config; +} + +// The body of the member list, or null (the cause is logged). TLS is +// verified against members_cafile only (the membership system's +// certificate; with a cafile PHP does not load the system's CAs), including +// the host name or address of the URL. Redirects are not followed (a 3xx is +// an error), so the list never comes from another host or over plain HTTP. +// Only 200 is accepted. ignore_errors: an HTTP error status is checked here +// instead of raising a warning. The token is never logged. +function getusers_fetch($config) +{ + $context = stream_context_create([ + 'http' => [ + 'header' => 'Authorization: Bearer ' . $config['members_token'] . "\r\nAccept: application/json\r\n", + 'ignore_errors' => true, + 'follow_location' => 0, + 'timeout' => 20, + ], + 'ssl' => [ + 'verify_peer' => true, + 'verify_peer_name' => true, + 'allow_self_signed' => false, + 'cafile' => $config['members_cafile'], + ], + ]); http_clear_last_response_headers(); error_clear_last(); - $sData = @file_get_contents("https://mitglieder.piratenpartei.at/adm_api/adm_names.php", false, $context); + $body = @file_get_contents($config['members_url'], false, $context); $headers = http_get_last_response_headers(); - if ($sData === false || !is_array($headers) || !preg_match('#^HTTP/\S+ 200( |$)#', $headers[0])) { + if ($body === false || !is_array($headers) || !preg_match('#^HTTP/\S+ 200( |$)#', $headers[0])) { $error = error_get_last(); - error_log('getusers: ' . ($sData === false ? ($error === null ? 'fetch failed' : $error['message']) : $headers[0])); - return 'Mitgliederliste konnte nicht abgerufen werden!'; - } - if (strlen($datakey) == 0) { - return getusers_failed('Kein Passwort!'); + error_log('getusers: ' . ($body === false ? ($error === null ? 'fetch failed' : $error['message']) : $headers[0])); + return null; } + return $body; +} - if (strlen($sData) < 1000) { - return getusers_failed('Daten von Mitgliederverwaltung zu kurz!'); +// The members of the JSON list $body ([{"id": int, "uuid": string, "name": +// string, "lo": int|null, "paid": 0|1}, ...]) as [id, uuid, name, pgacc +// organization, paid] rows, or null if the document is not such a non-empty +// list: every row must have exactly these fields, a positive id and a uuid +// that no other row has, a name without NUL bytes, an integer or null lo. +// lo is the membership system's organization role (37-45), mapped to the +// organization of pgacc; others and null become 10. +function getusers_parse($body) +{ + $members = json_decode($body, true); + if (!is_array($members) || $members === [] || !array_is_list($members)) { + return null; } - - $decrypted = rtrim(membership_decrypt($datakey, base64_decode($sData)), "\0"); - $query = 'INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES '; - $lines = explode("\n", $decrypted); - $count = 0; - foreach ($lines as $line) { - if (strlen($line) < 5) { - continue; - } - $values = explode("\t", $line); - // A line without the five fields means a damaged or undecryptable list. - if (count($values) < 5) { - return getusers_failed('Daten von Mitgliederverwaltung ungültig!'); - } - $id = intval($values[1]); - $name = stripslashes(iconv('ISO-8859-15', 'UTF-8', $values[2])); - $lo = $values[3]; - $paid = intval($values[4]); - switch ($lo) { - case 38: $lo_num = 1; - break; - case 40: $lo_num = 2; - break; - case 39: $lo_num = 3; - break; - case 41: $lo_num = 4; - break; - case 42: $lo_num = 5; - break; - case 43: $lo_num = 6; - break; - case 44: $lo_num = 10; - break; - case 45: $lo_num = 8; - break; - case 37: $lo_num = 9; - break; - default: $lo_num = 10; - break; + $organizations = [38 => 1, 40 => 2, 39 => 3, 41 => 4, 42 => 5, 43 => 6, 44 => 10, 45 => 8, 37 => 9]; + $rows = []; + $uuids = []; + foreach ($members as $member) { + if (!is_array($member) || count($member) !== 5 + || !is_int($member['id'] ?? null) || $member['id'] < 1 || isset($rows[$member['id']]) + || !member_uuid_valid($member['uuid'] ?? null) || isset($uuids[strtolower($member['uuid'])]) + || !is_string($member['name'] ?? null) || strpos($member['name'], "\0") !== false + || !array_key_exists('lo', $member) || ($member['lo'] !== null && !is_int($member['lo'])) + || !in_array($member['paid'] ?? null, [0, 1], true)) { + return null; } - //echo "insert: id=$id, name=$name, lo=$lo_num\n"; - if ($count > 0) { - $query .= ','; - } - $query .= "($id,'" . pg_escape_string($dbconn, $name) . "',$lo_num,$paid)"; - $count++; + $uuids[strtolower($member['uuid'])] = true; + $rows[$member['id']] = [$member['id'], strtolower($member['uuid']), $member['name'], + $member['lo'] === null ? 10 : $organizations[$member['lo']] ?? 10, $member['paid']]; + } + return array_values($rows); +} + +// Loads the member list of the membership system (internal/members.php of +// the membership system, over the internal TLS listener; deploy/README.md, +// "Membership system") into ppmembers, a temporary table of this connection +// (other requests neither see nor replace it). Returns null, or the error +// message for the page (the cause of a failed fetch goes to the error log); +// the caller decides how to stop. $file: the configuration file (the tests +// pass another one). +function getUsers($file = 'sync-secrets.php') +{ + global $dbconn; + $config = getusers_config($file); + if ($config === null) { + return getusers_failed('Mitgliederliste nicht konfiguriert!'); } - if ($count == 0) { + // The member list is replaced only by a complete, valid response, in one + // transaction; on any error the connection's previous list (if any) + // stays as it was. + $body = getusers_fetch($config); + if ($body === null) { + return 'Mitgliederliste konnte nicht abgerufen werden!'; + } + $members = getusers_parse($body); + if ($members === null) { return getusers_failed('Daten von Mitgliederverwaltung ungültig!'); } - $query .= ';'; + $values = []; + foreach ($members as [$id, $uuid, $name, $lo, $paid]) { + $values[] = "($id,'$uuid','" . pg_escape_string($dbconn, $name) . "',$lo,$paid)"; + } + $query = 'INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES ' . implode(',', $values) . ';'; // Inside a caller's transaction (the unit tests) a savepoint, so that the // caller's transaction is neither committed nor ended. $nested = pg_transaction_status($dbconn) != PGSQL_TRANSACTION_IDLE; $queries = [ $nested ? 'SAVEPOINT getusers;' : 'BEGIN;', - 'CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS;', + 'CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS;', 'DELETE FROM pg_temp.ppmembers;', $query, $nested ? 'RELEASE SAVEPOINT getusers;' : 'COMMIT;', diff --git a/mb.php b/mb.php index 51733a22..1c303a9a 100644 --- a/mb.php +++ b/mb.php @@ -1,5 +1,17 @@ ' . $id . ''; +} + function page_mb($rights) { global $dbconn; @@ -86,7 +98,7 @@ function page_mb($rights) if (($line['amount'] < 2000 && $line['paid'] == 1) || ($line['amount'] >= 2000 && $line['paid'] == 0)) { $count++; echo "$count - {$line['id']} (Buchungszeilen) + " . mb_member_link($line['id'], $line['uuid']) . " (Buchungszeilen) " . html_escape($line['name']) . " " . ($line['amount'] / 100.0) . " " . intval($line['paid']) . ""; @@ -105,7 +117,7 @@ function page_mb($rights) if (($line['amount'] >= 2000 && $line['paid'] == 1) || ($line['amount'] < 2000 && $line['paid'] == 0)) { $count++; echo "$count - {$line['id']} (Buchungszeilen) + " . mb_member_link($line['id'], $line['uuid']) . " (Buchungszeilen) " . html_escape($line['name']) . " " . ($line['amount'] / 100.0) . " " . intval($line['paid']) . ""; diff --git a/new.php b/new.php index 1892833c..2394065d 100644 --- a/new.php +++ b/new.php @@ -512,7 +512,7 @@ function page_edit_form($part, $voucher, $rights)
-' . (intval($voucher['mitgliedsnummer']) > 0 ? ' · In MV öffnen' : '') . ' +' . (intval($voucher['mitgliedsnummer']) > 0 ? ' · Nr. ' . intval($voucher['mitgliedsnummer']) : '') . '
diff --git a/scripts/release.sh b/scripts/release.sh index d7dd9cfa..cd0aeb25 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -136,7 +136,7 @@ build_archive() { # Code at HEAD, without the export-ignore'd development files. git -C "$repo_dir" archive --format=tar HEAD | tar -x -C "$stage" - if [ -e "$stage/constants.php" ] || [ -e "$stage/tests/run.sh" ]; then + if [ -e "$stage/constants.php" ] || [ -e "$stage/sync-secrets.php" ] || [ -e "$stage/tests/run.sh" ]; then echo "The archive contains development or configuration files; check .gitattributes" >&2 exit 1 fi diff --git a/tests/README.md b/tests/README.md index dc48e327..7b59b227 100644 --- a/tests/README.md +++ b/tests/README.md @@ -221,15 +221,20 @@ constraints; no backup table, owners, permissions, credentials or rows). The membership system never leaves the test network: `compose.test.yaml` runs the reference stub (`tests/reference/membership/server.php`) as the service `membership` under the alias `mitglieder.piratenpartei.at`, and -`tests/runtime/test-constants.php` sets the synthetic `$datakey` of its member -list. The application service waits for it. +`tests/runtime/test-sync-secrets.php` (the image's and the development +loop's `sync-secrets.php`) sets the URL, the synthetic token (which the stub +requires; 403 otherwise) and the `members_cafile` of its member list. The +application service waits for it. -The stub speaks HTTPS, and `getusers()` verifies its certificate with PHP's -default settings (verification is never turned off). A build stage of +The stub speaks HTTPS, and `getusers()` verifies its certificate against +`members_cafile` only (verification is never turned off). A build stage of `tests/php-runtime.Dockerfile` generates a synthetic test CA and a server certificate for `mitglieder.piratenpartei.at` on every image build; the CA key stays in that stage, and nothing is committed. The application image trusts -the CA system-wide (`update-ca-certificates`), and the stub runs from the same +the CA system-wide too (`update-ca-certificates`; `GetUsersTest` shows that +a certificate the system trusts is refused unless it is from +`members_cafile`, and that the stub's self-signed certificate is accepted +when it is `members_cafile`), and the stub runs from the same image with the server certificate (`/etc/pgacc-test-tls/membership.pem`), so the reference image, which builds on it, gets both too. The certificates are valid from 2020 to 2099 because the reference runs fake the application's @@ -237,18 +242,19 @@ clock. The tests control the stub over plain HTTP on port 80 (only the `/__stub/` controls are served there): `GET http://mitglieder.piratenpartei.at/__stub/mode?set=` switches the member-list response, and `POST .../__stub/body` serves a given body (the unit -tests, `tests/unit/MembershipStub.php`). The modes (`short`, `garbage`, -`empty`, `flow`, `overflow`, `redirect`, `redirect-http`, `selfsigned`, -`wrongname`, `error`, ...) and the response format as `getusers.php` reads it -are documented in the header of `server.php`; `selfsigned` and `wrongname` +tests, `tests/unit/MembershipStub.php`). The modes (`malformed`, `empty`, +`invalid-row`, `duplicate`, `bad-uuid`, `flow`, `overflow`, `redirect`, +`redirect-http`, `selfsigned`, `wrongname`, `error`, ...) are documented in +the header of `server.php`; `selfsigned` and `wrongname` present a self-signed and a wrong-name certificate (also generated per build) that `getusers()` must refuse. `tests/http-import.php` uses the modes for the failure cases and a member match; the refused handshakes' warnings are attributed with `with_expected_diagnostics()` (`tests/http-diagnostics.php`), and `/__stub/list-requests` proves that no redirect was followed. `GetUsersTest` fetches the synthetic `flow` list -(`tests/reference/membership/flow.tsv`) over HTTPS and checks the exact -`ppmembers` rows. +(`tests/reference/membership/flow.json`) over HTTPS and checks the exact +`ppmembers` rows, refuses every kind of malformed list, and checks the +settings, the UUID check and the profile links. All test servers run with `output_buffering=4096`, but no redirect depends on it: `http-login.php`, `http-redirects.php` and `write-workflows.php` repeat @@ -574,9 +580,8 @@ recording has: `fixtures/make-pdf.php`), receipt upload/download, `mbapi.php` and the member-fee page. `mitglieder.piratenpartei.at` resolves to the HTTPS stub (`membership/server.php`) inside the network; it serves - `membership/adm_names.b64` (synthetic members, key in - `runtime/reference-constants.php`, regenerated by `membership/generate.php`) - and `membership-stub.txt` records what it received. + `membership/members.json` (synthetic members) and `membership-stub.txt` + records what it received. - `diagnostics/*.txt`: PHP diagnostics per request (compared like the rest: a new, changed or missing diagnostic fails). diff --git a/tests/coverage/merge.php b/tests/coverage/merge.php index fd13bbf5..8aa8f7d4 100644 --- a/tests/coverage/merge.php +++ b/tests/coverage/merge.php @@ -15,7 +15,7 @@ * * contains phpunit.cov and http/*.ser. Scope: every * application PHP file: the top-level files in /app (except the test-only - * constants.php), the entry points in /app/public and the library files in + * constants.php and sync-secrets.php), the entry points in /app/public and the library files in * /app/src. Files that * no test reaches are included with zero coverage (statically analysed, never * executed). @@ -44,7 +44,7 @@ $files = []; foreach (array_merge(glob($appRoot . '/*.php'), glob($appRoot . '/public/*.php'), glob($appRoot . '/src/*.php')) as $file) { - if (basename($file) !== 'constants.php') { + if (!in_array(substr($file, strlen($appRoot) + 1), ['constants.php', 'sync-secrets.php'], true)) { $files[] = $file; } } diff --git a/tests/fixtures/mcrypt/generate-vectors.php b/tests/fixtures/mcrypt/generate-vectors.php index 2d1654d0..cc918829 100644 --- a/tests/fixtures/mcrypt/generate-vectors.php +++ b/tests/fixtures/mcrypt/generate-vectors.php @@ -52,15 +52,6 @@ function mbapi_vector($name, $datakey, $text) return array('name' => $name, 'datakey' => $datakey, 'text' => bin2hex($text), 'output' => $output); } -function getusers_vector($name, $datakey, $plain) -{ - // The membership system's export as getusers.php reads it: base64 ciphertext. - $sData = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($datakey), $plain, MCRYPT_MODE_CBC, md5(md5($datakey)))); - $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($datakey), base64_decode($sData), MCRYPT_MODE_CBC, md5(md5($datakey))), "\0"); - return array('name' => $name, 'datakey' => $datakey, 'plain' => bin2hex($plain), 'sData' => $sData, - 'decrypted' => bin2hex($decrypted)); -} - $pdf = "%PDF-1.4\n%\xE2\xE3\xCF\xD3\n1 0 obj\n<< /Type /Catalog >>\nendobj\ntrailer\n<< /Root 1 0 R >>\n%%EOF\n"; $jpeg = "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00" . "\xFF\xDB\x00\x43\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\x09\x09\x08\x0A\x0C\x14\x0D\x0C\x0B\x0B\x0C" @@ -97,39 +88,16 @@ function getusers_vector($name, $datakey, $plain) substr(hex2bin($receipts[5]['cipher']), 0, 50)), ); -$memberExport = "x\t1001\tSynthetic Member \xE4\xF6\xFC\t38\t1\n" - . "x\t1002\tO\\'Synthetic\t44\t0\n" - . "x\t1003\tThird Synthetic\t99\t1\n"; $mbapi = array( mbapi_vector('two members', 'synthetic-membership-key', "1001\t2500\t2026-12-31\n1002\t12000\t2026-12-31\n"), mbapi_vector('no members', 'synthetic-membership-key', ''), mbapi_vector('empty datakey (test constants)', '', "1001\t2500\t2026-12-31\n"), ); -// Long enough for getUsers(), which rejects responses under 1000 characters: -// every organization code it maps, an unknown one, a short line it skips, an -// escaped quote and an ISO-8859-15 euro sign. -$getUsersExport = "x\n"; -$organizations = array(37, 38, 39, 40, 41, 42, 43, 44, 45, 99); -for ($i = 0; $i < 30; $i++) { - $getUsersExport .= sprintf("x\t%d\tSynthetic Member %02d\t%d\t%d\n", 2001 + $i, $i, $organizations[$i % 10], $i % 2); -} -$getUsersExport .= "x\t2031\tO\\'Synthetic \xA4uro\t38\t1\n"; -// Not block-aligned: the zero padding (5 bytes) must be stripped before parsing. -$getUsersExport .= "x\t2032\tLast Synthetic\t40\t0\n"; - -$getusers = array( - getusers_vector('getUsers() export', 'synthetic-membership-key', $getUsersExport), - getusers_vector('member export', 'synthetic-membership-key', $memberExport), - getusers_vector('block-aligned export', 'synthetic-membership-key', str_repeat("x\t1004\tAligned\t40\t1\n", 4) . "abcdefghijkl\n"), - getusers_vector('export ending in NUL bytes', 'synthetic-membership-key', $memberExport . "\0\0"), -); - $vectors = array( 'generator' => 'tests/fixtures/mcrypt/generate-vectors.php', 'php' => PHP_VERSION, 'receipts' => $receipts, 'receipt_decrypts' => $receiptDecrypts, 'mbapi' => $mbapi, - 'getusers' => $getusers, ); echo json_encode($vectors, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), "\n"; diff --git a/tests/fixtures/mcrypt/vectors.json b/tests/fixtures/mcrypt/vectors.json index 8f0e7f5d..ba665dd6 100644 --- a/tests/fixtures/mcrypt/vectors.json +++ b/tests/fixtures/mcrypt/vectors.json @@ -134,35 +134,5 @@ "text": "31303031093235303009323032362d31322d33310a", "output": "c06212339f9f2166d707959bd6078c09c9d91fff\nSogmbFUp/vigi6g8fjHEmOyhBOGLGgB5CgVfwc/+ckI=" } - ], - "getusers": [ - { - "name": "getUsers() export", - "datakey": "synthetic-membership-key", - "plain": "780a7809323030310953796e746865746963204d656d62657220303009333709300a7809323030320953796e746865746963204d656d62657220303109333809310a7809323030330953796e746865746963204d656d62657220303209333909300a7809323030340953796e746865746963204d656d62657220303309343009310a7809323030350953796e746865746963204d656d62657220303409343109300a7809323030360953796e746865746963204d656d62657220303509343209310a7809323030370953796e746865746963204d656d62657220303609343309300a7809323030380953796e746865746963204d656d62657220303709343409310a7809323030390953796e746865746963204d656d62657220303809343509300a7809323031300953796e746865746963204d656d62657220303909393909310a7809323031310953796e746865746963204d656d62657220313009333709300a7809323031320953796e746865746963204d656d62657220313109333809310a7809323031330953796e746865746963204d656d62657220313209333909300a7809323031340953796e746865746963204d656d62657220313309343009310a7809323031350953796e746865746963204d656d62657220313409343109300a7809323031360953796e746865746963204d656d62657220313509343209310a7809323031370953796e746865746963204d656d62657220313609343309300a7809323031380953796e746865746963204d656d62657220313709343409310a7809323031390953796e746865746963204d656d62657220313809343509300a7809323032300953796e746865746963204d656d62657220313909393909310a7809323032310953796e746865746963204d656d62657220323009333709300a7809323032320953796e746865746963204d656d62657220323109333809310a7809323032330953796e746865746963204d656d62657220323209333909300a7809323032340953796e746865746963204d656d62657220323309343009310a7809323032350953796e746865746963204d656d62657220323409343109300a7809323032360953796e746865746963204d656d62657220323509343209310a7809323032370953796e746865746963204d656d62657220323609343309300a7809323032380953796e746865746963204d656d62657220323709343409310a7809323032390953796e746865746963204d656d62657220323809343509300a7809323033300953796e746865746963204d656d62657220323909393909310a780932303331094f5c2753796e74686574696320a475726f09333809310a780932303332094c6173742053796e74686574696309343009300a", - "sData": "n7dyQiLXzOVdr0lhQOWqZ/KxM7XTf89nwqVw8RBCZXIvLyAvaOBllGwSj+TK3drvX8d6cJ2g/NjzqmGRWCKvakI/byytGtNS4OlzOxxWYTDoM3cZ7kZwz7g6w4UDWAqMiPeYxeUvfA+fTmQOi1xkPxN5KHFv0bUyqI1Rszsclx6VuAyl0EoeITOIjqmrAOjc0Sx6ePGrd8y2neoskUOiIFBk52lsPMGs7c1brGnkeW9t8qxYJOxmJ7RhmAi6o9zQoftSOE6oXW6lICY8psE5u05f4y4xAaPJlRT6oOM3qavOJtvtqQwGqKRv9zQDwPROKQ/1DxIM169V+oqeWO0v5Rvy9iQkW0z1V+kLboGTn3VRaYWOIDMKFR6SGppPi8HAweWoNLO6CHAWcR0Vf0Fd3mUsU8OpBUm5YmR6FApyX33var3THyftG0F9dZa3IIV4vaxw/jTNU/w/IwtRoALlfM7DPtOzDcN2nN07nDEI5Txn2mT1NbC+iCUAwHY8lGWVv5Q6wXpIER3LonVKWZzBEp0+c537S221Q/jMQDlOVAqQAHvuHFydLVO0+mTMsnnjzN7zpcFUiqyYFcAFmNdiIeim3cdA53/jeVfm8KDQ2re47X43VxqW6+fNfdfkeVHFIQHo6sXxW7xwPnLSmqc7Z68XykmufBfddht9KXUO5Dz3Qmd/s+uKpvkIuvfG9n0/hN+jb+VKJGA9JgfzrtCpjEXNgXasEhtl1Mfmpu6lIpBd/yn7vnhqBxTGBvmCHCHFegzvDXLixH6un/EcnH1aeTFp+7rUaBZmfegCvr4xXwtS7OXhx7iKctWwct1Z1sTVS51RaCx3aYpDovCyL8D9RYGPMIcb0SoskUrCpjzMoM4B+7PWE55p6Qa/pMAfoaL/ELZPMkiEytPia1m+xlqoq2dI2fBrakqaPUUlpxlX3hfztfbfcanhWXTOILOFRWKuwqBv5ouemSOLdNQK5UNakqbujNUpKgmAV3nidVhnpHPo7FHej6sipQZLhoxq/E5i60C6i9P5nHBBJ2j5Byl2Vknlsz7/kZ4d9OAUVcYVponf789+DvA3pQCOfGN/ojq9i+Q6ZUwXshaZYlqx6KeqoEV0mg1jm00lgU451Za1l3mnxSn38MZJlY4GsrJ+QlJWV/IiXv0qSb/6BHDGTXbfiLKorR3FPsI3At6rxmqvWmNKMHWBtQb8Yvnkky4uPB0G8HE7a2L/tcjrib/gupHyv5LDC4iP1OpBT+TpRLJiFEa/wfnwC82S1J8ej3y8M2EJ5lu1RJah08dsrKZZlbAgxUev3uBpZaFlX/IDLw3/mG6AYXw/ElM95ZgWuTjB1hIul3i81IdbYkel9jqP9vbXRA==", - "decrypted": "780a7809323030310953796e746865746963204d656d62657220303009333709300a7809323030320953796e746865746963204d656d62657220303109333809310a7809323030330953796e746865746963204d656d62657220303209333909300a7809323030340953796e746865746963204d656d62657220303309343009310a7809323030350953796e746865746963204d656d62657220303409343109300a7809323030360953796e746865746963204d656d62657220303509343209310a7809323030370953796e746865746963204d656d62657220303609343309300a7809323030380953796e746865746963204d656d62657220303709343409310a7809323030390953796e746865746963204d656d62657220303809343509300a7809323031300953796e746865746963204d656d62657220303909393909310a7809323031310953796e746865746963204d656d62657220313009333709300a7809323031320953796e746865746963204d656d62657220313109333809310a7809323031330953796e746865746963204d656d62657220313209333909300a7809323031340953796e746865746963204d656d62657220313309343009310a7809323031350953796e746865746963204d656d62657220313409343109300a7809323031360953796e746865746963204d656d62657220313509343209310a7809323031370953796e746865746963204d656d62657220313609343309300a7809323031380953796e746865746963204d656d62657220313709343409310a7809323031390953796e746865746963204d656d62657220313809343509300a7809323032300953796e746865746963204d656d62657220313909393909310a7809323032310953796e746865746963204d656d62657220323009333709300a7809323032320953796e746865746963204d656d62657220323109333809310a7809323032330953796e746865746963204d656d62657220323209333909300a7809323032340953796e746865746963204d656d62657220323309343009310a7809323032350953796e746865746963204d656d62657220323409343109300a7809323032360953796e746865746963204d656d62657220323509343209310a7809323032370953796e746865746963204d656d62657220323609343309300a7809323032380953796e746865746963204d656d62657220323709343409310a7809323032390953796e746865746963204d656d62657220323809343509300a7809323033300953796e746865746963204d656d62657220323909393909310a780932303331094f5c2753796e74686574696320a475726f09333809310a780932303332094c6173742053796e74686574696309343009300a" - }, - { - "name": "member export", - "datakey": "synthetic-membership-key", - "plain": "7809313030310953796e746865746963204d656d62657220e4f6fc09333809310a780931303032094f5c2753796e74686574696309343409300a7809313030330954686972642053796e74686574696309393909310a", - "sData": "UckLQUfqvjWHLQKEtd1yfLcMRetYF4GNNMKDjPeiKk2XIp/wyGJAjiAOTePxgNPrd62C+iKsX9+bW0JuGPBANjkgRFT5Vjrxosj/yEvisagzw7rNKXeCUBsfxsFXVeL8", - "decrypted": "7809313030310953796e746865746963204d656d62657220e4f6fc09333809310a780931303032094f5c2753796e74686574696309343409300a7809313030330954686972642053796e74686574696309393909310a" - }, - { - "name": "block-aligned export", - "datakey": "synthetic-membership-key", - "plain": "78093130303409416c69676e656409343009310a78093130303409416c69676e656409343009310a78093130303409416c69676e656409343009310a78093130303409416c69676e656409343009310a6162636465666768696a6b6c0a", - "sData": "tNAHKj/xpQ7hTRqgzFwRNn8/6XgZOe9hgpUpHS/zjSF/HpCNfTHHc9kt+jbkfblOZqENLyF1O8HQPQcJpOGsAgJbcYIv0dTbTN4ylWx0Z3p1P/MG5JqB4u1RqykERMWy", - "decrypted": "78093130303409416c69676e656409343009310a78093130303409416c69676e656409343009310a78093130303409416c69676e656409343009310a78093130303409416c69676e656409343009310a6162636465666768696a6b6c0a" - }, - { - "name": "export ending in NUL bytes", - "datakey": "synthetic-membership-key", - "plain": "7809313030310953796e746865746963204d656d62657220e4f6fc09333809310a780931303032094f5c2753796e74686574696309343409300a7809313030330954686972642053796e74686574696309393909310a0000", - "sData": "UckLQUfqvjWHLQKEtd1yfLcMRetYF4GNNMKDjPeiKk2XIp/wyGJAjiAOTePxgNPrd62C+iKsX9+bW0JuGPBANjkgRFT5Vjrxosj/yEvisagzw7rNKXeCUBsfxsFXVeL8", - "decrypted": "7809313030310953796e746865746963204d656d62657220e4f6fc09333809310a780931303032094f5c2753796e74686574696309343409300a7809313030330954686972642053796e74686574696309393909310a" - } ] } diff --git a/tests/http-import.php b/tests/http-import.php index 6f042ff4..79d7921b 100644 --- a/tests/http-import.php +++ b/tests/http-import.php @@ -374,8 +374,9 @@ function import_amount_cases($database, $cookies, $name, $header, $cases, $line, // getusers() loads the member list into ppmembers, a temporary table of the // request's connection, only from a complete, valid response of the // membership stub (HTTPS, compose.test.yaml). A failed fetch (an HTTP error, -// a redirect, a refused certificate), a short or an undecryptable response, -// or an SQL error stops the page with an error. A shared ppmembers table (as +// a redirect, a refused certificate), a malformed list (not JSON, empty, a +// row without its uuid, a member twice, a uuid that is not a UUID) or an SQL +// error stops the page with an error. A shared ppmembers table (as // earlier releases kept one, planted here) is never read or changed. function membership_stub_mode($mode) { @@ -400,6 +401,10 @@ function member_rows($database) $memberPage = http_request('/index.php?action=mb', 'GET', [], $adminCookies); assert_status($memberPage, 200, 'member-fee page'); assert_contains($memberPage['body'], 'Anna Synthetisch-Müller', 'member-fee page'); +// The member's profile is linked by uuid (Admidio opens profiles by +// user_uuid only), not by id. +assert_contains($memberPage['body'], '9001 (', 'member-fee page profile link'); +assert_not_contains($memberPage['body'], 'user_id=', 'member-fee page profile link'); // A bank import matches a line's name against the list it just fetched (the // stub's "flow" list; its rows are checked in GetUsersTest): the voucher // becomes a membership fee (type 1) of that member. @@ -412,6 +417,16 @@ function member_rows($database) if ($flowFields !== [['name' => 'Jürgen Größe-Weiß', 'member_id' => '9111', 'type' => '1']]) { fail_test('member line with the flow list: ' . var_export($flowFields, true)); } +// The ledger and the voucher form show the member id as text: they do not +// load the member list, so they have no uuid to link the profile with. +$flowVoucher = pg_fetch_result(pg_query_params($database, 'SELECT voucher_id FROM vouchers WHERE comment = $1', ['Synthetic flow member line']), 0, 0); +$ledger = http_request('/index.php?action=all&filter_member_id=9111', 'GET', [], $adminCookies); +assert_contains($ledger['body'], '9111', 'ledger member id'); +$voucherForm = http_request('/index.php?action=edit&id=' . $flowVoucher, 'GET', [], $adminCookies); +assert_contains($voucherForm['body'], ' · Nr. 9111', 'voucher form member id'); +foreach (['ledger' => $ledger, 'voucher form' => $voucherForm] as $label => $page) { + assert_not_contains($page['body'], 'profile.php', "$label without a profile link"); +} membership_stub_mode('ok'); foreach (['DROP TABLE IF EXISTS ppmembers', 'CREATE TABLE ppmembers (id integer, name text, lo integer, paid integer)', "INSERT INTO ppmembers VALUES (8801, 'Synthetic Kept Member', 1, 1), (8802, 'Synthetic Kept Other', 10, 0)"] as $query) { @@ -421,14 +436,16 @@ function member_rows($database) } $members = member_rows($database); $failures = [ - 'short' => 'Daten von Mitgliederverwaltung zu kurz!', - 'garbage' => 'Daten von Mitgliederverwaltung ungültig!', + 'malformed' => 'Daten von Mitgliederverwaltung ungültig!', 'empty' => 'Daten von Mitgliederverwaltung ungültig!', + 'invalid-row' => 'Daten von Mitgliederverwaltung ungültig!', + 'duplicate' => 'Daten von Mitgliederverwaltung ungültig!', + 'bad-uuid' => 'Daten von Mitgliederverwaltung ungültig!', 'error' => 'Mitgliederliste konnte nicht abgerufen werden!', // Redirects are not followed, also not to the same host over HTTPS. 'redirect' => 'Mitgliederliste konnte nicht abgerufen werden!', 'redirect-http' => 'Mitgliederliste konnte nicht abgerufen werden!', - // The INSERT fails (member id out of range) after DROP and CREATE: the + // The INSERT fails (member id out of range) after DELETE: the // transaction is rolled back. 'overflow' => 'Abfrage fehlgeschlagen: ', // Certificate verification: PHP's warnings of the refused handshake diff --git a/tests/http-receipts.php b/tests/http-receipts.php index 65d4712b..607ebfdc 100644 --- a/tests/http-receipts.php +++ b/tests/http-receipts.php @@ -571,7 +571,7 @@ function receipts_membership_mode($mode) }); $memberCases = [ 'unreachable member list' => ['error', 4784, [], $membersUnavailable, true], - 'invalid member list' => ['garbage', 4784, [], $membersUnavailable, true], + 'invalid member list' => ['malformed', 4784, [], $membersUnavailable, true], 'invalid amount' => ['error', 4784, ['amount0' => 'abc'], 'Ungültiger Betrag', true], 'stale row' => ['error', 4784, ['bid0' => '9186'], 'Die Buchung wurde inzwischen geändert. Bitte neu laden.', false], 'no parts' => ['error', 4784, ['parts' => '0'], 'Keine Buchungszeile angegeben.', false], @@ -595,7 +595,7 @@ function receipts_membership_mode($mode) if ($formShown) { assert_contains($response['body'], 'value="Synthetic member revision"', "member revision: $label"); } - $fetched = @file_get_contents('http://mitglieder.piratenpartei.at/__stub/names-requests'); + $fetched = @file_get_contents('http://mitglieder.piratenpartei.at/__stub/members-requests'); if ($fetched !== ($expected === $membersUnavailable ? "1\n" : "0\n")) { fail_test("member revision: $label fetched the member list " . var_export($fetched, true) . ' times'); } @@ -1227,7 +1227,8 @@ function import2_text_pdf($lines) fail_test('membership export payload is not 64 bytes of base64: ' . var_export($lines[1], true)); } // The synthetic $datakey of tests/runtime/test-constants.php. -if (membership_decrypt('synthetic-reference-membership-key', $ciphertext) !== str_pad($text, 64, "\0")) { +[$cipherKey, $iv] = membership_cipher_params('synthetic-reference-membership-key'); +if (rijndael256_decrypt($cipherKey, $ciphertext, $iv) !== str_pad($text, 64, "\0")) { fail_test('membership export payload does not decrypt to the expected members'); } diff --git a/tests/mutation/README.md b/tests/mutation/README.md index 74c158d3..090df8d0 100644 --- a/tests/mutation/README.md +++ b/tests/mutation/README.md @@ -412,7 +412,7 @@ All targets run on PHP 8.5 (`ci.sh`). The target files hold each mutation's rati | `edge-requests` | removed `transfer` action and creation-form `ack` branch, four-digit `year`, array parameters in `getfilter()`/`get_param()`, closed-listing columns, member lookup without a name, null guards for `users.hide`, `getoppsort()`, `convif()` | PHPUnit, `http-page-views.php`, `http-listing-prefs.php`, `http-output-escaping.php`, `write-workflows.php` | | `amount-parsing` | `amount_cents()` in `src/format.php` and its call sites: the voucher form (`new.php`, the refused save in `new.php`/`edit.php`, the amount field shown again) and every bank import format (`import.php`); the year range of `date_condition()` and `page_donations()` | `AmountParsingTest`, `http-donations.php`, `write-workflows.php`, `http-import.php` | | `output-escaping` | `html_escape()`, `listing_text()` and the CSV cell serialization in `tag()`; every HTML and URL encoding call site (one mutant per call), also the uncalled kdonations sink | `FunctionsTest`, `UnusedOutputTest`, `http-output-escaping.php` | -| `receipt-crypto` | mcrypt-compatible helpers; receipt v2 (key validation, HKDF, MAC, chunked encryption and two-pass decryption, short reads); the migration (CLI guard, phases, lock, sync, checks); call sites in `file.php`, `new.php`, `import2.php`, `getusers.php`, `mbapi.php` | `CryptoTest`, `GetUsersTest`, `ReceiptImportTest`, `ReceiptStorageTest`, `ReceiptMigrationTest`, `ReceiptMigrationCommandTest`, `http-receipts.php` | +| `receipt-crypto` | mcrypt-compatible helpers; receipt v2 (key validation, HKDF, MAC, chunked encryption and two-pass decryption, short reads); the migration (CLI guard, phases, lock, sync, checks); call sites in `file.php`, `new.php`, `import2.php`, `mbapi.php` | `CryptoTest`, `ReceiptImportTest`, `ReceiptStorageTest`, `ReceiptMigrationTest`, `ReceiptMigrationCommandTest`, `http-receipts.php` | | `booking-progress` | `percent_of_bookings()` in `functions.php`: column order, the bar's segment widths, `aria-hidden`, no table without bookings | PHPUnit `testPercentOfBookings*` | Accepted equivalents (reasons in the target files): diff --git a/tests/mutation/targets/import-checks.php b/tests/mutation/targets/import-checks.php index 3232297a..366da041 100644 --- a/tests/mutation/targets/import-checks.php +++ b/tests/mutation/targets/import-checks.php @@ -7,7 +7,8 @@ * skipped, with a summary per file; and the PDF import's voucher match * (import2.php: the user's organizations, no finalized row) and the row check * of the receipt upload (new.php page_new_file()); and the member-list - * refresh (getusers.php: fetch status, list checks, one transaction). + * refresh (getusers.php: settings, TLS and token, fetch status, list + * checks, one transaction). * Tested with tests/http-import.php against the membership stub of * compose.test.yaml. See tests/mutation/README.md for the format. */ @@ -197,8 +198,8 @@ [ 'id' => 'members-error-status-accepted', 'file' => 'getusers.php', - 'search' => "if (\$sData === false || !is_array(\$headers) || !preg_match('#^HTTP/\\S+ 200( |\$)#', \$headers[0]))", - 'replace' => 'if ($sData === false)', + 'search' => "if (\$body === false || !is_array(\$headers) || !preg_match('#^HTTP/\\S+ 200( |\$)#', \$headers[0]))", + 'replace' => 'if ($body === false)', 'rationale' => 'A failed fetch (HTTP error status, redirect) stops with its own error.', ], [ @@ -208,19 +209,68 @@ 'replace' => "'follow_location' => 1", 'rationale' => 'Redirects are not followed (no other host, no plain HTTP).', ], + [ + 'id' => 'members-peer-name-unchecked', + 'file' => 'getusers.php', + 'search' => "'verify_peer_name' => true,", + 'replace' => "'verify_peer_name' => false,", + 'rationale' => 'The certificate must be for the host name or address of the URL.', + ], + [ + 'id' => 'members-system-cas-trusted', + 'file' => 'getusers.php', + 'search' => "'cafile' => \$config['members_cafile'],", + 'replace' => "'verify_depth' => 9,", + 'rationale' => 'Only the configured certificate is trusted, not the system\'s CAs.', + ], + [ + 'id' => 'members-token-not-sent', + 'file' => 'getusers.php', + 'search' => "'header' => 'Authorization: Bearer ' . \$config['members_token'] . \"\\r\\nAccept: application/json\\r\\n\",", + 'replace' => "'header' => \"Accept: application/json\\r\\n\",", + 'rationale' => 'The request carries the configured token.', + ], + [ + 'id' => 'members-plain-http-url-accepted', + 'file' => 'getusers.php', + 'search' => " if (strncmp(\$config['members_url'], 'https://', 8) !== 0) {", + 'replace' => ' if (false) {', + 'rationale' => 'Only an https:// URL is fetched.', + ], [ 'id' => 'members-fields-unchecked', 'file' => 'getusers.php', - 'search' => ' if (count($values) < 5)', - 'replace' => ' if (false)', - 'rationale' => 'An undecryptable list (lines without the five fields) is not imported.', + 'search' => '|| count($member) !== 5', + 'replace' => '', + 'rationale' => 'A row with other fields than the five of the format is refused.', + ], + [ + 'id' => 'members-duplicate-id-accepted', + 'file' => 'getusers.php', + 'search' => ' || isset($rows[$member[\'id\']])', + 'replace' => '', + 'rationale' => 'A list with a member id twice is refused.', + ], + [ + 'id' => 'members-duplicate-uuid-accepted', + 'file' => 'getusers.php', + 'search' => ' || isset($uuids[strtolower($member[\'uuid\'])])', + 'replace' => '', + 'rationale' => 'A list with a uuid twice is refused.', + ], + [ + 'id' => 'members-uuid-unchecked', + 'file' => 'getusers.php', + 'search' => '|| !member_uuid_valid($member[\'uuid\'] ?? null)', + 'replace' => '|| !is_string($member[\'uuid\'] ?? null)', + 'rationale' => 'Only a UUID is stored (it goes into the profile links).', ], [ 'id' => 'members-empty-list-accepted', 'file' => 'getusers.php', - 'search' => 'if ($count == 0)', - 'replace' => 'if (false)', - 'rationale' => 'A list without a member line is refused.', + 'search' => ' || $members === []', + 'replace' => '', + 'rationale' => 'A list without a member is refused.', ], [ 'id' => 'members-commits-caller-transaction', @@ -253,17 +303,17 @@ . 'failed refresh stops the page, so a partly refreshed list is never read.'], ], [ - 'id' => 'members-key-unchecked', + 'id' => 'members-unconfigured-fetched', 'file' => 'getusers.php', - 'search' => ' if (strlen($datakey) == 0) {', + 'search' => ' if ($config === null) {', 'replace' => ' if (false) {', - 'rationale' => 'Without a membership key the refresh returns its own error.', + 'rationale' => 'Without the member list settings the refresh returns its own error.', ], [ 'id' => 'members-shared-table', 'file' => 'getusers.php', - 'search' => " 'CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS;',", - 'replace' => " 'CREATE TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer);',", + 'search' => " 'CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS;',", + 'replace' => " 'CREATE TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer);',", 'rationale' => 'Each request has its own member list: a shared table is neither needed nor touched.', ], [ diff --git a/tests/mutation/targets/listing-columns.php b/tests/mutation/targets/listing-columns.php index ea64c832..cd3233f4 100644 --- a/tests/mutation/targets/listing-columns.php +++ b/tests/mutation/targets/listing-columns.php @@ -138,7 +138,7 @@ 3 => ["\n echo tag(\"td\", format_date(", null], 4 => ["\n echo tag(\"td\", \$line2[\"name\"]);", $typeLoop], 5 => ["\n echo tag(\"td\", \$line2[\"name\"]);", $loLoop], - 6 => ["\n if (\$make_csv) {\n echo tag(\"td\", \$line[\"member\"]", null], + 6 => ["\n echo tag(\"td\", \$line[\"member\"]", null], 7 => ["\n echo tag(\"td\", \$line[\"contra_account\"]);", null], 8 => ["\n echo tag(\"td\", \$line[\"account\"]);", null], 9 => ["\n echo tag(\"td\", \$line[\"vaccount\"]);", null], diff --git a/tests/mutation/targets/output-escaping.php b/tests/mutation/targets/output-escaping.php index e39264b0..d8a349d1 100644 --- a/tests/mutation/targets/output-escaping.php +++ b/tests/mutation/targets/output-escaping.php @@ -779,15 +779,15 @@ [ 'id' => 'mb-html-escape-line-name-3', 'file' => 'mb.php', - 'search' => '{' . "\n" . ' $count++;' . "\n" . ' echo "$count' . "\n" . ' {$line[\'id\']} (Buchungszeilen)' . "\n" . ' " . html_escape($line[\'name\']) . "' . "\n" . ' " . ($line[\'amount\'] / 100.0) . "' . "\n" . ' " . intval($line[\'paid\']) . "";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' echo "
";', - 'replace' => '{' . "\n" . ' $count++;' . "\n" . ' echo "$count' . "\n" . ' {$line[\'id\']} (Buchungszeilen)' . "\n" . ' " . ($line[\'name\']) . "' . "\n" . ' " . ($line[\'amount\'] / 100.0) . "' . "\n" . ' " . intval($line[\'paid\']) . "";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' echo "
";', + 'search' => '{' . "\n" . ' $count++;' . "\n" . ' echo "$count' . "\n" . ' " . mb_member_link($line[\'id\'], $line[\'uuid\']) . " (Buchungszeilen)' . "\n" . ' " . html_escape($line[\'name\']) . "' . "\n" . ' " . ($line[\'amount\'] / 100.0) . "' . "\n" . ' " . intval($line[\'paid\']) . "";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' echo "
";', + 'replace' => '{' . "\n" . ' $count++;' . "\n" . ' echo "$count' . "\n" . ' " . mb_member_link($line[\'id\'], $line[\'uuid\']) . " (Buchungszeilen)' . "\n" . ' " . ($line[\'name\']) . "' . "\n" . ' " . ($line[\'amount\'] / 100.0) . "' . "\n" . ' " . intval($line[\'paid\']) . "";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' echo "
";', 'rationale' => 'Unescaped output: html_escape() removed around $line[\'name\'].', ], [ 'id' => 'mb-html-escape-line-name-4', 'file' => 'mb.php', - 'search' => '{' . "\n" . ' $count++;' . "\n" . ' echo "$count' . "\n" . ' {$line[\'id\']} (Buchungszeilen)' . "\n" . ' " . html_escape($line[\'name\']) . "' . "\n" . ' " . ($line[\'amount\'] / 100.0) . "' . "\n" . ' " . intval($line[\'paid\']) . "";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' echo "";', - 'replace' => '{' . "\n" . ' $count++;' . "\n" . ' echo "$count' . "\n" . ' {$line[\'id\']} (Buchungszeilen)' . "\n" . ' " . ($line[\'name\']) . "' . "\n" . ' " . ($line[\'amount\'] / 100.0) . "' . "\n" . ' " . intval($line[\'paid\']) . "";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' echo "";', + 'search' => '{' . "\n" . ' $count++;' . "\n" . ' echo "$count' . "\n" . ' " . mb_member_link($line[\'id\'], $line[\'uuid\']) . " (Buchungszeilen)' . "\n" . ' " . html_escape($line[\'name\']) . "' . "\n" . ' " . ($line[\'amount\'] / 100.0) . "' . "\n" . ' " . intval($line[\'paid\']) . "";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' echo "";', + 'replace' => '{' . "\n" . ' $count++;' . "\n" . ' echo "$count' . "\n" . ' " . mb_member_link($line[\'id\'], $line[\'uuid\']) . " (Buchungszeilen)' . "\n" . ' " . ($line[\'name\']) . "' . "\n" . ' " . ($line[\'amount\'] / 100.0) . "' . "\n" . ' " . intval($line[\'paid\']) . "";' . "\n" . ' }' . "\n" . ' }' . "\n" . ' echo "";', 'rationale' => 'Unescaped output: html_escape() removed around $line[\'name\'].', ], [ diff --git a/tests/mutation/targets/receipt-crypto.php b/tests/mutation/targets/receipt-crypto.php index 579656a6..49f87306 100644 --- a/tests/mutation/targets/receipt-crypto.php +++ b/tests/mutation/targets/receipt-crypto.php @@ -2,12 +2,12 @@ /* * The mcrypt replacement in functions.php (Rijndael-256 CBC, zero padding) - * and its five call sites: receipt upload (new.php), PDF import - * (import2.php), receipt download (file.php), membership import - * (getusers.php) and export (mbapi.php); the receipt storage helpers + * and its four call sites: receipt upload (new.php), PDF import + * (import2.php), receipt download (file.php) and the membership export + * (mbapi.php); the receipt storage helpers * (configured key, .v2.aes and legacy .aes) and the receipt key * migration (migrate-receipt-key.php). Killed by the mcrypt contract vectors - * (tests/unit/CryptoTest.php), the storage, getUsers(), import and migration + * (tests/unit/CryptoTest.php), the storage, import and migration * tests, and the HTTP receipt and export tests. See tests/mutation/README.md * for the format. */ @@ -16,7 +16,6 @@ 'file' => 'functions.php', 'tests' => [ ['type' => 'phpunit', 'filter' => 'CryptoTest', 'file' => 'tests/unit/CryptoTest.php'], - ['type' => 'phpunit', 'filter' => 'GetUsersTest', 'file' => 'tests/unit/GetUsersTest.php'], ['type' => 'phpunit', 'filter' => 'ReceiptImportTest', 'file' => 'tests/unit/ReceiptImportTest.php'], ['type' => 'phpunit', 'filter' => 'ReceiptStorageTest', 'file' => 'tests/unit/ReceiptStorageTest.php'], ['type' => 'phpunit', 'filter' => 'ReceiptMigrationTest', 'file' => 'tests/unit/ReceiptMigrationTest.php'], @@ -79,7 +78,7 @@ 'search' => 'return [md5($datakey), md5(md5($datakey))];', 'replace' => 'return [md5($datakey), md5($datakey)];', 'rationale' => 'The membership IV is md5(md5(datakey)).'], ['id' => 'membership-encrypt-params-swapped', - 'search' => " return rijndael256_encrypt(\$cipherKey, \$data, \$iv);\n}\n\nfunction membership_decrypt", 'replace' => " return rijndael256_encrypt(\$iv, \$data, \$cipherKey);\n}\n\nfunction membership_decrypt", + 'search' => " return rijndael256_encrypt(\$cipherKey, \$data, \$iv);\n}\n\n/*\n * Login sessions", 'replace' => " return rijndael256_encrypt(\$iv, \$data, \$cipherKey);\n}\n\n/*\n * Login sessions", 'rationale' => 'Encryption passes the key first.'], // Receipt storage helpers (functions.php). @@ -585,12 +584,6 @@ ['id' => 'migration-ignored-outside-sample-unchecked', 'file' => 'migrate-receipt-key.php', 'search' => "array_intersect(\$checked, \$options['ignore-unverified'])", 'replace' => '[]', 'rationale' => 'A file of --ignore-unverified outside the sample is skipped too.'], - ['id' => 'members-padding-kept', 'file' => 'getusers.php', - 'search' => '$decrypted = rtrim(membership_decrypt($datakey, base64_decode($sData)), "\0");', 'replace' => '$decrypted = membership_decrypt($datakey, base64_decode($sData));', - 'rationale' => 'The zero padding is stripped before the lines are parsed.'], - ['id' => 'members-not-base64-decoded', 'file' => 'getusers.php', - 'search' => '$decrypted = rtrim(membership_decrypt($datakey, base64_decode($sData)), "\0");', 'replace' => '$decrypted = rtrim(membership_decrypt($datakey, $sData), "\0");', - 'rationale' => 'The membership system sends base64.'], ['id' => 'export-not-base64', 'file' => 'public/mbapi.php', 'search' => '$encrypted = base64_encode(membership_encrypt($datakey, $text));', 'replace' => '$encrypted = membership_encrypt($datakey, $text);', 'rationale' => 'The export is base64.'], diff --git a/tests/mutation/targets/sql-injection.php b/tests/mutation/targets/sql-injection.php index 4744c9f3..fa6c18da 100644 --- a/tests/mutation/targets/sql-injection.php +++ b/tests/mutation/targets/sql-injection.php @@ -113,8 +113,8 @@ $mutations[] = [ 'id' => 'member-id-raw', 'file' => 'getusers.php', - 'search' => ' $id = intval($values[1]);', - 'replace' => ' $id = $values[1];', + 'search' => '|| !is_int($member[\'id\'] ?? null) || $member[\'id\'] < 1', + 'replace' => '|| !isset($member[\'id\'])', 'rationale' => 'A member id from the membership system is inserted as a number, not as SQL.', ]; diff --git a/tests/php-runtime.Dockerfile b/tests/php-runtime.Dockerfile index dd5bbdb7..27df9ba6 100644 --- a/tests/php-runtime.Dockerfile +++ b/tests/php-runtime.Dockerfile @@ -42,8 +42,9 @@ RUN openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=pgacc synthetic && cat wrongname.crt wrongname.key >wrongname.pem FROM php:8.5-cli@sha256:d5e3f03b94966fd65df52b9819c6dde463003b5a32d032698290a0b37b53bb37 -# The test CA is trusted system-wide (PHP's default CA file), so the -# application verifies the stub's certificate with the default settings. +# The test CA is the members_cafile of tests/runtime/test-sync-secrets.php. +# It is also trusted system-wide, so the tests can show that getusers.php +# trusts members_cafile only (GetUsersTest). COPY --from=membership-tls /tls/ca.pem /usr/local/share/ca-certificates/pgacc-synthetic-test-ca.crt # The stub's certificates: the valid one, and for the verification tests a # self-signed one and a test-CA one for another host name. @@ -63,6 +64,7 @@ WORKDIR /app COPY . ./ COPY --from=dependencies /dependencies/vendor ./vendor COPY tests/runtime/test-constants.php ./constants.php +COPY tests/runtime/test-sync-secrets.php ./sync-secrets.php RUN printf 'date.timezone=UTC\n' >/usr/local/etc/php/conf.d/test-timezone.ini \ && mkdir -p files CMD ["php", "-S", "0.0.0.0:8080", "-t", "/app/public", "/app/tests/runtime/router.php"] diff --git a/tests/reference/compose.yaml b/tests/reference/compose.yaml index 1ae2ff95..9e8b2184 100644 --- a/tests/reference/compose.yaml +++ b/tests/reference/compose.yaml @@ -45,7 +45,7 @@ services: condition: service_healthy # Local membership-system stub (HTTPS, see compose.test.yaml): getusers() - # fetches https://mitglieder.piratenpartei.at/adm_api/adm_names.php, which this alias + # fetches https://mitglieder.piratenpartei.at/members.php, which this alias # resolves to inside the internal test network. membership: image: ${PGACC_REFERENCE_IMAGE:?} diff --git a/tests/reference/membership/adm_names.b64 b/tests/reference/membership/adm_names.b64 deleted file mode 100644 index 32c4f502..00000000 --- a/tests/reference/membership/adm_names.b64 +++ /dev/null @@ -1 +0,0 @@ -8zrpkOyo3DU4nqJysP3ymWaW6QIKlEyCfYw0z6cEqFy36q8m5dShjXC/a4WBOD3AJVDFJc3EOxWAZNkAAkd5WbfXUkFkNSqQlryByIl0VgPijakO7FuzE8LFUDjIHjzEDMN+TF2GUDeukLG9dlKIX/u4ATleW/NWX2INwZPTX9ud88YPuH4J0wYYWPpDBZ6wLTHZrNpw1J3Ef9kMhkLBvvpTh5CRxpAdxaChtkTCmUGePbCYZcT5lF0Gg+o68DIW5qEM7Wdm/6dooRohfu6WJ7PqbRxZHinp+zXhPQABI1NoCi7omWYCTHAu5NjMPWq1/oF85IMv8xc7+3d/JnqF80W5LkW0LRiGq0UrASa2A1Oi+Qt/nMEYD6LE77Gjog9mHAvrte7i3ys/uBlxLGqoKAkOI1/28hUwvRVMjv1KcdcUSVo0D8widCOeLn5lZRpdLmeObxV6vtH6Qjf2AXnX5QwLMyrmI/kVI7LUjzUwF9v+e3pPP5n3onhXMHBZCuqZpw0YkU/eZcCkP++o08+eX+TjeokyGXPAIWotMO5BUWtMK5BninO3FqFAPuRB7CzPKfgx7M/DAkzetvFjOr0WTrIwJ5Y/Mr1xeEIZfgf+mvrwvXyHM8Dvo4tPUKvWR3xyTpXg/+JctGMboesYmCDFGg1yPQLB3Y62HX3ZQWOa+VbUAp4vQLPDxRSiNtHtv2FsUNR74I4aD9iZLFobm36nK6hMa1gP71GraRkZEIwb/BOd0IPTLSSvQfQPIkr9QMTDgKlUttyJZqmffh317ImstZuJoco2J0YtuMKaM+YhFhRvFYo83jrkhCn1w23lAqyqMN+m+35doCkJIzgLZh5bU6pz9IWSPN8aGrJLKGZrb3F2F0W9KF4SxeJ0l8R6G5D1VQghfFfM7R17Oa/p/zZSQFxTiSxXLffJy+hBCykzDJGjYgPM+h3t8yUvnL4m5Kdiw4Jdx6gpByjfuhsRwzvsBjW4rSAZq7oywZcQ6UpO/AJ1xTQtknMQkAn1P5nLz5IqdiU9SnNb0ozSjoSUVxYh+KvjRI6r3VvGP9Gtm0udUdIJxHw1//C8X4QTLc2eHHqFSmd06QaosSJ+jO9vhNCIMIzjHd3Y0Vp/DKOXD6AmUw3LuIfRa5x3zv4QDGwSm5wEqkXtXuqBcdvPi/kCAdJkxpt4NZN5XMR1D/6J5NecWAaHM+abjbx1ychBKSFEKfuneqKdj78Fr+ACSeUbzs4WrbPbM0RyWjDyRMMBmuR0kumgkXnpPpWvcVjonrsxpeHcTYw3u77mlfLr06cj3utMs+6aUOdEkVojQekCIkB7r+MFt63T2zXiICDPA9IiV/N1aKtbN6PaKl/y493lB0NteSQvNgrn5riHfurmQwba2K08CyIzBsjGTVw+nyaViGWzLAKqbp3/iLufZy20U6td4t8D/hHyLdUI4xzFmoLBuH1LeqxolOFJDa0vuA5QbI9//9qNfMNeBilKeghFAhp38w== \ No newline at end of file diff --git a/tests/reference/membership/adm_names.tsv b/tests/reference/membership/adm_names.tsv deleted file mode 100644 index dd1da78a..00000000 --- a/tests/reference/membership/adm_names.tsv +++ /dev/null @@ -1,35 +0,0 @@ -1 9001 Anna Synthetisch-Müller 37 1 -2 9002 Bernd Synthetisch 38 0 -3 9003 Carla Synthetisch 39 0 -4 9004 Dieter Synthetisch 40 1 -5 9005 Emma Synthetisch 41 0 -6 9006 Franz Synthetisch-Müller 42 0 -7 9007 Gerda Synthetisch 43 1 -8 9008 Hannes Synthetisch 44 0 -9 9009 Iris Synthetisch 45 0 -10 9010 Jörg Synthetisch 46 1 -11 9011 Käthe Synthetisch-Müller 37 0 -12 9012 Lukas Synthetisch 38 0 -13 9013 Maria Synthetisch 39 1 -14 9014 Norbert Synthetisch 40 0 -15 9015 Olga Synthetisch 41 0 -16 9016 Paul Synthetisch-Müller 42 1 -17 9017 Rosa Synthetisch 43 0 -18 9018 Stefan Synthetisch 44 0 -19 9019 Theresa Synthetisch 45 1 -20 9020 Ulrich Synthetisch 46 0 -21 9021 Vera Synthetisch-Müller 37 0 -22 9022 Walter Synthetisch 38 1 -23 9023 Xaver Synthetisch 39 0 -24 9024 Yvonne Synthetisch 40 0 -25 9025 Zoë Synthetisch 41 1 -26 9026 Ömer Synthetisch-Müller 42 0 -27 9027 Ännchen Synthetisch 43 0 -28 9028 Ludwig Synthetisch 44 1 -29 9029 Sophie Synthetisch 45 0 -30 9030 Max Synthetisch 46 0 -31 9031 Testa Mitglied 40 1 -32 9032 Mitglied Zweitname 38 0 -33 9033 O'Brien Synthetisch 45 1 -34 9034 Gerlinde Titelträgerin 39 0 -35 9035 Synthetica 42 1 diff --git a/tests/reference/membership/flow.json b/tests/reference/membership/flow.json new file mode 100644 index 00000000..0bbe1d21 --- /dev/null +++ b/tests/reference/membership/flow.json @@ -0,0 +1,34 @@ +[ +{"id": 9101, "uuid": "00000000-0000-4000-8000-000000009101", "name": "Anna Fluss", "lo": 37, "paid": 1}, +{"id": 9102, "uuid": "00000000-0000-4000-8000-000000009102", "name": "Bernd Fluss", "lo": 38, "paid": 0}, +{"id": 9103, "uuid": "00000000-0000-4000-8000-000000009103", "name": "Carla Fluss", "lo": 39, "paid": 1}, +{"id": 9104, "uuid": "00000000-0000-4000-8000-000000009104", "name": "Dieter Fluss", "lo": 40, "paid": 0}, +{"id": 9105, "uuid": "00000000-0000-4000-8000-000000009105", "name": "Emma Fluss", "lo": 41, "paid": 1}, +{"id": 9106, "uuid": "00000000-0000-4000-8000-000000009106", "name": "Franz Fluss", "lo": 42, "paid": 0}, +{"id": 9107, "uuid": "00000000-0000-4000-8000-000000009107", "name": "Gerda Fluss", "lo": 43, "paid": 1}, +{"id": 9108, "uuid": "00000000-0000-4000-8000-000000009108", "name": "Hannes Fluss", "lo": 44, "paid": 0}, +{"id": 9109, "uuid": "00000000-0000-4000-8000-000000009109", "name": "Iris Fluss", "lo": 45, "paid": 1}, +{"id": 9110, "uuid": "00000000-0000-4000-8000-000000009110", "name": "Unbekannt Fluss", "lo": 99, "paid": 0}, +{"id": 9111, "uuid": "00000000-0000-4000-8000-000000009111", "name": "Jürgen Größe-Weiß", "lo": 40, "paid": 1}, +{"id": 9112, "uuid": "00000000-0000-4000-8000-000000009112", "name": "D'Arcy Back\\slash", "lo": 38, "paid": 0}, +{"id": 9120, "uuid": "00000000-0000-4000-8000-000000009120", "name": "Synthetic Flow Filler 00", "lo": null, "paid": 0}, +{"id": 9121, "uuid": "00000000-0000-4000-8000-000000009121", "name": "Synthetic Flow Filler 01", "lo": 40, "paid": 1}, +{"id": 9122, "uuid": "00000000-0000-4000-8000-000000009122", "name": "Synthetic Flow Filler 02", "lo": 40, "paid": 0}, +{"id": 9123, "uuid": "00000000-0000-4000-8000-000000009123", "name": "Synthetic Flow Filler 03", "lo": 40, "paid": 1}, +{"id": 9124, "uuid": "00000000-0000-4000-8000-000000009124", "name": "Synthetic Flow Filler 04", "lo": 40, "paid": 0}, +{"id": 9125, "uuid": "00000000-0000-4000-8000-000000009125", "name": "Synthetic Flow Filler 05", "lo": 40, "paid": 1}, +{"id": 9126, "uuid": "00000000-0000-4000-8000-000000009126", "name": "Synthetic Flow Filler 06", "lo": 40, "paid": 0}, +{"id": 9127, "uuid": "00000000-0000-4000-8000-000000009127", "name": "Synthetic Flow Filler 07", "lo": 40, "paid": 1}, +{"id": 9128, "uuid": "00000000-0000-4000-8000-000000009128", "name": "Synthetic Flow Filler 08", "lo": 40, "paid": 0}, +{"id": 9129, "uuid": "00000000-0000-4000-8000-000000009129", "name": "Synthetic Flow Filler 09", "lo": 40, "paid": 1}, +{"id": 9130, "uuid": "00000000-0000-4000-8000-000000009130", "name": "Synthetic Flow Filler 10", "lo": 40, "paid": 0}, +{"id": 9131, "uuid": "00000000-0000-4000-8000-000000009131", "name": "Synthetic Flow Filler 11", "lo": 40, "paid": 1}, +{"id": 9132, "uuid": "00000000-0000-4000-8000-000000009132", "name": "Synthetic Flow Filler 12", "lo": 40, "paid": 0}, +{"id": 9133, "uuid": "00000000-0000-4000-8000-000000009133", "name": "Synthetic Flow Filler 13", "lo": 40, "paid": 1}, +{"id": 9134, "uuid": "00000000-0000-4000-8000-000000009134", "name": "Synthetic Flow Filler 14", "lo": 40, "paid": 0}, +{"id": 9135, "uuid": "00000000-0000-4000-8000-000000009135", "name": "Synthetic Flow Filler 15", "lo": 40, "paid": 1}, +{"id": 9136, "uuid": "00000000-0000-4000-8000-000000009136", "name": "Synthetic Flow Filler 16", "lo": 40, "paid": 0}, +{"id": 9137, "uuid": "00000000-0000-4000-8000-000000009137", "name": "Synthetic Flow Filler 17", "lo": 40, "paid": 1}, +{"id": 9138, "uuid": "00000000-0000-4000-8000-000000009138", "name": "Synthetic Flow Filler 18", "lo": 40, "paid": 0}, +{"id": 9139, "uuid": "00000000-0000-4000-8000-000000009139", "name": "Synthetic Flow Filler 19", "lo": 40, "paid": 1} +] diff --git a/tests/reference/membership/flow.tsv b/tests/reference/membership/flow.tsv deleted file mode 100644 index 5a619b16..00000000 --- a/tests/reference/membership/flow.tsv +++ /dev/null @@ -1,34 +0,0 @@ -1 9101 Anna Fluss 37 1 -2 9102 Bernd Fluss 38 0 -3 9103 Carla Fluss 39 1 -4 9104 Dieter Fluss 40 0 -5 9105 Emma Fluss 41 1 -6 9106 Franz Fluss 42 0 -7 9107 Gerda Fluss 43 1 -8 9108 Hannes Fluss 44 0 -9 9109 Iris Fluss 45 1 -10 9110 Unbekannt Fluss 99 0 -11 9111 Jürgen Größe-Weiß 40 1 -12 9112 D\'Arcy Back\\slash 38 0 -x 1 -13 9120 Synthetic Flow Filler 00 40 0 -14 9121 Synthetic Flow Filler 01 40 1 -15 9122 Synthetic Flow Filler 02 40 0 -16 9123 Synthetic Flow Filler 03 40 1 -17 9124 Synthetic Flow Filler 04 40 0 -18 9125 Synthetic Flow Filler 05 40 1 -19 9126 Synthetic Flow Filler 06 40 0 -20 9127 Synthetic Flow Filler 07 40 1 -21 9128 Synthetic Flow Filler 08 40 0 -22 9129 Synthetic Flow Filler 09 40 1 -23 9130 Synthetic Flow Filler 10 40 0 -24 9131 Synthetic Flow Filler 11 40 1 -25 9132 Synthetic Flow Filler 12 40 0 -26 9133 Synthetic Flow Filler 13 40 1 -27 9134 Synthetic Flow Filler 14 40 0 -28 9135 Synthetic Flow Filler 15 40 1 -29 9136 Synthetic Flow Filler 16 40 0 -30 9137 Synthetic Flow Filler 17 40 1 -31 9138 Synthetic Flow Filler 18 40 0 -32 9139 Synthetic Flow Filler 19 40 1 - diff --git a/tests/reference/membership/generate.php b/tests/reference/membership/generate.php deleted file mode 100644 index a9301cae..00000000 --- a/tests/reference/membership/generate.php +++ /dev/null @@ -1,32 +0,0 @@ - php /app/tests/reference/membership/generate.php /out - * The output is deterministic (fixed IV), so regenerating it without changing - * adm_names.tsv or the key reproduces the committed file byte for byte. - */ -require '/app/constants.php'; -$out = isset($argv[1]) ? rtrim($argv[1], '/') : __DIR__; -$plain = ''; -foreach (file(__DIR__ . '/adm_names.tsv', FILE_IGNORE_NEW_LINES) as $line) { - $fields = explode("\t", $line); - $fields[2] = iconv('UTF-8', 'ISO-8859-15', $fields[2]); - $plain .= implode("\t", $fields) . "\n"; -} -$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($datakey), $plain, MCRYPT_MODE_CBC, md5(md5($datakey)))); -$check = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($datakey), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($datakey))), "\0"); -if ($check !== $plain || strlen($encrypted) < 1000) { - fwrite(STDERR, "round trip failed or payload shorter than getusers() accepts\n"); - exit(1); -} -file_put_contents($out . '/adm_names.b64', $encrypted); -echo 'wrote ' . strlen($encrypted) . " bytes\n"; diff --git a/tests/reference/membership/members.json b/tests/reference/membership/members.json new file mode 100644 index 00000000..38cfe70c --- /dev/null +++ b/tests/reference/membership/members.json @@ -0,0 +1,37 @@ +[ +{"id": 9001, "uuid": "00000000-0000-4000-8000-000000009001", "name": "Anna Synthetisch-Müller", "lo": 37, "paid": 1}, +{"id": 9002, "uuid": "00000000-0000-4000-8000-000000009002", "name": "Bernd Synthetisch", "lo": 38, "paid": 0}, +{"id": 9003, "uuid": "00000000-0000-4000-8000-000000009003", "name": "Carla Synthetisch", "lo": 39, "paid": 0}, +{"id": 9004, "uuid": "00000000-0000-4000-8000-000000009004", "name": "Dieter Synthetisch", "lo": 40, "paid": 1}, +{"id": 9005, "uuid": "00000000-0000-4000-8000-000000009005", "name": "Emma Synthetisch", "lo": 41, "paid": 0}, +{"id": 9006, "uuid": "00000000-0000-4000-8000-000000009006", "name": "Franz Synthetisch-Müller", "lo": 42, "paid": 0}, +{"id": 9007, "uuid": "00000000-0000-4000-8000-000000009007", "name": "Gerda Synthetisch", "lo": 43, "paid": 1}, +{"id": 9008, "uuid": "00000000-0000-4000-8000-000000009008", "name": "Hannes Synthetisch", "lo": 44, "paid": 0}, +{"id": 9009, "uuid": "00000000-0000-4000-8000-000000009009", "name": "Iris Synthetisch", "lo": 45, "paid": 0}, +{"id": 9010, "uuid": "00000000-0000-4000-8000-000000009010", "name": "Jörg Synthetisch", "lo": 46, "paid": 1}, +{"id": 9011, "uuid": "00000000-0000-4000-8000-000000009011", "name": "Käthe Synthetisch-Müller", "lo": 37, "paid": 0}, +{"id": 9012, "uuid": "00000000-0000-4000-8000-000000009012", "name": "Lukas Synthetisch", "lo": 38, "paid": 0}, +{"id": 9013, "uuid": "00000000-0000-4000-8000-000000009013", "name": "Maria Synthetisch", "lo": 39, "paid": 1}, +{"id": 9014, "uuid": "00000000-0000-4000-8000-000000009014", "name": "Norbert Synthetisch", "lo": 40, "paid": 0}, +{"id": 9015, "uuid": "00000000-0000-4000-8000-000000009015", "name": "Olga Synthetisch", "lo": 41, "paid": 0}, +{"id": 9016, "uuid": "00000000-0000-4000-8000-000000009016", "name": "Paul Synthetisch-Müller", "lo": 42, "paid": 1}, +{"id": 9017, "uuid": "00000000-0000-4000-8000-000000009017", "name": "Rosa Synthetisch", "lo": 43, "paid": 0}, +{"id": 9018, "uuid": "00000000-0000-4000-8000-000000009018", "name": "Stefan Synthetisch", "lo": 44, "paid": 0}, +{"id": 9019, "uuid": "00000000-0000-4000-8000-000000009019", "name": "Theresa Synthetisch", "lo": 45, "paid": 1}, +{"id": 9020, "uuid": "00000000-0000-4000-8000-000000009020", "name": "Ulrich Synthetisch", "lo": 46, "paid": 0}, +{"id": 9021, "uuid": "00000000-0000-4000-8000-000000009021", "name": "Vera Synthetisch-Müller", "lo": 37, "paid": 0}, +{"id": 9022, "uuid": "00000000-0000-4000-8000-000000009022", "name": "Walter Synthetisch", "lo": 38, "paid": 1}, +{"id": 9023, "uuid": "00000000-0000-4000-8000-000000009023", "name": "Xaver Synthetisch", "lo": 39, "paid": 0}, +{"id": 9024, "uuid": "00000000-0000-4000-8000-000000009024", "name": "Yvonne Synthetisch", "lo": 40, "paid": 0}, +{"id": 9025, "uuid": "00000000-0000-4000-8000-000000009025", "name": "Zoë Synthetisch", "lo": 41, "paid": 1}, +{"id": 9026, "uuid": "00000000-0000-4000-8000-000000009026", "name": "Ömer Synthetisch-Müller", "lo": 42, "paid": 0}, +{"id": 9027, "uuid": "00000000-0000-4000-8000-000000009027", "name": "Ännchen Synthetisch", "lo": 43, "paid": 0}, +{"id": 9028, "uuid": "00000000-0000-4000-8000-000000009028", "name": "Ludwig Synthetisch", "lo": 44, "paid": 1}, +{"id": 9029, "uuid": "00000000-0000-4000-8000-000000009029", "name": "Sophie Synthetisch", "lo": 45, "paid": 0}, +{"id": 9030, "uuid": "00000000-0000-4000-8000-000000009030", "name": "Max Synthetisch", "lo": 46, "paid": 0}, +{"id": 9031, "uuid": "00000000-0000-4000-8000-000000009031", "name": "Testa Mitglied", "lo": 40, "paid": 1}, +{"id": 9032, "uuid": "00000000-0000-4000-8000-000000009032", "name": "Mitglied Zweitname", "lo": 38, "paid": 0}, +{"id": 9033, "uuid": "00000000-0000-4000-8000-000000009033", "name": "O'Brien Synthetisch", "lo": 45, "paid": 1}, +{"id": 9034, "uuid": "00000000-0000-4000-8000-000000009034", "name": "Gerlinde Titelträgerin", "lo": 39, "paid": 0}, +{"id": 9035, "uuid": "00000000-0000-4000-8000-000000009035", "name": "Synthetica", "lo": 42, "paid": 1} +] diff --git a/tests/reference/membership/server.php b/tests/reference/membership/server.php index cb6e648f..87773767 100644 --- a/tests/reference/membership/server.php +++ b/tests/reference/membership/server.php @@ -3,26 +3,29 @@ /* * Local stand-in for the membership system (lane and reference runs). The * compose network alias mitglieder.piratenpartei.at points at this server, - * so getusers() never reaches the real service. It speaks HTTPS on port 443 + * so getusers() never reaches a real service. It speaks HTTPS on port 443 * with the synthetic server certificate that tests/php-runtime.Dockerfile - * generates per build, signed by a test CA that the same image trusts, so the - * application verifies it with PHP's default settings. Port 80 (plain HTTP) - * serves only the test controls below. One request per connection, one - * connection at a time. + * generates per build, signed by a test CA; the members_cafile of the test + * configuration (tests/runtime/test-sync-secrets.php) is that CA. Port 80 + * (plain HTTP) serves only the test controls below. One request per + * connection, one connection at a time. * - * GET https://.../adm_api/adm_names.php serves the synthetic, encrypted - * member list (adm_names.b64) and is logged to PGACC_REFERENCE_STUB_LOG, so - * the recorder can prove where getusers() went. The tests switch the - * response with GET http://.../__stub/mode?set= (port 80, not logged): + * GET https://.../members.php with "Authorization: Bearer " serves the synthetic member list (members.json, + * the format of the membership system's internal/members.php); without that + * token it answers 403 with an empty body. Requests to it are logged to + * PGACC_REFERENCE_STUB_LOG, so the recorder can prove where getusers() went. + * The tests switch the response with GET http://.../__stub/mode?set= + * (port 80, not logged): * ok the member list (default) - * short the first 200 bytes of it - * garbage 1,536 bytes of base64 that decrypt to noise (wrong key or - * damaged data) - * empty a list encrypted like adm_names.b64 (key: $datakey of the - * image's constants.php) whose lines are all too short - * flow flow.tsv, encrypted the same way (GetUsersTest) - * overflow flow.tsv plus a member id out of the integer range, so the - * INSERT fails after DROP and CREATE + * malformed a body that is not JSON + * empty an empty list ([]) + * invalid-row the member list with one row without its uuid + * duplicate the member list with its first member twice + * bad-uuid the member list with a uuid that is not a UUID + * flow flow.json (GetUsersTest) + * overflow flow.json plus a member id out of the integer range, so the + * INSERT fails after DELETE * body the body last sent with POST http://.../__stub/body * (which also selects this mode; the unit tests) * redirect 302 to https://mitglieder.piratenpartei.at/__stub/list @@ -33,19 +36,10 @@ * /__stub/list serves the member list on both ports (the redirect targets) * and counts its requests: GET http://.../__stub/list-requests answers the * count since the last mode switch, so the tests can prove that no redirect - * was followed. GET http://.../__stub/names-requests counts the member-list - * requests (adm_names.php) the same way, so the tests can prove that a - * refused save did not fetch the list. /__stub/health answers 200 for the - * health check; anything - * else is 404. - * - * Response format, as getusers.php reads it (inferred from the code, never - * from a real sample): base64 of Rijndael-256/CBC ciphertext, key - * md5($datakey), IV md5(md5($datakey)), zero (NUL) padding to 32 bytes. The - * plain text is lines separated by "\n"; each line is tab-separated fields - * [0] (unused), [1] member id, [2] name in ISO-8859-15 with backslash - * escapes (stripslashes()), [3] organization code (lo), [4] paid (0/1). - * Lines shorter than 5 bytes (such as an empty last line) are skipped. + * was followed. GET http://.../__stub/members-requests counts the + * member-list requests (members.php) the same way, so the tests can prove + * that a refused save did not fetch the list. /__stub/health answers 200 for + * the health check; anything else is 404. */ $https = stream_socket_server('tcp://0.0.0.0:443', $errno, $errstr); $http = $https === false ? false : stream_socket_server('tcp://0.0.0.0:80', $errno, $errstr); @@ -56,44 +50,36 @@ $modeFile = '/tmp/pgacc-membership-stub-mode'; $bodyFile = '/tmp/pgacc-membership-stub-body'; $listRequestsFile = '/tmp/pgacc-membership-stub-list-requests'; -$namesRequestsFile = '/tmp/pgacc-membership-stub-names-requests'; -$modes = ['ok', 'short', 'garbage', 'empty', 'flow', 'overflow', 'body', 'redirect', 'redirect-http', - 'selfsigned', 'wrongname', 'error']; +$membersRequestsFile = '/tmp/pgacc-membership-stub-members-requests'; +$modes = ['ok', 'malformed', 'empty', 'invalid-row', 'duplicate', 'bad-uuid', 'flow', 'overflow', 'body', + 'redirect', 'redirect-http', 'selfsigned', 'wrongname', 'error']; +$membersToken = (require '/app/tests/runtime/test-sync-secrets.php')['members_token']; $certificates = [ 'selfsigned' => '/etc/pgacc-test-tls/selfsigned.pem', 'wrongname' => '/etc/pgacc-test-tls/wrongname.pem', ]; -// As membership_encrypt() of functions.php: Rijndael-256/CBC, key -// md5($datakey), IV md5(md5($datakey)), zero padding. -function membership_stub_encrypt($plain) +function membership_stub_mode($modeFile) { - require_once '/app/vendor/autoload.php'; - require '/app/constants.php'; - $cipher = new \phpseclib\Crypt\Rijndael(\phpseclib\Crypt\Base::MODE_CBC); - $cipher->setBlockLength(256); - $cipher->setKey(md5($datakey)); - $cipher->setIV(md5(md5($datakey))); - $cipher->disablePadding(); - $length = max(1, intval(ceil(strlen($plain) / 32))) * 32; - return base64_encode($cipher->encrypt(str_pad($plain, $length, "\0"))); + return is_file($modeFile) ? file_get_contents($modeFile) : 'ok'; } -function membership_stub_mode($modeFile) +// The list $members as JSON, as the membership system sends it. +function membership_stub_json($members) { - return is_file($modeFile) ? file_get_contents($modeFile) : 'ok'; + return json_encode($members, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } -function membership_stub_response($secure, $method, $uri, $body, $modeFile, $bodyFile, $modes) +function membership_stub_response($secure, $method, $uri, $authorization, $body, $modeFile, $bodyFile, $modes) { - global $listRequestsFile, $namesRequestsFile; + global $listRequestsFile, $membersRequestsFile, $membersToken; $path = parse_url($uri, PHP_URL_PATH); if ($path === '/__stub/health') { return ['200 OK', "ok\n"]; } if ($path === '/__stub/list') { file_put_contents($listRequestsFile, "x", FILE_APPEND); - return ['200 OK', file_get_contents(__DIR__ . '/adm_names.b64')]; + return ['200 OK', file_get_contents(__DIR__ . '/members.json')]; } if (!$secure) { if ($path === '/__stub/mode') { @@ -104,16 +90,16 @@ function membership_stub_response($secure, $method, $uri, $body, $modeFile, $bod } file_put_contents($modeFile, $mode); @unlink($listRequestsFile); - @unlink($namesRequestsFile); + @unlink($membersRequestsFile); return ['200 OK', "mode $mode\n"]; } if ($path === '/__stub/list-requests') { clearstatcache(); return ['200 OK', (is_file($listRequestsFile) ? filesize($listRequestsFile) : 0) . "\n"]; } - if ($path === '/__stub/names-requests') { + if ($path === '/__stub/members-requests') { clearstatcache(); - return ['200 OK', (is_file($namesRequestsFile) ? filesize($namesRequestsFile) : 0) . "\n"]; + return ['200 OK', (is_file($membersRequestsFile) ? filesize($membersRequestsFile) : 0) . "\n"]; } if ($path === '/__stub/body' && $method === 'POST') { file_put_contents($bodyFile, $body); @@ -122,30 +108,36 @@ function membership_stub_response($secure, $method, $uri, $body, $modeFile, $bod } return ['404 Not Found', "not found\n"]; } - if ($path !== '/adm_api/adm_names.php') { + if ($path !== '/members.php') { return ['404 Not Found', "not found\n"]; } - file_put_contents($namesRequestsFile, "x", FILE_APPEND); - $list = file_get_contents(__DIR__ . '/adm_names.b64'); + file_put_contents($membersRequestsFile, "x", FILE_APPEND); + if (!hash_equals('Bearer ' . $membersToken, $authorization)) { + return ['403 Forbidden', '']; + } + $members = json_decode(file_get_contents(__DIR__ . '/members.json'), true); switch (membership_stub_mode($modeFile)) { - case 'short': - return ['200 OK', substr($list, 0, 200)]; - case 'garbage': - $bytes = ''; - for ($i = 0; strlen($bytes) < 1536; $i++) { - $bytes .= hash('sha256', "pgacc synthetic garbage $i", true); - } - return ['200 OK', base64_encode($bytes)]; + case 'malformed': + return ['200 OK', '[{"id": 9001, "uuid": ']; case 'empty': - return ['200 OK', membership_stub_encrypt(str_repeat("abc\n", 300))]; + return ['200 OK', '[]']; + case 'invalid-row': + unset($members[1]['uuid']); + return ['200 OK', membership_stub_json($members)]; + case 'duplicate': + $members[] = $members[0]; + return ['200 OK', membership_stub_json($members)]; + case 'bad-uuid': + $members[1]['uuid'] = 'javascript:alert(1)'; + return ['200 OK', membership_stub_json($members)]; case 'flow': case 'overflow': - // flow.tsv is UTF-8; the membership system sends ISO-8859-15. - $plain = iconv('UTF-8', 'ISO-8859-15', file_get_contents(__DIR__ . '/flow.tsv')); + $flow = json_decode(file_get_contents(__DIR__ . '/flow.json'), true); if (membership_stub_mode($modeFile) === 'overflow') { - $plain .= "99\t99999999999\tSynthetic Overflow Member\t40\t0\n"; + $flow[] = ['id' => 99999999999, 'uuid' => '00000000-0000-4000-8000-099999999999', + 'name' => 'Synthetic Overflow Member', 'lo' => 40, 'paid' => 0]; } - return ['200 OK', membership_stub_encrypt($plain)]; + return ['200 OK', membership_stub_json($flow)]; case 'body': return ['200 OK', (string) @file_get_contents($bodyFile)]; case 'redirect': @@ -155,7 +147,7 @@ function membership_stub_response($secure, $method, $uri, $body, $modeFile, $bod case 'error': return ['500 Internal Server Error', "synthetic failure\n"]; default: - return ['200 OK', $list]; + return ['200 OK', file_get_contents(__DIR__ . '/members.json')]; } } @@ -185,9 +177,12 @@ function membership_stub_response($secure, $method, $uri, $body, $modeFile, $bod } $requestLine = (string) fgets($client); $length = 0; + $authorization = ''; while (($header = fgets($client)) !== false && rtrim($header, "\r\n") !== '') { if (stripos($header, 'Content-Length:') === 0) { $length = intval(trim(substr($header, 15))); + } elseif (stripos($header, 'Authorization:') === 0) { + $authorization = trim(substr($header, 14)); } } $body = ''; @@ -205,7 +200,7 @@ function membership_stub_response($secure, $method, $uri, $body, $modeFile, $bod if ($pgaccStubLog !== false && $pgaccStubLog !== '' && strpos($uri, '/__stub/') !== 0) { file_put_contents($pgaccStubLog, $method . ' ' . $uri . "\n", FILE_APPEND | LOCK_EX); } - list($status, $responseBody) = membership_stub_response($secure, $method, $uri, $body, $modeFile, $bodyFile, $modes); + list($status, $responseBody) = membership_stub_response($secure, $method, $uri, $authorization, $body, $modeFile, $bodyFile, $modes); @fwrite($client, "HTTP/1.0 $status\r\nContent-Type: text/plain\r\nContent-Length: " . strlen($responseBody) . "\r\nConnection: close\r\n\r\n" . $responseBody); @fclose($client); diff --git a/tests/reference/php85/http/edit-view-with-receipt.txt b/tests/reference/php85/http/edit-view-with-receipt.txt index b327f501..2875bf23 100644 --- a/tests/reference/php85/http/edit-view-with-receipt.txt +++ b/tests/reference/php85/http/edit-view-with-receipt.txt @@ -2,7 +2,7 @@ # request: GET /index.php?action=edit&id=5001 as admin status: 200 header: Content-type: text/html; charset=UTF-8 ---- body (24047 bytes) --- +--- body (23923 bytes) --- @@ -242,7 +242,7 @@ function merge()
- · In MV öffnen + · Nr. 9001
diff --git a/tests/reference/php85/http/mb-admin.txt b/tests/reference/php85/http/mb-admin.txt index 421fd4c0..07634fab 100644 --- a/tests/reference/php85/http/mb-admin.txt +++ b/tests/reference/php85/http/mb-admin.txt @@ -2,7 +2,7 @@ # request: GET /index.php?action=mb as admin status: 200 header: Content-type: text/html; charset=UTF-8 ---- body (10725 bytes) --- +--- body (11167 bytes) --- @@ -28,55 +28,55 @@ header: Content-type: text/html; charset=UTF-8 Virt. Konten
ErfassenImportBelege ImportOffenAbgeschlossenAllesMitgliedsbeiträgeKontenAlte Rev.Benutzer

MB Zahlungen nach LO

TeilorganisationAnzahlSummeDurchschnitt
Synthetic Regional Unit239.99 €20.00 €
Synthetic Unit Nine124.00 €24.00 €
Summe363.99 €21.33 €

MB Zahlungen nach Konto

Konto der TeilorganisationSumme
Synthetic Federal Unit20.00 €
Synthetic Regional Unit43.99 €

Inkonsistenzen bei Zahlungsstatus

- + - + - + - + - + - + - + - + - + - + - +
#MemberNameAmountPaid
19004 (Buchungszeilen)9004 (Buchungszeilen) Dieter Synthetisch 19.99 1
29007 (Buchungszeilen)9007 (Buchungszeilen) Gerda Synthetisch 0 1
39010 (Buchungszeilen)9010 (Buchungszeilen) Jörg Synthetisch 0 1
49013 (Buchungszeilen)9013 (Buchungszeilen) Maria Synthetisch 0 1
59016 (Buchungszeilen)9016 (Buchungszeilen) Paul Synthetisch-Müller 0 1
69019 (Buchungszeilen)9019 (Buchungszeilen) Theresa Synthetisch 0 1
79022 (Buchungszeilen)9022 (Buchungszeilen) Walter Synthetisch 0 1
89025 (Buchungszeilen)9025 (Buchungszeilen) Zoë Synthetisch 0 1
99028 (Buchungszeilen)9028 (Buchungszeilen) Ludwig Synthetisch 0 1
109033 (Buchungszeilen)9033 (Buchungszeilen) O'Brien Synthetisch 0 1
119035 (Buchungszeilen)9035 (Buchungszeilen) Synthetica 0 1

Mitglieder mit konsistentem Zahlungsstatus

- + - +
#MemberNameAmountPaid
19001 (Buchungszeilen)9001 (Buchungszeilen) Anna Synthetisch-Müller 24 1
29031 (Buchungszeilen)9031 (Buchungszeilen) Testa Mitglied 20 1

Offene Darlehen

VoucherAmountName
diff --git a/tests/reference/php85/membership-stub.txt b/tests/reference/php85/membership-stub.txt index df006b9a..0ad92af9 100644 --- a/tests/reference/php85/membership-stub.txt +++ b/tests/reference/php85/membership-stub.txt @@ -1,11 +1,11 @@ # requests received by the local membership stub -GET /adm_api/adm_names.php -GET /adm_api/adm_names.php -GET /adm_api/adm_names.php -GET /adm_api/adm_names.php -GET /adm_api/adm_names.php -GET /adm_api/adm_names.php -GET /adm_api/adm_names.php -GET /adm_api/adm_names.php -GET /adm_api/adm_names.php -GET /adm_api/adm_names.php +GET /members.php +GET /members.php +GET /members.php +GET /members.php +GET /members.php +GET /members.php +GET /members.php +GET /members.php +GET /members.php +GET /members.php diff --git a/tests/reference/php85/sql/import-bawag-again.sql b/tests/reference/php85/sql/import-bawag-again.sql index c399d414..bdbcd1ff 100644 --- a/tests/reference/php85/sql/import-bawag-again.sql +++ b/tests/reference/php85/sql/import-bawag-again.sql @@ -40,11 +40,11 @@ SELECT * FROM users WHERE id = 1 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/php85/sql/import-bawag.sql b/tests/reference/php85/sql/import-bawag.sql index 8597cd45..f61cae6b 100644 --- a/tests/reference/php85/sql/import-bawag.sql +++ b/tests/reference/php85/sql/import-bawag.sql @@ -40,11 +40,11 @@ SELECT * FROM users WHERE id = 1 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/php85/sql/import-form-unitone.sql b/tests/reference/php85/sql/import-form-unitone.sql index df05968b..03b09268 100644 --- a/tests/reference/php85/sql/import-form-unitone.sql +++ b/tests/reference/php85/sql/import-form-unitone.sql @@ -38,11 +38,11 @@ SELECT * FROM users WHERE id = 3 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/php85/sql/import-form.sql b/tests/reference/php85/sql/import-form.sql index 1b014aa4..e056eed3 100644 --- a/tests/reference/php85/sql/import-form.sql +++ b/tests/reference/php85/sql/import-form.sql @@ -38,11 +38,11 @@ SELECT * FROM users WHERE id = 1 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/php85/sql/import-latin9-handkassa.sql b/tests/reference/php85/sql/import-latin9-handkassa.sql index 4c05fa26..26eb5ea5 100644 --- a/tests/reference/php85/sql/import-latin9-handkassa.sql +++ b/tests/reference/php85/sql/import-latin9-handkassa.sql @@ -40,11 +40,11 @@ SELECT * FROM users WHERE id = 1 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/php85/sql/import-paypal.sql b/tests/reference/php85/sql/import-paypal.sql index cd92ce59..f54617df 100644 --- a/tests/reference/php85/sql/import-paypal.sql +++ b/tests/reference/php85/sql/import-paypal.sql @@ -40,11 +40,11 @@ SELECT * FROM users WHERE id = 1 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/php85/sql/import-rejected-files.sql b/tests/reference/php85/sql/import-rejected-files.sql index 90f66d5e..e681665b 100644 --- a/tests/reference/php85/sql/import-rejected-files.sql +++ b/tests/reference/php85/sql/import-rejected-files.sql @@ -40,11 +40,11 @@ SELECT * FROM users WHERE id = 1 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/php85/sql/import-sparkasse.sql b/tests/reference/php85/sql/import-sparkasse.sql index f53ce71b..921fc595 100644 --- a/tests/reference/php85/sql/import-sparkasse.sql +++ b/tests/reference/php85/sql/import-sparkasse.sql @@ -40,11 +40,11 @@ SELECT * FROM users WHERE id = 1 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/php85/sql/import-unknown-account.sql b/tests/reference/php85/sql/import-unknown-account.sql index ea906f05..43625bbb 100644 --- a/tests/reference/php85/sql/import-unknown-account.sql +++ b/tests/reference/php85/sql/import-unknown-account.sql @@ -40,11 +40,11 @@ SELECT * FROM users WHERE id = 1 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/php85/sql/mb-admin.sql b/tests/reference/php85/sql/mb-admin.sql index 19f178fc..f859062c 100644 --- a/tests/reference/php85/sql/mb-admin.sql +++ b/tests/reference/php85/sql/mb-admin.sql @@ -38,11 +38,11 @@ SELECT * FROM users WHERE id = 1 AND login > now() - '24 hours'::interval -- next BEGIN; -- next -CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; +CREATE TEMP TABLE IF NOT EXISTS ppmembers (id integer, uuid text, name text, lo integer, paid integer) ON COMMIT PRESERVE ROWS; -- next DELETE FROM pg_temp.ppmembers; -- next -INSERT INTO pg_temp.ppmembers (id, name, lo, paid) VALUES (9001,'Anna Synthetisch-Müller',9,1),(9002,'Bernd Synthetisch',1,0),(9003,'Carla Synthetisch',3,0),(9004,'Dieter Synthetisch',2,1),(9005,'Emma Synthetisch',4,0),(9006,'Franz Synthetisch-Müller',5,0),(9007,'Gerda Synthetisch',6,1),(9008,'Hannes Synthetisch',10,0),(9009,'Iris Synthetisch',8,0),(9010,'Jörg Synthetisch',10,1),(9011,'Käthe Synthetisch-Müller',9,0),(9012,'Lukas Synthetisch',1,0),(9013,'Maria Synthetisch',3,1),(9014,'Norbert Synthetisch',2,0),(9015,'Olga Synthetisch',4,0),(9016,'Paul Synthetisch-Müller',5,1),(9017,'Rosa Synthetisch',6,0),(9018,'Stefan Synthetisch',10,0),(9019,'Theresa Synthetisch',8,1),(9020,'Ulrich Synthetisch',10,0),(9021,'Vera Synthetisch-Müller',9,0),(9022,'Walter Synthetisch',1,1),(9023,'Xaver Synthetisch',3,0),(9024,'Yvonne Synthetisch',2,0),(9025,'Zoë Synthetisch',4,1),(9026,'Ömer Synthetisch-Müller',5,0),(9027,'Ännchen Synthetisch',6,0),(9028,'Ludwig Synthetisch',10,1),(9029,'Sophie Synthetisch',8,0),(9030,'Max Synthetisch',10,0),(9031,'Testa Mitglied',2,1),(9032,'Mitglied Zweitname',1,0),(9033,'O''Brien Synthetisch',8,1),(9034,'Gerlinde Titelträgerin',3,0),(9035,'Synthetica',5,1); +INSERT INTO pg_temp.ppmembers (id, uuid, name, lo, paid) VALUES (9001,'00000000-0000-4000-8000-000000009001','Anna Synthetisch-Müller',9,1),(9002,'00000000-0000-4000-8000-000000009002','Bernd Synthetisch',1,0),(9003,'00000000-0000-4000-8000-000000009003','Carla Synthetisch',3,0),(9004,'00000000-0000-4000-8000-000000009004','Dieter Synthetisch',2,1),(9005,'00000000-0000-4000-8000-000000009005','Emma Synthetisch',4,0),(9006,'00000000-0000-4000-8000-000000009006','Franz Synthetisch-Müller',5,0),(9007,'00000000-0000-4000-8000-000000009007','Gerda Synthetisch',6,1),(9008,'00000000-0000-4000-8000-000000009008','Hannes Synthetisch',10,0),(9009,'00000000-0000-4000-8000-000000009009','Iris Synthetisch',8,0),(9010,'00000000-0000-4000-8000-000000009010','Jörg Synthetisch',10,1),(9011,'00000000-0000-4000-8000-000000009011','Käthe Synthetisch-Müller',9,0),(9012,'00000000-0000-4000-8000-000000009012','Lukas Synthetisch',1,0),(9013,'00000000-0000-4000-8000-000000009013','Maria Synthetisch',3,1),(9014,'00000000-0000-4000-8000-000000009014','Norbert Synthetisch',2,0),(9015,'00000000-0000-4000-8000-000000009015','Olga Synthetisch',4,0),(9016,'00000000-0000-4000-8000-000000009016','Paul Synthetisch-Müller',5,1),(9017,'00000000-0000-4000-8000-000000009017','Rosa Synthetisch',6,0),(9018,'00000000-0000-4000-8000-000000009018','Stefan Synthetisch',10,0),(9019,'00000000-0000-4000-8000-000000009019','Theresa Synthetisch',8,1),(9020,'00000000-0000-4000-8000-000000009020','Ulrich Synthetisch',10,0),(9021,'00000000-0000-4000-8000-000000009021','Vera Synthetisch-Müller',9,0),(9022,'00000000-0000-4000-8000-000000009022','Walter Synthetisch',1,1),(9023,'00000000-0000-4000-8000-000000009023','Xaver Synthetisch',3,0),(9024,'00000000-0000-4000-8000-000000009024','Yvonne Synthetisch',2,0),(9025,'00000000-0000-4000-8000-000000009025','Zoë Synthetisch',4,1),(9026,'00000000-0000-4000-8000-000000009026','Ömer Synthetisch-Müller',5,0),(9027,'00000000-0000-4000-8000-000000009027','Ännchen Synthetisch',6,0),(9028,'00000000-0000-4000-8000-000000009028','Ludwig Synthetisch',10,1),(9029,'00000000-0000-4000-8000-000000009029','Sophie Synthetisch',8,0),(9030,'00000000-0000-4000-8000-000000009030','Max Synthetisch',10,0),(9031,'00000000-0000-4000-8000-000000009031','Testa Mitglied',2,1),(9032,'00000000-0000-4000-8000-000000009032','Mitglied Zweitname',1,0),(9033,'00000000-0000-4000-8000-000000009033','O''Brien Synthetisch',8,1),(9034,'00000000-0000-4000-8000-000000009034','Gerlinde Titelträgerin',3,0),(9035,'00000000-0000-4000-8000-000000009035','Synthetica',5,1); -- next COMMIT; -- next diff --git a/tests/reference/runtime/reference-constants.php b/tests/reference/runtime/reference-constants.php index b0f52362..e223ae15 100644 --- a/tests/reference/runtime/reference-constants.php +++ b/tests/reference/runtime/reference-constants.php @@ -1,8 +1,7 @@ decrypt( - rijndael256_zero_pad(base64_decode($vector['sData'])), - ), "\0"); - if (bin2hex($plain) !== $vector['decrypted']) { - pgacc_vendor_check_fail("getusers vector '{$vector['name']}' differs"); - } - $checked++; -} echo "vendor: phpseclib: $checked mcrypt contract vectors match\n"; // The calls of import2.php on a one-page statement with one text line. diff --git a/tests/runtime/test-constants.php b/tests/runtime/test-constants.php index 0e658c46..137ba725 100644 --- a/tests/runtime/test-constants.php +++ b/tests/runtime/test-constants.php @@ -1,6 +1,6 @@ 'https://mitglieder.piratenpartei.at/members.php', + 'members_token' => 'synthetic-test-only-members-token', + 'members_cafile' => '/usr/local/share/ca-certificates/pgacc-synthetic-test-ca.crt', +]; diff --git a/tests/unit/CryptoTest.php b/tests/unit/CryptoTest.php index fdaf72c8..7a869d51 100644 --- a/tests/unit/CryptoTest.php +++ b/tests/unit/CryptoTest.php @@ -5,7 +5,7 @@ * padding) in functions.php. The expected bytes in * tests/fixtures/mcrypt/vectors.json were produced by the real mcrypt * extension (see tests/fixtures/mcrypt/generate-vectors.php), so existing - * receipt files and the membership-system exchange stay readable. + * receipt files and the membership export stay readable. */ final class CryptoTest extends FunctionsTestCase @@ -35,11 +35,6 @@ public static function mbapiProvider() return self::vectors('mbapi'); } - public static function getusersProvider() - { - return self::vectors('getusers'); - } - #[PHPUnit\Framework\Attributes\DataProvider('receiptProvider')] public function testReceiptEncryptionMatchesMcrypt(array $vector) { @@ -86,19 +81,6 @@ public function testMembershipExportFramingMatchesMcrypt(array $vector) ); } - #[PHPUnit\Framework\Attributes\DataProvider('getusersProvider')] - public function testMembershipImportMatchesMcrypt(array $vector) - { - // getusers.php: base64 ciphertext in, zero padding stripped with rtrim(). - self::assertSame( - $vector['decrypted'], - bin2hex(rtrim(membership_decrypt($vector['datakey'], base64_decode($vector['sData'])), "\0")), - ); - $padded = membership_decrypt($vector['datakey'], base64_decode($vector['sData'])); - self::assertSame(0, strlen($padded) % 32); - self::assertSame(hex2bin($vector['plain']), substr($padded, 0, strlen($vector['plain']) / 2)); - } - public function testBlockSizeIs256Bits() { // Rijndael with a 256-bit block, not AES (128-bit block): the IV is a diff --git a/tests/unit/GetUsersTest.php b/tests/unit/GetUsersTest.php index 0fff5885..692af7eb 100644 --- a/tests/unit/GetUsersTest.php +++ b/tests/unit/GetUsersTest.php @@ -3,163 +3,240 @@ /* * getUsers() (getusers.php) against synthetic membership-system responses, * served by the membership stub of compose.test.yaml over verified HTTPS - * (MembershipStub), so the live membership system is never contacted. The ppmembers table is rebuilt - * inside a transaction that is rolled back. + * (MembershipStub), so no membership system is contacted. The settings come + * from sync-secrets.php (tests/runtime/test-sync-secrets.php). The ppmembers + * table is rebuilt inside a transaction that is rolled back. */ require_once dirname(dirname(__DIR__)) . '/getusers.php'; +require_once dirname(dirname(__DIR__)) . '/mb.php'; require_once __DIR__ . '/AppExitGuard.php'; require_once __DIR__ . '/MembershipStub.php'; final class GetUsersTest extends FunctionsTestCase { - public function testImportsTheDecryptedMemberList() + // getUsers() in a transaction that is rolled back: [its result, the rows + // of ppmembers or null if there is no table, the transaction status]. + private static function load($file = 'sync-secrets.php') { - $vectors = json_decode(file_get_contents(dirname(__DIR__) . '/fixtures/mcrypt/vectors.json'), true); - $vector = $vectors['getusers'][0]; - self::assertSame('getUsers() export', $vector['name']); - - $datakey = isset($GLOBALS['datakey']) ? $GLOBALS['datakey'] : null; - $GLOBALS['datakey'] = $vector['datakey']; - MembershipStub::serve($vector['sData']); // pg_connect() returns the default link that the application code uses. $connection = pg_connect(pgacc_test_connection_string()); pg_query($connection, 'BEGIN'); try { - // getUsers() returns null, or the error (a short response, an - // empty key, an SQL error); the guard fails on an exit. AppExitGuard::enter('getUsers()'); - self::assertNull(getUsers()); - // Inside the test's transaction getUsers() uses a savepoint and - // leaves the transaction open. + $error = getUsers($file); + AppExitGuard::leave(); $status = pg_transaction_status($connection); - $result = pg_query($connection, 'SELECT id, name, lo, paid FROM ppmembers ORDER BY id'); - $rows = pg_fetch_all($result); - pg_free_result($result); + $result = @pg_query($connection, 'SELECT id, uuid, name, lo, paid FROM ppmembers ORDER BY id'); + $rows = $result === false ? null : pg_fetch_all($result); } finally { - // die() skips finally blocks, so this only runs when the call returned. - AppExitGuard::leave(); MembershipStub::reset(); pg_query($connection, 'ROLLBACK'); - $GLOBALS['datakey'] = $datakey; } + return [$error, $rows, $status]; + } - self::assertSame(PGSQL_TRANSACTION_INTRANS, $status); - self::assertCount(32, $rows); - self::assertSame(['id' => '2001', 'name' => 'Synthetic Member 00', 'lo' => '9', 'paid' => '0'], $rows[0]); - $organizations = []; - foreach (array_slice($rows, 0, 10) as $row) { - $organizations[] = $row['lo']; - } - // Membership-system codes 37-45 and an unknown code (99). - self::assertSame(['9', '1', '3', '2', '4', '5', '6', '10', '8', '10'], $organizations); - self::assertSame(['id' => '2030', 'name' => 'Synthetic Member 29', 'lo' => '10', 'paid' => '1'], $rows[29]); - // stripslashes() and ISO-8859-15 to UTF-8. - self::assertSame(['id' => '2031', 'name' => "O'Synthetic \xE2\x82\xACuro", 'lo' => '1', 'paid' => '1'], $rows[30]); - // The last line before the zero padding, which rtrim() removes. - self::assertSame(['id' => '2032', 'name' => 'Last Synthetic', 'lo' => '2', 'paid' => '0'], $rows[31]); + private static function uuid($id) + { + return sprintf('00000000-0000-4000-8000-%012d', $id); } public function testImportsTheStubListOverHttps() { - // The whole flow: getUsers() fetches the stub's "flow" list (tests/reference/membership/flow.tsv, - // format in server.php) over verified HTTPS, decrypts and parses it. - // Needs the membership stub of compose.test.yaml. - $datakey = isset($GLOBALS['datakey']) ? $GLOBALS['datakey'] : null; - // The stub's key (tests/runtime/test-constants.php). - $GLOBALS['datakey'] = 'synthetic-reference-membership-key'; + // The whole flow: getUsers() fetches the stub's "flow" list + // (tests/reference/membership/flow.json) over verified HTTPS with + // the token and loads it. MembershipStub::mode('flow'); - $connection = pg_connect(pgacc_test_connection_string()); - pg_query($connection, 'BEGIN'); - try { - AppExitGuard::enter('getUsers()'); - getUsers(); - $result = pg_query($connection, 'SELECT id, name, lo, paid FROM ppmembers ORDER BY id'); - $rows = pg_fetch_all($result); - pg_free_result($result); - } finally { - AppExitGuard::leave(); - pg_query($connection, 'ROLLBACK'); - MembershipStub::reset(); - $GLOBALS['datakey'] = $datakey; - } + [$error, $rows, $status] = self::load(); + self::assertNull($error); + // Inside the test's transaction getUsers() uses a savepoint and + // leaves the transaction open. + self::assertSame(PGSQL_TRANSACTION_INTRANS, $status); $expected = [ - // Every organization code of the mapping, and an unknown one (99). - ['9101', 'Anna Fluss', '9', '1'], - ['9102', 'Bernd Fluss', '1', '0'], - ['9103', 'Carla Fluss', '3', '1'], - ['9104', 'Dieter Fluss', '2', '0'], - ['9105', 'Emma Fluss', '4', '1'], - ['9106', 'Franz Fluss', '5', '0'], - ['9107', 'Gerda Fluss', '6', '1'], - ['9108', 'Hannes Fluss', '10', '0'], - ['9109', 'Iris Fluss', '8', '1'], - ['9110', 'Unbekannt Fluss', '10', '0'], - // ISO-8859-15 umlauts and sharp s, converted to UTF-8. - ['9111', "J\xC3\xBCrgen Gr\xC3\xB6\xC3\x9Fe-Wei\xC3\x9F", '2', '1'], - // stripslashes(): \' and \\ in the list become ' and \. - ['9112', "D'Arcy Back\\slash", '1', '0'], + // Every organization role of the mapping, and an unknown one (99). + [9101, 'Anna Fluss', '9', '1'], + [9102, 'Bernd Fluss', '1', '0'], + [9103, 'Carla Fluss', '3', '1'], + [9104, 'Dieter Fluss', '2', '0'], + [9105, 'Emma Fluss', '4', '1'], + [9106, 'Franz Fluss', '5', '0'], + [9107, 'Gerda Fluss', '6', '1'], + [9108, 'Hannes Fluss', '10', '0'], + [9109, 'Iris Fluss', '8', '1'], + [9110, 'Unbekannt Fluss', '10', '0'], + // UTF-8 names as sent, quotes and backslashes unchanged. + [9111, "J\xC3\xBCrgen Gr\xC3\xB6\xC3\x9Fe-Wei\xC3\x9F", '2', '1'], + [9112, "D'Arcy Back\\slash", '1', '0'], ]; - // The short line "x1" and the empty last line are skipped. for ($i = 0; $i < 20; $i++) { - $expected[] = [(string) (9120 + $i), sprintf('Synthetic Flow Filler %02d', $i), '2', (string) ($i % 2)]; + // Filler 00 has no organization role (lo null). + $expected[] = [9120 + $i, sprintf('Synthetic Flow Filler %02d', $i), $i === 0 ? '10' : '2', (string) ($i % 2)]; } - foreach ($expected as $index => $row) { - $expected[$index] = array_combine(['id', 'name', 'lo', 'paid'], $row); + foreach ($expected as $index => [$id, $name, $lo, $paid]) { + $expected[$index] = ['id' => (string) $id, 'uuid' => self::uuid($id), 'name' => $name, 'lo' => $lo, 'paid' => $paid]; } self::assertSame($expected, $rows); } - public function testMemberIdsAreNumbers() + public function testUuidsAreStoredInLowerCase() { - // A member id that is not a number (second-order input from the - // membership system) is inserted as intval(), not as SQL. - $datakey = 'synthetic-getusers-test-key'; - $plain = "1\t2101 OR 1=1\tSynthetic Odd Id\t38\t1\n"; - for ($i = 2; $i < 40; $i++) { - $plain .= "$i\t" . (2100 + $i) . "\tSynthetic Padding Member $i\t40\t0\n"; - } - $rows = self::importMembers($datakey, base64_encode(membership_encrypt($datakey, $plain))); - self::assertCount(39, $rows); - self::assertSame(['id' => '2101', 'name' => 'Synthetic Odd Id', 'lo' => '1', 'paid' => '1'], $rows[0]); + MembershipStub::serve('[{"id": 2101, "uuid": "ABCDEF01-2345-4678-9ABC-DEF012345678", "name": "Synthetic Upper", "lo": 38, "paid": 1}]'); + [$error, $rows] = self::load(); + self::assertNull($error); + self::assertSame([['id' => '2101', 'uuid' => 'abcdef01-2345-4678-9abc-def012345678', 'name' => 'Synthetic Upper', 'lo' => '1', 'paid' => '1']], $rows); } - public function testWithoutAKeyTheErrorIsReturned() + public static function invalidListProvider() { - // No die(): the caller decides (the pages stop, a voucher save refuses). - $datakey = isset($GLOBALS['datakey']) ? $GLOBALS['datakey'] : null; - $GLOBALS['datakey'] = ''; - MembershipStub::mode('ok'); + $row = '{"id": 2101, "uuid": "00000000-0000-4000-8000-000000002101", "name": "Synthetic A", "lo": 38, "paid": 1}'; + $other = '{"id": 2102, "uuid": "00000000-0000-4000-8000-000000002102", "name": "Synthetic B", "lo": null, "paid": 0}'; + $with = fn($search, $replace) => "[$other," . str_replace($search, $replace, $row) . ']'; + return [ + 'not JSON' => ["[$row"], + 'an object' => ['{"members": []}'], + 'empty list' => ['[]'], + 'a row that is no object' => ["[$other, 2101]"], + 'a string id (no SQL)' => [$with('"id": 2101', '"id": "2101 OR 1=1"')], + 'id 0' => [$with('"id": 2101', '"id": 0')], + 'duplicate id' => [$with('"id": 2101', '"id": 2102')], + 'duplicate uuid' => [$with('000000002101', '000000002102')], + 'no uuid' => [$with('"uuid": "00000000-0000-4000-8000-000000002101", ', '')], + 'uuid not a UUID' => [$with('00000000-0000-4000-8000-000000002101', 'javascript:alert(1)')], + 'uuid with a trailing newline' => [$with('000000002101"', '000000002101\n"')], + 'uuid with a quote' => [$with('000000002101"', '00000000210\""')], + 'name not a string' => [$with('"name": "Synthetic A"', '"name": 7')], + 'name with a NUL byte' => [$with('"name": "Synthetic A"', '"name": "Synthetic\u0000A"')], + 'no lo' => [$with('"lo": 38, ', '')], + 'lo a string' => [$with('"lo": 38', '"lo": "38"')], + 'paid 2' => [$with('"paid": 1', '"paid": 2')], + 'paid true' => [$with('"paid": 1', '"paid": true')], + 'an extra field' => [$with('"paid": 1', '"paid": 1, "email": "a@example.org"')], + ]; + } + + // Any malformed row refuses the whole list: the previous list of the + // connection stays (here: none was loaded, so there is no table). + #[PHPUnit\Framework\Attributes\DataProvider('invalidListProvider')] + public function testAnInvalidListIsRefused($body) + { + MembershipStub::serve($body); + [$error, $rows] = self::load(); + self::assertSame('Daten von Mitgliederverwaltung ungültig!', $error); + self::assertNull($rows); + } + + public static function refusedFetchProvider() + { + return [ + // The stub's own test-CA certificate is not for another name. + 'certificate for another name' => ['wrongname', null], + 'self-signed certificate' => ['selfsigned', null], + 'HTTP 500' => ['error', null], + 'redirect' => ['redirect', null], + // The stub's certificate is signed by a CA that the system trusts, + // but members_cafile is another certificate: only that one counts. + 'certificate not from members_cafile' => ['ok', ['members_cafile' => '/etc/pgacc-test-tls/selfsigned.pem']], + 'another token (403)' => ['ok', ['members_token' => 'synthetic-wrong-token']], + ]; + } + + #[PHPUnit\Framework\Attributes\DataProvider('refusedFetchProvider')] + public function testARefusedFetchFailsClosed($mode, $settings) + { + $config = getusers_config('sync-secrets.php'); + self::assertNotNull($config); + MembershipStub::mode($mode); try { - AppExitGuard::enter('getUsers()'); - $error = getUsers(); + $body = getusers_fetch(array_merge($config, $settings ?? [])); } finally { - AppExitGuard::leave(); MembershipStub::reset(); - $GLOBALS['datakey'] = $datakey; } - self::assertSame('Kein Passwort!', $error); + self::assertNull($body); } - private static function importMembers($key, $response) + public function testTheMembersCafileIsTheTrustAnchor() { - $datakey = isset($GLOBALS['datakey']) ? $GLOBALS['datakey'] : null; - $GLOBALS['datakey'] = $key; - MembershipStub::serve($response); - $connection = pg_connect(pgacc_test_connection_string()); - pg_query($connection, 'BEGIN'); + // The self-signed certificate of the stub is accepted when it is the + // members_cafile (as in production: the membership system's own + // certificate), with the token. + $config = getusers_config('sync-secrets.php'); + MembershipStub::mode('selfsigned'); try { - AppExitGuard::enter('getUsers()'); - getUsers(); - $result = pg_query($connection, 'SELECT id, name, lo, paid FROM ppmembers ORDER BY id'); - $rows = pg_fetch_all($result); - pg_free_result($result); + $body = getusers_fetch(array_merge($config, ['members_cafile' => '/etc/pgacc-test-tls/selfsigned.pem'])); } finally { - AppExitGuard::leave(); MembershipStub::reset(); - pg_query($connection, 'ROLLBACK'); - $GLOBALS['datakey'] = $datakey; } - return $rows; + self::assertSame(file_get_contents(dirname(__DIR__) . '/reference/membership/members.json'), $body); + } + + public static function configProvider() + { + $valid = ['members_url' => 'https://members.invalid/members.php', 'members_token' => 't', 'members_cafile' => '/c.crt']; + return [ + 'valid' => [$valid, true], + 'http URL' => [array_merge($valid, ['members_url' => 'http://members.invalid/members.php']), false], + 'upper-case scheme' => [array_merge($valid, ['members_url' => 'HTTPS://members.invalid/members.php']), false], + 'empty URL' => [array_merge($valid, ['members_url' => '']), false], + 'empty token' => [array_merge($valid, ['members_token' => '']), false], + 'no token' => [array_diff_key($valid, ['members_token' => 1]), false], + 'no cafile' => [array_diff_key($valid, ['members_cafile' => 1]), false], + 'cafile not a string' => [array_merge($valid, ['members_cafile' => ['/c.crt']]), false], + 'not an array' => [1, false], + ]; + } + + #[PHPUnit\Framework\Attributes\DataProvider('configProvider')] + public function testConfiguration($config, $accepted) + { + $file = tempnam(sys_get_temp_dir(), 'pgacc-sync-secrets'); + file_put_contents($file, ' ['0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d', true], + 'upper case' => ['0A1B2C3D-4E5F-4A6B-8C7D-9E0F1A2B3C4D', true], + 'too short' => ['0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4', false], + 'no dashes' => ['0a1b2c3d4e5f4a6b8c7d9e0f1a2b3c4d', false], + 'not hex' => ['0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4g', false], + 'trailing newline' => ["0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d\n", false], + 'markup' => ['">', false], + 'null' => [null, false], + 'integer' => [12, false], + ]; + } + + #[PHPUnit\Framework\Attributes\DataProvider('uuidProvider')] + public function testUuidValidation($uuid, $valid) + { + self::assertSame($valid, member_uuid_valid($uuid)); + } + + public function testMemberLinksUseTheUuid() + { + // Admidio opens profiles by user_uuid only; an id alone would open + // the viewer's own profile. + self::assertSame( + '9001', + mb_member_link('9001', '00000000-0000-4000-8000-000000009001'), + ); + // Not a UUID: the id as text, no link. + self::assertSame('9002', mb_member_link('9002', '">')); + self::assertSame('9003', mb_member_link('9003', null)); + self::assertSame('0', mb_member_link('x', null)); } } diff --git a/tests/unit/ImportMemberMatchTest.php b/tests/unit/ImportMemberMatchTest.php index 78f6250b..94794004 100644 --- a/tests/unit/ImportMemberMatchTest.php +++ b/tests/unit/ImportMemberMatchTest.php @@ -20,14 +20,13 @@ final class ImportMemberMatchTest extends FunctionsTestCase */ private static function importAgainstMember($memberName, $text) { - $key = 'synthetic-import-member-key'; // Padding members have spaces in their names; the import compares the // line without spaces, so they never match. - $plain = "1\t7101\t$memberName\t38\t1\n"; + $members = [[7101, $memberName, 38, 1]]; for ($i = 2; $i < 40; $i++) { - $plain .= "$i\t" . (7100 + $i) . "\tPadding Member $i\t40\t0\n"; + $members[] = [7100 + $i, "Padding Member $i", 40, 0]; } - MembershipStub::serve(base64_encode(membership_encrypt($key, $plain))); + MembershipStub::serveMembers($members); $csv = "Datum;Betrag;Konto;Text;Kommentar;Fremdkonto;Zweckwidmung;Kostenrückerstattung;Name;Mitgliedsnummer;Lo;Adresse;PLZ;Stadt\r\n" . "05.04.2024;5,00;Handkassa;$text;;;Nein;Nein;;0;1;;;\r\n"; $path = tempnam(sys_get_temp_dir(), 'pgacc-import'); @@ -39,8 +38,6 @@ private static function importAgainstMember($memberName, $text) 'error' => [0], 'size' => [strlen($csv)], ]]; - $datakey = isset($GLOBALS['datakey']) ? $GLOBALS['datakey'] : null; - $GLOBALS['datakey'] = $key; $connection = pg_connect(pgacc_test_connection_string()); pg_query($connection, 'BEGIN'); $diagnostics = []; @@ -61,7 +58,6 @@ private static function importAgainstMember($memberName, $text) restore_error_handler(); MembershipStub::reset(); pg_query($connection, 'ROLLBACK'); - $GLOBALS['datakey'] = $datakey; $_FILES = []; unlink($path); } @@ -74,12 +70,11 @@ private static function importAgainstMember($memberName, $text) // type with an upload error, so only a constructed upload reaches it. public function testUploadErrorShowsTheEncodedFileName() { - $key = 'synthetic-import-member-key'; - $plain = ''; + $members = []; for ($i = 1; $i < 40; $i++) { - $plain .= "$i\t" . (7100 + $i) . "\tPadding Member $i\t40\t0\n"; + $members[] = [7100 + $i, "Padding Member $i", 40, 0]; } - MembershipStub::serve(base64_encode(membership_encrypt($key, $plain))); + MembershipStub::serveMembers($members); $_FILES = ['uploadcsv' => [ 'name' => ['a&b.csv'], 'type' => ['text/csv'], @@ -87,8 +82,6 @@ public function testUploadErrorShowsTheEncodedFileName() 'error' => [UPLOAD_ERR_PARTIAL], 'size' => [100], ]]; - $datakey = isset($GLOBALS['datakey']) ? $GLOBALS['datakey'] : null; - $GLOBALS['datakey'] = $key; $connection = pg_connect(pgacc_test_connection_string()); pg_query($connection, 'BEGIN'); ob_start(); @@ -100,7 +93,6 @@ public function testUploadErrorShowsTheEncodedFileName() $output = ob_get_clean(); MembershipStub::reset(); pg_query($connection, 'ROLLBACK'); - $GLOBALS['datakey'] = $datakey; $_FILES = []; } self::assertStringContainsString('Datei 1 (<i>a&b</i>.csv) wurde nicht erfolgreich hochgeladen', $output); @@ -129,7 +121,7 @@ public static function wildcardMemberProvider() return [ 'percent sign' => ['%', 'Spende Synthetic'], 'underscore' => ['A_B', 'Spende AxB'], - 'backslash' => ['A\\\\', 'Spende Ab'], + 'backslash' => ['A\\', 'Spende Ab'], 'empty name' => ['', 'Spende Synthetic'], ]; } diff --git a/tests/unit/MembershipStub.php b/tests/unit/MembershipStub.php index 73f344e9..0cce7d02 100644 --- a/tests/unit/MembershipStub.php +++ b/tests/unit/MembershipStub.php @@ -16,6 +16,17 @@ private static function control($path, $context = null) return $answer; } + // Serves the members [[id, name, lo, paid], ...] as the membership + // system's JSON list (uuid derived from the id) until reset(). + public static function serveMembers(array $members) + { + $list = []; + foreach ($members as [$id, $name, $lo, $paid]) { + $list[] = ['id' => $id, 'uuid' => sprintf('00000000-0000-4000-8000-%012d', $id), 'name' => $name, 'lo' => $lo, 'paid' => $paid]; + } + self::serve(json_encode($list)); + } + // Serves $body as the member list until reset(). public static function serve($body) { From 2986640f968ea59ee540e0b5e2dc3b041b427384 Mon Sep 17 00:00:00 2001 From: PeterTheOne Date: Sun, 1 Nov 2026 03:31:02 +0100 Subject: [PATCH 2/8] Count unit-test coverage of mb.php mb.php was not in the phpunit coverage source, so the non-UUID branch of mb_member_link(), exercised by GetUsersTest, did not count and the changed-line coverage gate reported mb.php line 10 as uncovered. No behaviour change. Co-Authored-By: Claude Opus 5.5 --- phpunit.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml b/phpunit.xml index 6556149e..39074a40 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -51,6 +51,7 @@ import.php import2.php kdonations.php + mb.php migrate-receipt-key.php new.php wk.php From 759f28aebc919094b3be32997492c653e5ca31d4 Mon Sep 17 00:00:00 2001 From: PeterTheOne Date: Sun, 1 Nov 2026 03:57:40 +0100 Subject: [PATCH 3/8] sync-secrets.php from the inventory; 4 MiB cap; broken file fails closed Align the consumer side with the sync v2 cross-review: - One template task writes shared/sync-secrets.php from the inventory on every run (templates/sync-secrets.php.j2, root:pgacc 0640, no_log), replacing the "create if missing" shell task and the lineinfile loop. The template and the task are the same in the provider branch: the members_* keys while pgacc_members_url is set, the payments_* keys of the internal sync listener while it is on. - getusers_fetch(): fopen + stream_get_contents(4 MiB + 1), refused when larger or when the read timed out (same shape as accsync_fetch on the membership side). The stub gets a "stall" mode for the timeout test. - A sync-secrets.php that does not load (parse error, exception) fails closed with "Mitgliederliste nicht konfiguriert!" instead of a fatal error; only the class is logged. - The membership system's certificate is /etc/pgacc/admidio-addons-tls.crt (/etc//-tls.crt, as on the membership side). - The member list asserts move to their own task; the certificate tasks to their own section, so the two branches merge without conflicts in the playbook. - Docs: one "Sync v2" CHANGELOG entry and UPGRADING section, the certificate path convention, pgacc_timezone Europe/Vienna recommended. - tests/runtime/test-sync-secrets.php holds the payments_* and members_* test keys (same file in the provider branch). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 47 ++++++---- UPGRADING.md | 78 +++++++++++------ deploy/README.md | 58 ++++++++++--- deploy/ansible/inventory.example.yml | 14 +-- deploy/ansible/playbook.yml | 90 +++++++++----------- deploy/ansible/templates/sync-secrets.php.j2 | 19 +++++ deploy/deploy.sh | 2 +- getusers.php | 50 ++++++++--- tests/README.md | 8 +- tests/http-import.php | 2 +- tests/mutation/targets/import-checks.php | 32 ++++++- tests/reference/membership/server.php | 15 +++- tests/runtime/test-sync-secrets.php | 17 ++-- tests/unit/GetUsersTest.php | 68 +++++++++++++++ 14 files changed, 361 insertions(+), 139 deletions(-) create mode 100644 deploy/ansible/templates/sync-secrets.php.j2 diff --git a/CHANGELOG.md b/CHANGELOG.md index e2a1144e..7b09b51c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,26 +5,39 @@ on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] -### Changed - -- **Behaviour change**: the member list (`getusers.php`; the member-fee page, - the bank import, saving a member voucher) comes from the membership - system's `members.php` as JSON over its internal TLS listener instead of - the encrypted `adm_names.php` of the old membership system. New - configuration file `sync-secrets.php` (release root, like - `constants.php`) with `members_url` (https only), `members_token` (sent as - `Authorization: Bearer`) and `members_cafile` (the only trust anchor); - with `deploy/` the variables `pgacc_members_url`, `pgacc_members_token` - and `pgacc_members_cert` (empty by default, so the member list is off and - those pages fail with "Mitgliederliste nicht konfiguriert!"), and - `pgacc-deploy` links `shared/sync-secrets.php` into each release. The - fetch requires a verified certificate, no redirect and HTTP 200, and +### Sync v2 (membership sync) + +The data exchange with the membership system is replaced (sync v2): two +read-only JSON endpoints, called directly between the two hosts over TLS +with one token per direction and the caller's address checked, instead of +the encrypted exports of the old membership system. Both directions are +configured in the new file `sync-secrets.php` (release root, like +`constants.php`; a file that does not load counts as missing); with +`deploy/` the playbook writes `shared/sync-secrets.php` from the inventory +on every run (changes on the host are overwritten) and `pgacc-deploy` +links it into each release. Recommended: `pgacc_timezone: Europe/Vienna`. +See [UPGRADING.md](UPGRADING.md), "Sync v2 (membership sync)". + +- **Behaviour change**: the member list (`getusers.php`; the member-fee + page, the bank import, saving a member voucher) comes from the + membership system's `members.php` as JSON over its internal TLS listener + instead of the encrypted `adm_names.php` of the old membership system. + Settings in `sync-secrets.php`: `members_url` (https only), + `members_token` (sent as `Authorization: Bearer`) and `members_cafile` + (the only trust anchor); with `deploy/` the variables + `pgacc_members_url`, `pgacc_members_token` (64 hex characters, the same + as on the membership system) and `pgacc_members_cert` (written to + `/etc/pgacc/admidio-addons-tls.crt`), empty by default, so the member + list is off and those pages fail with "Mitgliederliste nicht + konfiguriert!". The fetch requires a verified certificate, no redirect, + HTTP 200 and a complete body of at most 4 MiB within 20 seconds, and refuses the whole list if a row is malformed or a member id or uuid appears twice (fail closed as before). The member list stores each member's uuid; the member-fee page links profiles by `user_uuid`, the - ledger listing and the voucher form show the member id as text instead of - a link. `membership_decrypt()` is removed. See - [UPGRADING.md](UPGRADING.md), "Member list from the membership system". + ledger listing and the voucher form show the member id as text instead + of a link. `membership_decrypt()` is removed. + +### Changed - **Deployment change** (for the next major release): the web server's document root is now `public/` of the release, not the release root diff --git a/UPGRADING.md b/UPGRADING.md index efc04c16..34d5e379 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -9,39 +9,69 @@ verifies, unpacks and activates the archive, with a smoke test and automatic rollback ([deploy/README.md](deploy/README.md)). It does not run the manual steps below (pgacc has no database migrations); do them as described. -## Member list from the membership system (`getusers.php`) - -**Behaviour change.** `getusers.php` (the member-fee page, the bank import, -saving a voucher with a member part) no longer fetches the encrypted -`adm_api/adm_names.php` of the old membership system (shut down). It fetches -the JSON member list of the membership system's `members.php` over its -internal TLS listener, with a token, and needs three settings in the new -configuration file `sync-secrets.php` (release root, outside the document -root, readable by PHP but not writable, like `constants.php`; with `deploy/` the -inventory variables `pgacc_members_url`, `pgacc_members_token`, -`pgacc_members_cert`, see [deploy/README.md](deploy/README.md), "Member -list"): +## Sync v2 (membership sync) + +The data exchange with the membership system is replaced: two read-only +JSON endpoints, called directly between the two hosts over TLS (not through +the reverse proxy), with one token per direction and the caller's address +checked, instead of the encrypted exports of the old membership system. +The membership system's side is in the add-ons for it (`members.php`, +`accsync.php`). + +Both directions are configured in `sync-secrets.php` in the release root +(outside the document roots; with `deploy/` a link to +`shared/sync-secrets.php`, like `constants.php`), readable by PHP but not +writable (`root:`, mode 0640). It returns an array with the +keys of the directions below; a direction without its keys refuses or +fails closed, and so does a file that does not load (a syntax error): ```php 'https://192.0.2.20:8443/members.php', // https only - 'members_token' => '<64 hex characters, the same as on the membership system>', - 'members_cafile' => '/etc/pgacc/members-tls.crt', // its certificate, the only trust anchor + // internal/mbapi.php (payments for the membership system) + 'payments_token' => '<64 hex characters>', + 'payments_peers' => ['192.0.2.20'], + // getusers.php (member list from the membership system) + 'members_url' => 'https://192.0.2.20:8443/members.php', + 'members_token' => '<64 hex characters>', + 'members_cafile' => '/etc/pgacc/admidio-addons-tls.crt', ]; ``` -- Without them the pages that need the list stop with "Mitgliederliste - nicht konfiguriert!" (fail closed, as for any failed fetch). +Each token is made once (`openssl rand -hex 32`) and the same value goes +into the membership system's secrets file of that direction +(`accsync-secrets.php` for the payments, `members-secrets.php` for the +member list). With `deploy/` the playbook writes `shared/sync-secrets.php` +from the inventory on every run (changes on the host are overwritten); see +[deploy/README.md](deploy/README.md), "Membership system". Recommended: +`pgacc_timezone: Europe/Vienna` (same section). + +### Member list from the membership system (`getusers.php`) + +**Behaviour change.** `getusers.php` (the member-fee page, the bank import, +saving a voucher with a member part) no longer fetches the encrypted +`adm_api/adm_names.php` of the old membership system (shut down). It fetches +the JSON member list of the membership system's `members.php` over its +internal TLS listener, with a token. Settings in `sync-secrets.php` (above): +`members_url` (https only), `members_token` and `members_cafile` (the +membership system's certificate, the only trust anchor); with `deploy/` the +inventory variables `pgacc_members_url`, `pgacc_members_token` and +`pgacc_members_cert`, see [deploy/README.md](deploy/README.md), "Member +list". + +- Without them, or if `sync-secrets.php` does not load, the pages that need + the list stop with "Mitgliederliste nicht konfiguriert!" (fail closed, as + for any failed fetch). - The fetch verifies the certificate and its name or address against `members_cafile` only, sends `Authorization: Bearer `, follows no - redirects, times out after 20 seconds and needs HTTP 200. The list must be - valid as a whole (`[{"id": int, "uuid": string, "name": string, "lo": - int|null, "paid": 0|1}]`, exactly these fields, a positive id and a UUID - per member, none twice); otherwise "Daten von Mitgliederverwaltung - ungültig!" and nothing is loaded. Names are UTF-8 as sent (no more - ISO-8859-15 conversion or backslash unescaping). `lo` is mapped to the - organizations as before (44 and unknown roles or none: 10). + redirects, times out after 20 seconds and needs HTTP 200 with a complete + body of at most 4 MiB. The list must be valid as a whole + (`[{"id": int, "uuid": string, "name": string, "lo": int|null, "paid": 0|1}]`, + exactly these fields, a positive id and a UUID per member, none twice); + otherwise "Daten von Mitgliederverwaltung ungültig!" and nothing is + loaded. Names are UTF-8 as sent (no more ISO-8859-15 conversion or + backslash unescaping). `lo` is mapped to the organizations as before (44 + and unknown roles or none: 10). - The member list now also holds each member's `uuid`. The member-fee page links a member's profile by `user_uuid` (the membership system opens profiles by uuid only); the ledger listing and the voucher form show the diff --git a/deploy/README.md b/deploy/README.md index 8bf1c310..733f3cb0 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -43,13 +43,13 @@ Settings (inventory variables, see | Variable | Default | | | --- | --- | --- | | `pgacc_trusted_proxies` | none, required | Addresses or CIDR ranges of the TLS-terminating reverse proxy. | -| `pgacc_timezone` | `UTC` | PHP `date.timezone`. | +| `pgacc_timezone` | `UTC` | PHP `date.timezone`. With the membership sync: `Europe/Vienna` (see "Membership system"). | | `pgacc_backup_keep_days` | `7` | Days the nightly dumps are kept. | | `pgacc_disable_sshd` | `true` | Stops and disables the SSH server (`ssh.service`, `ssh.socket`): the host is administered through the container runtime. Set it to `false` if Ansible connects over SSH to the host itself. | -| `pgacc_extra_hosts` | `[]` | Entries for `/etc/hosts` (list of `{ip, names}`), kept in a block marked by Ansible; see "Membership system". Nothing is written while the list is empty. | | `pgacc_members_url` | `''` (off) | URL of the membership system's member list (`https://:/members.php`; see "Member list"). Empty: no member list, so the member-fee page, the bank import and saving member vouchers fail with "Mitgliederliste nicht konfiguriert!". | | `pgacc_members_token` | `''` | The token for that URL (64 hex characters, `openssl rand -hex 32`, the same as on the membership system); required with `pgacc_members_url`. Keep it in a vault. | -| `pgacc_members_cert` | `''` | The membership system's listener certificate (PEM), written to `/etc/pgacc/members-tls.crt`: the only trust anchor of the fetch; required with `pgacc_members_url`. | +| `pgacc_members_cert` | `''` | The membership system's listener certificate (PEM), written to `/etc/pgacc/admidio-addons-tls.crt`: the only trust anchor of the fetch; required with `pgacc_members_url`. | +| `pgacc_extra_hosts` | `[]` | Entries for `/etc/hosts` (list of `{ip, names}`), kept in a block marked by Ansible; see "Membership system". Nothing is written while the list is empty. | | `pgacc_fresh_install` | `false` | Pass `-e pgacc_fresh_install=true` once to create the database (see below). | Defaults: time zone UTC and dumps kept 7 days (the settings above); uploads @@ -63,7 +63,7 @@ What it sets up: | Users | `pgacc` runs PHP (the PHP-FPM pool) and is the database role. `pgacc-deploy` owns the releases and may run `systemctl reload php8.5-fpm.service` with sudo, nothing else. Both are system users without a login shell. | | Layout | `/srv/pgacc/releases/v/` and the symlink `/srv/pgacc/current` belong to `pgacc-deploy`; PHP can read them but not write. `/srv/pgacc/shared/files/` (receipts) belongs to `pgacc` (mode 0700). `/srv/pgacc/shared/constants.php` is `root:pgacc` 0640: PHP reads it, nobody but root writes it. PHP errors go to `/var/log/pgacc/php-error.log` (rotated weekly). | | `constants.php` | Created only if there is none, with a random `$key` and a random placeholder `$datakey` (replace it with the key shared with the membership system). The playbook prints a notice when it creates one. An existing file is never changed (only its owner and mode). | -| Sync settings | `/srv/pgacc/shared/sync-secrets.php` (`root:pgacc` 0640), created if there is none; on every run its member list settings are set from `pgacc_members_url` and `pgacc_members_token` (`members_cafile`: `/etc/pgacc/members-tls.crt` from `pgacc_members_cert`; all empty while `pgacc_members_url` is empty, and the certificate removed). | +| Sync settings | `/srv/pgacc/shared/sync-secrets.php` (`root:pgacc` 0640), written from the inventory on every run (see "Membership system"); `/etc/pgacc` holds the certificates of the sync. | | PHP-FPM | Pool `pgacc` (socket `/run/php/pgacc-fpm.sock`, `display_errors` off, errors logged); Debian's default pool `www` is removed. `90-pgacc.ini`: `expose_php` off, `cgi.fix_pathinfo=0`, time zone, 20M uploads, 256M memory. `allow_url_fopen` stays on (Debian's default): `getusers.php` fetches the member list over HTTPS. Reloaded only when this configuration changes. | | nginx | Port 80, `server_name _`, document root `/srv/pgacc/current/public` (only `public/` is served; the code, `constants.php` and `files/` are in the release root, see [UPGRADING.md](../UPGRADING.md), "Document root `public/`"), PHP with the resolved release path (`$realpath_root`) and `SERVER_NAME` set to the request's `Host` (the proxy must pass the public host name; `index.php` redirects to it). The short page addresses the application links to (`/donations`, `/kdonations`, `/spendings`, `/wk`, `/transactions`, `/vreport`, `/tinyreport`, each with an optional query string) are rewritten to `index.php?action=`. Only the trusted proxies and the host itself may connect, so `X-Forwarded-Proto` is trusted only from them. Allow list: only `/`, `index.php`, `mbapi.php`, `style.css`, `js/*.js`, `icons/*.png` and the short page addresses are served, anything else answers 404; as a second line of defence dot files and backup, editor and dump copies (names ending in `~`, `.bak`, `.orig`, `.save`, `.swp`, `.sql`, `.tar.gz` and the like, or with something after `.php`, such as `constants.php.bak`) answer 403. Caching: the static files (`style.css`, `js/*.js`, `icons/*.png`) get `Cache-Control: no-cache`, so browsers revalidate them on every use (ETag/`Last-Modified`, a 304 if unchanged) and pick up a deploy on the next page view; the asset URLs are not versioned yet. PHP responses get `Cache-Control: private, no-store` unless the application sets its own Cache-Control, which is kept (the application sets none at present); pages after login hold personal and financial data. The default site is disabled. | | Database | PostgreSQL 18 with the `en_US.UTF-8` locale generated (the collation of the existing installation). A normal run never creates or changes a database. Only with `-e pgacc_fresh_install=true`: role `pgacc` (peer authentication over the local socket, no password) and the database `accounting` owned by it (UTF-8, `en_US.UTF-8`), with `pgcrypto` and [tests/fixtures/schema.sql](../tests/fixtures/schema.sql); `CONNECT` revoked from `PUBLIC`. It refuses if `accounting` exists already, with or without tables. | @@ -249,6 +249,37 @@ pgacc_extra_hosts: - { ip: 192.0.2.1, names: [members.example.org] } ``` +### Sync v2 settings (`sync-secrets.php`) + +Both directions of the membership sync (sync v2) are set in the inventory. +The playbook writes `/srv/pgacc/shared/sync-secrets.php` from it on every +run (template `templates/sync-secrets.php.j2`; changes on the host are +overwritten), and `pgacc-deploy` links it into each release. It holds the +`payments_*` keys while the internal sync listener is on and the +`members_*` keys while the member list is set; a direction without its +keys refuses (`internal/mbapi.php`: 403) or fails closed (`getusers.php`). +Format: [UPGRADING.md](../UPGRADING.md), "Sync v2 (membership sync)". + +Tokens: one per direction, 64 hex characters, made once with +`openssl rand -hex 32`; keep it in a vault, and put the same value into the +membership system's secrets file of that direction. A new token: change it +in both inventories and run both playbooks. + +Certificates: each side's own certificate is `/etc//sync-tls.{crt,key}`, +self-signed by the side that is called (subject alternative name: the +address in the caller's URL); the caller keeps the peer's certificate as +`/etc//-tls.crt`, handed over through the inventory. On this +host: `/etc/pgacc/sync-tls.{crt,key}` (the internal sync listener) and +`/etc/pgacc/admidio-addons-tls.crt` (the membership system's listener, for +the member list). + +Time zone: set `pgacc_timezone: Europe/Vienna`, the membership system's. +`internal/mbapi.php` sends "paid until 31 December" of PHP's current year +(`date('Y')`), while the membership system compares "paid until" with its +database's current date. With PHP on UTC the two years differ for the +hours between the two New Years. That is harmless, as the membership +system only moves "paid until" forward, but avoidable. + ### Member list (`getusers.php`) The member-fee page, the bank import and saving a voucher with a member part @@ -261,22 +292,27 @@ the inventory (the token in a vault): ```yaml pgacc_members_url: https://192.0.2.20:8443/members.php # its internal address -pgacc_members_token: "<64 hex characters, the same as on the membership system>" +pgacc_members_token: "{{ vault_pgacc_members_token }}" # openssl rand -hex 32, once pgacc_members_cert: | # its listener certificate -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- ``` +The playbook writes the certificate to `/etc/pgacc/admidio-addons-tls.crt` +(`members_cafile`; removed while `pgacc_members_url` is empty) and the +token into `sync-secrets.php`; the same token goes into the membership +system's `members-secrets.php`. + `getusers.php` sends `Authorization: Bearer `, verifies the certificate and its name or address against `members_cafile` only (not the system's CAs), follows no redirects, waits at most 20 seconds and accepts -only HTTP 200 with a valid list: every row with exactly these fields, a -positive id and a UUID that no other row has. Otherwise the list is not -loaded and the page stops with an error (fail closed); without the settings -the error is "Mitgliederliste nicht konfiguriert!". A new token: set the new -`pgacc_members_token` here and on the membership system in the same run. -Allow outgoing TCP to the membership system's port in the firewall. +only HTTP 200 with a complete body of at most 4 MiB and a valid list: +every row with exactly these fields, a positive id and a UUID that no other +row has. Otherwise the list is not loaded and the page stops with an error +(fail closed); without the settings the error is "Mitgliederliste nicht +konfiguriert!". Allow outgoing TCP to the membership system's port in the +firewall. ## Staging diff --git a/deploy/ansible/inventory.example.yml b/deploy/ansible/inventory.example.yml index 875581ee..43e7d51d 100644 --- a/deploy/ansible/inventory.example.yml +++ b/deploy/ansible/inventory.example.yml @@ -24,16 +24,16 @@ all: pgacc_trusted_proxies: - 192.0.2.1 # Optional (defaults shown). - # pgacc_timezone: UTC + # pgacc_timezone: UTC # Europe/Vienna with the membership sync (deploy/README.md) # pgacc_backup_keep_days: 7 # pgacc_disable_sshd: true - # /etc/hosts entries for names the internal DNS does not resolve (see - # README.md, "Membership system"). Empty by default: nothing is written. - # pgacc_extra_hosts: - # - { ip: 192.0.2.1, names: [members.example.org] } # The member list of the membership system (README.md, "Member list"). # Off while pgacc_members_url is empty (the default); keep the token in - # a vault. + # a vault (openssl rand -hex 32, once). # pgacc_members_url: https://192.0.2.20:8443/members.php # pgacc_members_token: "{{ vault_pgacc_members_token }}" - # pgacc_members_cert: "{{ lookup('ansible.builtin.file', 'members-tls.crt') }}" + # pgacc_members_cert: "{{ lookup('ansible.builtin.file', 'admidio-addons-tls.crt') }}" + # /etc/hosts entries for names the internal DNS does not resolve (see + # README.md, "Membership system"). Empty by default: nothing is written. + # pgacc_extra_hosts: + # - { ip: 192.0.2.1, names: [members.example.org] } diff --git a/deploy/ansible/playbook.yml b/deploy/ansible/playbook.yml index d430f643..2f649b3e 100644 --- a/deploy/ansible/playbook.yml +++ b/deploy/ansible/playbook.yml @@ -50,15 +50,21 @@ - pgacc_backup_keep_days | default(7) | int > 0 - pgacc_extra_hosts | default([]) | rejectattr('ip', 'defined') | list | length == 0 - pgacc_extra_hosts | default([]) | rejectattr('names', 'defined') | list | length == 0 - - pgacc_members_url | default('') == '' or pgacc_members_url is match('^https://[A-Za-z0-9.:/_-]+$') - - pgacc_members_url | default('') == '' or pgacc_members_token | default('') is match('^[0-9a-f]{64}$') - - pgacc_members_url | default('') == '' or 'BEGIN CERTIFICATE' in pgacc_members_cert | default('') fail_msg: >- Needs Debian 13 and pgacc_trusted_proxies: the addresses or CIDR ranges of the TLS-terminating reverse proxy (X-Forwarded-Proto is trusted only from them). pgacc_extra_hosts entries need ip and - names. pgacc_members_url: empty or an https:// URL, then - pgacc_members_token (64 hex characters) and pgacc_members_cert (PEM). + names. + + - name: Check the member list settings + ansible.builtin.assert: + that: + - pgacc_members_url | default('') == '' or pgacc_members_url is match('^https://[A-Za-z0-9.:/_-]+$') + - pgacc_members_url | default('') == '' or pgacc_members_token | default('') is match('^[0-9a-f]{64}$') + - pgacc_members_url | default('') == '' or 'BEGIN CERTIFICATE' in pgacc_members_cert | default('') + fail_msg: >- + pgacc_members_url: empty or an https:// URL, then pgacc_members_token + (64 hex characters) and pgacc_members_cert (PEM). # --- Packages: PostgreSQL from apt.postgresql.org, PHP from packages.sury.org @@ -195,10 +201,12 @@ group: pgacc mode: "0640" - # --- Sync settings (deploy/README.md, "Membership system"): - # sync-secrets.php holds the member list settings of getusers.php; it is - # linked into each release like constants.php. The settings come from the - # inventory on every run. + # --- Sync v2 (deploy/README.md, "Membership system"): sync-secrets.php + # holds the settings of both directions, written from the inventory on + # every run (templates/sync-secrets.php.j2: the payments_* keys while the + # internal sync listener is on, the members_* keys while the member list + # is configured). It is linked into each release like constants.php. + # /etc/pgacc holds the certificates. - name: Create the configuration directory ansible.builtin.file: @@ -206,52 +214,13 @@ state: directory mode: "0755" - - name: Create sync-secrets.php if there is none - ansible.builtin.shell: | - set -eu - umask 077 - printf '%s\n' ' ''," " 'members_token' => ''," " 'members_cafile' => ''," \ - '];' >/srv/pgacc/shared/sync-secrets.php.new - mv /srv/pgacc/shared/sync-secrets.php.new /srv/pgacc/shared/sync-secrets.php - args: - creates: /srv/pgacc/shared/sync-secrets.php - - # The certificate of the membership system's internal listener: the only - # trust anchor of getusers.php (members_cafile). - - name: Install the certificate of the membership system (pgacc_members_cert) - ansible.builtin.copy: - dest: /etc/pgacc/members-tls.crt - content: "{{ pgacc_members_cert }}" - mode: "0644" - when: pgacc_members_url | default('') != '' - - - name: Remove the certificate of the membership system while the member list is off - ansible.builtin.file: - path: /etc/pgacc/members-tls.crt - state: absent - when: pgacc_members_url | default('') == '' - - - name: Set the member list settings in sync-secrets.php - ansible.builtin.lineinfile: - path: /srv/pgacc/shared/sync-secrets.php - regexp: "^ '{{ item.key }}' => " - line: " '{{ item.key }}' => {{ item.value }}," - insertbefore: '^\];$' - # Only in check mode, where the file may not exist yet. - create: true + - name: Write sync-secrets.php from the inventory + ansible.builtin.template: + src: sync-secrets.php.j2 + dest: /srv/pgacc/shared/sync-secrets.php owner: root group: pgacc mode: "0640" - loop: - - { key: members_url, value: "'{{ pgacc_members_url | default('') }}'" } - - { key: members_token, value: "'{{ pgacc_members_token | default('') if pgacc_members_url | default('') != '' else '' }}'" } - - { key: members_cafile, value: "'{{ '/etc/pgacc/members-tls.crt' if pgacc_members_url | default('') != '' else '' }}'" } - loop_control: - label: "{{ item.key }}" no_log: true # --- PHP-FPM, nginx, deploy command @@ -323,6 +292,23 @@ dest: /etc/logrotate.d/pgacc mode: "0644" + # --- Member list (deploy/README.md, "Member list"): the certificate of + # the membership system's internal listener, the only trust anchor of + # getusers.php (members_cafile in sync-secrets.php). + + - name: Install the certificate of the membership system (pgacc_members_cert) + ansible.builtin.copy: + dest: /etc/pgacc/admidio-addons-tls.crt + content: "{{ pgacc_members_cert }}" + mode: "0644" + when: pgacc_members_url | default('') != '' + + - name: Remove the certificate of the membership system while the member list is off + ansible.builtin.file: + path: /etc/pgacc/admidio-addons-tls.crt + state: absent + when: pgacc_members_url | default('') == '' + # --- PostgreSQL - name: Start PostgreSQL diff --git a/deploy/ansible/templates/sync-secrets.php.j2 b/deploy/ansible/templates/sync-secrets.php.j2 new file mode 100644 index 00000000..9f89c8d9 --- /dev/null +++ b/deploy/ansible/templates/sync-secrets.php.j2 @@ -0,0 +1,19 @@ + '{{ pgacc_payments_token }}', + 'payments_peers' => [{% for peer in pgacc_sync_peers %}'{{ peer }}'{{ ', ' if not loop.last else '' }}{% endfor %}], +{% endif %} +{% if pgacc_members_url | default('') != '' %} + // getusers.php: the member list of the membership system. + 'members_url' => '{{ pgacc_members_url }}', + 'members_token' => '{{ pgacc_members_token }}', + 'members_cafile' => '/etc/pgacc/admidio-addons-tls.crt', +{% endif %} +]; diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 07a771ef..9bc54bf0 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -100,7 +100,7 @@ if [ ! -d "$release" ]; then [ -f "$work/$name/public/index.php" ] && [ -f "$work/$name/vendor/autoload.php" ] || die "the archive has no public/index.php or vendor/autoload.php" ln -s "$root/shared/constants.php" "$work/$name/constants.php" - # A dangling link before the playbook created it: the member list cannot be loaded. + # Written by the playbook on every run; without it the sync refuses (deploy/README.md, "Membership system"). ln -s "$root/shared/sync-secrets.php" "$work/$name/sync-secrets.php" ln -s "$root/shared/files" "$work/$name/files" mv "$work/$name" "$release" diff --git a/getusers.php b/getusers.php index bb070435..dfb8600e 100644 --- a/getusers.php +++ b/getusers.php @@ -1,5 +1,8 @@ 'https://...', 'members_token' => non-empty string, -// 'members_cafile' => the membership system's certificate], or null if the -// file is missing or one of them is missing, empty or (the URL) not https. +// 'members_cafile' => the membership system's certificate, ...], or null if +// the file is missing, does not load (a parse error or an exception: logged +// by class only) or one of them is missing, empty or (the URL) not https. function getusers_config($file) { - $config = stream_resolve_include_path($file) === false ? null : include $file; + if (stream_resolve_include_path($file) === false) { + return null; + } + try { + $config = include $file; + } catch (Throwable $e) { + // Only the class: the message of a parse error can quote the file. + error_log('getusers: sync-secrets.php cannot be loaded (' . get_class($e) . ')'); + return null; + } foreach (['members_url', 'members_token', 'members_cafile'] as $name) { if (!is_string($config[$name] ?? null) || $config[$name] === '') { return null; @@ -57,16 +70,19 @@ function getusers_config($file) // certificate; with a cafile PHP does not load the system's CAs), including // the host name or address of the URL. Redirects are not followed (a 3xx is // an error), so the list never comes from another host or over plain HTTP. -// Only 200 is accepted. ignore_errors: an HTTP error status is checked here -// instead of raising a warning. The token is never logged. -function getusers_fetch($config) +// Only 200 is accepted, with a complete body of at most GETUSERS_MAX_BODY +// bytes (a read that timed out is refused, not returned in part). +// ignore_errors: an HTTP error status is checked here instead of raising a +// warning. $timeout: seconds (the tests pass less). The token is never +// logged. +function getusers_fetch($config, $timeout = 20) { $context = stream_context_create([ 'http' => [ 'header' => 'Authorization: Bearer ' . $config['members_token'] . "\r\nAccept: application/json\r\n", 'ignore_errors' => true, 'follow_location' => 0, - 'timeout' => 20, + 'timeout' => $timeout, ], 'ssl' => [ 'verify_peer' => true, @@ -75,13 +91,23 @@ function getusers_fetch($config) 'cafile' => $config['members_cafile'], ], ]); - http_clear_last_response_headers(); error_clear_last(); - $body = @file_get_contents($config['members_url'], false, $context); - $headers = http_get_last_response_headers(); - if ($body === false || !is_array($headers) || !preg_match('#^HTTP/\S+ 200( |$)#', $headers[0])) { + $stream = @fopen($config['members_url'], 'r', false, $context); + if ($stream === false) { $error = error_get_last(); - error_log('getusers: ' . ($body === false ? ($error === null ? 'fetch failed' : $error['message']) : $headers[0])); + error_log('getusers: ' . ($error === null ? 'fetch failed' : $error['message'])); + return null; + } + $body = stream_get_contents($stream, GETUSERS_MAX_BODY + 1); + $meta = stream_get_meta_data($stream); + fclose($stream); + $status = $meta['wrapper_data'][0] ?? ''; + if (!is_string($status) || !preg_match('#^HTTP/\S+ 200( |$)#', $status)) { + error_log('getusers: ' . (is_string($status) && $status !== '' ? $status : 'no status')); + return null; + } + if ($body === false || $meta['timed_out'] || strlen($body) > GETUSERS_MAX_BODY) { + error_log('getusers: incomplete or too large response'); return null; } return $body; diff --git a/tests/README.md b/tests/README.md index 7b59b227..3dd24c7c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -244,7 +244,7 @@ http://mitglieder.piratenpartei.at/__stub/mode?set=` switches the member-list response, and `POST .../__stub/body` serves a given body (the unit tests, `tests/unit/MembershipStub.php`). The modes (`malformed`, `empty`, `invalid-row`, `duplicate`, `bad-uuid`, `flow`, `overflow`, `redirect`, -`redirect-http`, `selfsigned`, `wrongname`, `error`, ...) are documented in +`redirect-http`, `selfsigned`, `wrongname`, `error`, `stall`) are documented in the header of `server.php`; `selfsigned` and `wrongname` present a self-signed and a wrong-name certificate (also generated per build) that `getusers()` must refuse. `tests/http-import.php` uses the modes for the @@ -253,8 +253,10 @@ attributed with `with_expected_diagnostics()` (`tests/http-diagnostics.php`), an `/__stub/list-requests` proves that no redirect was followed. `GetUsersTest` fetches the synthetic `flow` list (`tests/reference/membership/flow.json`) over HTTPS and checks the exact -`ppmembers` rows, refuses every kind of malformed list, and checks the -settings, the UUID check and the profile links. +`ppmembers` rows, refuses every kind of malformed list, a body over 4 MiB +(exactly 4 MiB is read), a read that timed out (`stall`) and a +`sync-secrets.php` that does not load, and checks the settings, the UUID +check and the profile links. All test servers run with `output_buffering=4096`, but no redirect depends on it: `http-login.php`, `http-redirects.php` and `write-workflows.php` repeat diff --git a/tests/http-import.php b/tests/http-import.php index 79d7921b..f596e7d3 100644 --- a/tests/http-import.php +++ b/tests/http-import.php @@ -465,7 +465,7 @@ function member_rows($database) } }; if ($mode === 'selfsigned' || $mode === 'wrongname') { - with_expected_diagnostics("refused $mode certificate", [['getusers.php', 'file_get_contents(']], $requests); + with_expected_diagnostics("refused $mode certificate", [['getusers.php', 'fopen(']], $requests); } else { $requests(); } diff --git a/tests/mutation/targets/import-checks.php b/tests/mutation/targets/import-checks.php index 366da041..7cd89330 100644 --- a/tests/mutation/targets/import-checks.php +++ b/tests/mutation/targets/import-checks.php @@ -198,10 +198,38 @@ [ 'id' => 'members-error-status-accepted', 'file' => 'getusers.php', - 'search' => "if (\$body === false || !is_array(\$headers) || !preg_match('#^HTTP/\\S+ 200( |\$)#', \$headers[0]))", - 'replace' => 'if ($body === false)', + 'search' => " if (!is_string(\$status) || !preg_match('#^HTTP/\\S+ 200( |\$)#', \$status)) {", + 'replace' => ' if (false) {', 'rationale' => 'A failed fetch (HTTP error status, redirect) stops with its own error.', ], + [ + 'id' => 'members-body-unlimited', + 'file' => 'getusers.php', + 'search' => '|| strlen($body) > GETUSERS_MAX_BODY) {', + 'replace' => '|| strlen($body) > GETUSERS_MAX_BODY + 1) {', + 'rationale' => 'A body larger than 4 MiB is refused.', + ], + [ + 'id' => 'members-body-limit-exclusive', + 'file' => 'getusers.php', + 'search' => '|| strlen($body) > GETUSERS_MAX_BODY) {', + 'replace' => '|| strlen($body) >= GETUSERS_MAX_BODY) {', + 'rationale' => 'A body of exactly 4 MiB is accepted.', + ], + [ + 'id' => 'members-timed-out-body-accepted', + 'file' => 'getusers.php', + 'search' => " || \$meta['timed_out']", + 'replace' => '', + 'rationale' => 'A read that timed out is refused, not returned in part.', + ], + [ + 'id' => 'members-broken-config-fatal', + 'file' => 'getusers.php', + 'search' => ' } catch (Throwable $e) {', + 'replace' => ' } catch (DivisionByZeroError $e) {', + 'rationale' => 'A sync-secrets.php that does not load fails closed, not with a fatal error.', + ], [ 'id' => 'members-redirect-followed', 'file' => 'getusers.php', diff --git a/tests/reference/membership/server.php b/tests/reference/membership/server.php index 87773767..5a2d7229 100644 --- a/tests/reference/membership/server.php +++ b/tests/reference/membership/server.php @@ -33,6 +33,9 @@ * selfsigned HTTPS with a self-signed certificate for the host * wrongname HTTPS with a test-CA certificate for another host name * error HTTP 500 + * stall the member list, but only its first half, then nothing + * for 3 seconds before the connection closes (a read + * timeout; GetUsersTest) * /__stub/list serves the member list on both ports (the redirect targets) * and counts its requests: GET http://.../__stub/list-requests answers the * count since the last mode switch, so the tests can prove that no redirect @@ -52,7 +55,7 @@ $listRequestsFile = '/tmp/pgacc-membership-stub-list-requests'; $membersRequestsFile = '/tmp/pgacc-membership-stub-members-requests'; $modes = ['ok', 'malformed', 'empty', 'invalid-row', 'duplicate', 'bad-uuid', 'flow', 'overflow', 'body', - 'redirect', 'redirect-http', 'selfsigned', 'wrongname', 'error']; + 'redirect', 'redirect-http', 'selfsigned', 'wrongname', 'error', 'stall']; $membersToken = (require '/app/tests/runtime/test-sync-secrets.php')['members_token']; $certificates = [ 'selfsigned' => '/etc/pgacc-test-tls/selfsigned.pem', @@ -201,8 +204,14 @@ function membership_stub_response($secure, $method, $uri, $authorization, $body, file_put_contents($pgaccStubLog, $method . ' ' . $uri . "\n", FILE_APPEND | LOCK_EX); } list($status, $responseBody) = membership_stub_response($secure, $method, $uri, $authorization, $body, $modeFile, $bodyFile, $modes); - @fwrite($client, "HTTP/1.0 $status\r\nContent-Type: text/plain\r\nContent-Length: " . strlen($responseBody) - . "\r\nConnection: close\r\n\r\n" . $responseBody); + $head = "HTTP/1.0 $status\r\nContent-Type: text/plain\r\nContent-Length: " . strlen($responseBody) + . "\r\nConnection: close\r\n\r\n"; + if ($secure && $status === '200 OK' && strpos($uri, '/members.php') === 0 && membership_stub_mode($modeFile) === 'stall') { + @fwrite($client, $head . substr($responseBody, 0, intdiv(strlen($responseBody), 2))); + sleep(3); + } else { + @fwrite($client, $head . $responseBody); + } @fclose($client); } } diff --git a/tests/runtime/test-sync-secrets.php b/tests/runtime/test-sync-secrets.php index 85bc6be3..19302048 100644 --- a/tests/runtime/test-sync-secrets.php +++ b/tests/runtime/test-sync-secrets.php @@ -1,12 +1,17 @@ 'synthetic-test-only-payments-token', + 'payments_peers' => ['127.0.0.1'], 'members_url' => 'https://mitglieder.piratenpartei.at/members.php', 'members_token' => 'synthetic-test-only-members-token', 'members_cafile' => '/usr/local/share/ca-certificates/pgacc-synthetic-test-ca.crt', diff --git a/tests/unit/GetUsersTest.php b/tests/unit/GetUsersTest.php index 692af7eb..ad39f981 100644 --- a/tests/unit/GetUsersTest.php +++ b/tests/unit/GetUsersTest.php @@ -154,6 +154,38 @@ public function testARefusedFetchFailsClosed($mode, $settings) self::assertNull($body); } + // The body is read up to 4 MiB: one byte more is refused, exactly the + // limit is returned. + public function testATooLargeResponseIsRefused() + { + $config = getusers_config('sync-secrets.php'); + MembershipStub::serve(str_repeat('x', 4 * 1024 * 1024 + 1)); + try { + $tooLarge = getusers_fetch($config); + MembershipStub::serve(str_repeat('x', 4 * 1024 * 1024)); + $atTheLimit = getusers_fetch($config); + } finally { + MembershipStub::reset(); + } + // Lengths only: the bodies are megabytes. + self::assertNull($tooLarge === null ? null : strlen($tooLarge)); + self::assertSame(4 * 1024 * 1024, strlen((string) $atTheLimit)); + } + + // A response that stops in the middle of the body (the stub's "stall" + // mode) is refused when the read times out, not returned in part. + public function testATimedOutResponseIsRefused() + { + $config = getusers_config('sync-secrets.php'); + MembershipStub::mode('stall'); + try { + $body = getusers_fetch($config, 1); + } finally { + MembershipStub::reset(); + } + self::assertNull($body === null ? null : strlen($body)); + } + public function testTheMembersCafileIsTheTrustAnchor() { // The self-signed certificate of the stub is accepted when it is the @@ -197,6 +229,42 @@ public function testConfiguration($config, $accepted) } } + // A sync-secrets.php that does not load (a parse error, an exception) + // counts as missing: the list fails closed with the usual error instead + // of a fatal error of the page. + public static function brokenConfigProvider() + { + return [ + 'parse error' => [" 'https://members.invalid/members.php',;\n"], + 'throws' => [" Date: Sun, 1 Nov 2026 12:49:09 +0100 Subject: [PATCH 4/8] Docs: rollout order of the member list, with a check from the pgacc host The membership system's listener must serve members.php before pgacc_members_url is set; UPGRADING.md and deploy/README.md give a curl check that must print 200. Co-Authored-By: Claude Opus 5.5 --- UPGRADING.md | 11 +++++++++++ deploy/README.md | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/UPGRADING.md b/UPGRADING.md index 34d5e379..32c5ff54 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -79,6 +79,17 @@ list". - `$datakey` in `constants.php` is now used only by the membership export `mbapi.php`. +Rollout order: the membership system's listener must serve `members.php` +before `pgacc_members_url` (or `members_url`) is set. Check it from the +pgacc host with its certificate saved as `admidio-addons-tls.crt` (the +playbook writes `/etc/pgacc/admidio-addons-tls.crt` only once the URL is +set); it must print 200: + +```sh +curl --cacert admidio-addons-tls.crt -H 'Authorization: Bearer ' \ + https://192.0.2.20:8443/members.php -o /dev/null -w '%{http_code}\n' +``` + ## Document root `public/` (deployment change) This release changes how pgacc is deployed; it is meant for a major release. diff --git a/deploy/README.md b/deploy/README.md index 733f3cb0..b28e1279 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -304,6 +304,16 @@ The playbook writes the certificate to `/etc/pgacc/admidio-addons-tls.crt` token into `sync-secrets.php`; the same token goes into the membership system's `members-secrets.php`. +Rollout order: the membership system's listener must serve `members.php` +before `pgacc_members_url` is set. Check it from the pgacc host, with the +certificate of `pgacc_members_cert` saved as `admidio-addons-tls.crt`; it +must print 200: + +```sh +curl --cacert admidio-addons-tls.crt -H 'Authorization: Bearer ' \ + https://192.0.2.20:8443/members.php -o /dev/null -w '%{http_code}\n' +``` + `getusers.php` sends `Authorization: Bearer `, verifies the certificate and its name or address against `members_cafile` only (not the system's CAs), follows no redirects, waits at most 20 seconds and accepts From 36e566211289aea40d91de83a1901976e8c48311 Mon Sep 17 00:00:00 2001 From: PeterTheOne Date: Sun, 1 Nov 2026 13:07:35 +0100 Subject: [PATCH 5/8] Test: render sync-secrets.php.j2 with Ansible and load it with the readers tests/sync-secrets-template.sh renders the real template with the template module (ansible-core of tests/playbook-settings.sh) for payments only, members only and both, and loads each file with sync_api_config() and getusers_config() where present. A broken template made every sync request 403, which the deploy smoke test accepts. Wired into the web-server CI job. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/tests.yaml | 2 + tests/README.md | 8 +++ tests/sync-secrets-template.sh | 100 +++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 tests/sync-secrets-template.sh diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 02f7309b..4fcb2e69 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -116,6 +116,8 @@ jobs: run: sh tests/web-server/run.sh - name: Test the public/ guards of deploy/deploy.sh (stubbed, no server) run: sh tests/deploy-guards.sh + - name: Test the rendering of sync-secrets.php.j2 with the PHP readers + run: sh tests/sync-secrets-template.sh docker-harness: name: PHP 8.5 / PostgreSQL 18 characterization harness diff --git a/tests/README.md b/tests/README.md index 3dd24c7c..f8f0bc0c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -299,6 +299,14 @@ without `public/`, the smoke test of an already current release, the rollback to a release without `public/`). Red evidence: the `deploy.sh` before these guards fails 2 of its 5 cases. +It also runs `sh tests/sync-secrets-template.sh` (Docker, ansible-core, +PHP 8.5): `deploy/ansible/templates/sync-secrets.php.j2` rendered with +Ansible's template module for payments only, members only and both, each +file loaded with the real readers of the checkout, `sync_api_config()` and +`getusers_config()` (a reader that is not there is skipped): the exact +array, accepted with the expected values, refused without its keys. Red +evidence: the template with `payment_token` and `member_token` fails. + ### PHPUnit `tests/unit/` runs on PHPUnit 13.4 (PHP 8.5). Every configuration sets diff --git a/tests/sync-secrets-template.sh b/tests/sync-secrets-template.sh new file mode 100644 index 00000000..0e547ca9 --- /dev/null +++ b/tests/sync-secrets-template.sh @@ -0,0 +1,100 @@ +#!/bin/sh +# Renders deploy/ansible/templates/sync-secrets.php.j2 with Ansible's +# template module (the playbook's "Write sync-secrets.php from the +# inventory" task, same ansible-core as tests/playbook-settings.sh) and +# loads each result with the real PHP readers of this checkout: +# +# sh tests/sync-secrets-template.sh +# +# Cases: payments only (pgacc_sync_listen_address set), members only +# (pgacc_members_url set), both. Each file must return exactly the expected +# array, and each reader present here must accept it with those values or +# refuse it when its keys are absent: sync_api_config() (src/sync-api.php, +# internal/mbapi.php) and getusers_config() (getusers.php). A reader that is +# not in this checkout is skipped; at least one must be present. Synthetic +# values only. The temporary directory is removed at the end. +set -eu + +python_image=python:3.13-slim@sha256:2d44738ebf4ce5f63b9d9ea871e9c7cfdc0426f7b0c97cac915fd88ded1d86bb +php_image=php:8.5-fpm@sha256:c34bcf437ed61bd5e4c1114494eaf1ffd54253bce2b95d263bfa18b350ee8432 +ansible_core_version=2.18.19 + +repo=$(cd "$(dirname "$0")/.." && pwd -P) +# Below the checkout (build/ is ignored): a Docker daemon in a snap or a VM +# may not see the host's /tmp. +mkdir -p "$repo/build" +tmp=$(mktemp -d "$repo/build/sync-secrets.XXXXXX") +trap 'rm -rf "$tmp"' EXIT + +cat >"$tmp/render.yml" <<'EOF' +- hosts: localhost + connection: local + gather_facts: false + vars: + ansible_python_interpreter: auto_silent + payments: &payments + pgacc_sync_listen_address: 192.0.2.10 + pgacc_sync_peers: [192.0.2.20, 192.0.2.21] + pgacc_payments_token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + members: &members + pgacc_members_url: https://192.0.2.20:8443/members.php + pgacc_members_token: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + tasks: + - name: Render sync-secrets.php, payments only + ansible.builtin.template: {src: /ansible/templates/sync-secrets.php.j2, dest: /out/payments.php} + vars: *payments + - name: Render sync-secrets.php, members only + ansible.builtin.template: {src: /ansible/templates/sync-secrets.php.j2, dest: /out/members.php} + vars: *members + - name: Render sync-secrets.php, both + ansible.builtin.template: {src: /ansible/templates/sync-secrets.php.j2, dest: /out/both.php} + vars: {<<: [*payments, *members]} +EOF + +docker run --rm --user "$(id -u):$(id -g)" -e HOME=/tmp -e USER=ansible -v "$repo/deploy/ansible:/ansible:ro" \ + -v "$tmp:/out" "$python_image" sh -c " +pip install --quiet --disable-pip-version-check --no-warn-script-location --user ansible-core==$ansible_core_version && +/tmp/.local/bin/ansible-playbook -i localhost, /out/render.yml >/tmp/ansible.log || { cat /tmp/ansible.log; exit 1; }" + +docker run --rm -i --network none -v "$repo:/app:ro" -v "$tmp:/out:ro" -w /app "$php_image" php <<'EOF' + str_repeat('a', 64), 'payments_peers' => ['192.0.2.20', '192.0.2.21']]; +$members = ['members_url' => 'https://192.0.2.20:8443/members.php', 'members_token' => str_repeat('b', 64), + 'members_cafile' => '/etc/pgacc/admidio-addons-tls.crt']; +$cases = ['payments' => $payments, 'members' => $members, 'both' => $payments + $members]; +$readers = []; +if (is_file('src/sync-api.php')) { + require 'src/sync-api.php'; + $readers['sync_api_config'] = array_keys($payments); +} +if (is_file('getusers.php') && strpos(file_get_contents('getusers.php'), 'function getusers_config(') !== false) { + require 'getusers.php'; + $readers['getusers_config'] = array_keys($members); +} +if ($readers === []) { + echo "FAIL: no reader of sync-secrets.php in this checkout\n"; + exit(1); +} +$failed = 0; +foreach ($cases as $name => $expected) { + $file = "/out/$name.php"; + $check = function ($ok, $what) use ($name, $file, &$failed) { + echo ($ok ? 'ok' : 'FAIL') . ": $name: $what\n"; + if (!$ok) { + $failed++; + echo file_get_contents($file); + } + }; + $check((include $file) === $expected, 'returns the expected array'); + foreach ($readers as $reader => $keys) { + $want = array_intersect_key($expected, array_flip($keys)); + $config = $reader($file); + if (count($want) === count($keys)) { + $check($config !== null && array_intersect_key($config, $want) === $want, "$reader() accepts it"); + } else { + $check($config === null, "$reader() refuses it (its keys are absent)"); + } + } +} +exit($failed ? 1 : 0); +EOF From d12bbb8fcb3a343ad4c1db9ab992ea9897d9f26c Mon Sep 17 00:00:00 2001 From: PeterTheOne Date: Sun, 1 Nov 2026 13:20:59 +0100 Subject: [PATCH 6/8] getusers.php: overall 20 s deadline for connection, headers and body PHP's stream timeout applies to each read, so a membership system that trickles the response could hold the request far longer. The fetch now reads the response itself under one deadline and fails closed. Co-Authored-By: Claude Opus 5.5 --- getusers.php | 65 +++++++++++++++++++-------- tests/http-import.php | 2 +- tests/reference/membership/server.php | 18 +++++++- tests/unit/GetUsersTest.php | 27 +++++++++++ 4 files changed, 92 insertions(+), 20 deletions(-) diff --git a/getusers.php b/getusers.php index dfb8600e..2c8437e5 100644 --- a/getusers.php +++ b/getusers.php @@ -71,42 +71,71 @@ function getusers_config($file) // the host name or address of the URL. Redirects are not followed (a 3xx is // an error), so the list never comes from another host or over plain HTTP. // Only 200 is accepted, with a complete body of at most GETUSERS_MAX_BODY -// bytes (a read that timed out is refused, not returned in part). -// ignore_errors: an HTTP error status is checked here instead of raising a -// warning. $timeout: seconds (the tests pass less). The token is never -// logged. +// bytes (a response not complete by the deadline is refused, not returned +// in part). $timeout: seconds for connection, headers and body together +// (PHP's own stream timeout applies to each read only; the tests pass less). +// The token is never logged. function getusers_fetch($config, $timeout = 20) { + $deadline = microtime(true) + $timeout; + $url = parse_url($config['members_url']); + if (!is_array($url) || ($url['scheme'] ?? '') !== 'https' || !isset($url['host']) || isset($url['user']) || isset($url['pass'])) { + error_log('getusers: not an https URL'); + return null; + } + $port = $url['port'] ?? 443; $context = stream_context_create([ - 'http' => [ - 'header' => 'Authorization: Bearer ' . $config['members_token'] . "\r\nAccept: application/json\r\n", - 'ignore_errors' => true, - 'follow_location' => 0, - 'timeout' => $timeout, - ], 'ssl' => [ 'verify_peer' => true, 'verify_peer_name' => true, + 'peer_name' => trim($url['host'], '[]'), 'allow_self_signed' => false, 'cafile' => $config['members_cafile'], ], ]); error_clear_last(); - $stream = @fopen($config['members_url'], 'r', false, $context); + $stream = @stream_socket_client("ssl://{$url['host']}:$port", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context); if ($stream === false) { $error = error_get_last(); - error_log('getusers: ' . ($error === null ? 'fetch failed' : $error['message'])); + error_log('getusers: ' . ($errstr !== '' ? $errstr : ($error === null ? 'fetch failed' : $error['message']))); return null; } - $body = stream_get_contents($stream, GETUSERS_MAX_BODY + 1); - $meta = stream_get_meta_data($stream); + // HTTP/1.0: no chunked body; the connection closes after the response. + $request = 'GET ' . ($url['path'] ?? '/') . (isset($url['query']) ? '?' . $url['query'] : '') . " HTTP/1.0\r\n" + . 'Host: ' . $url['host'] . (isset($url['port']) ? ':' . $port : '') . "\r\n" + . 'Authorization: Bearer ' . $config['members_token'] . "\r\nAccept: application/json\r\nConnection: close\r\n\r\n"; + $response = ''; + $timedOut = false; + $limit = 65536 + GETUSERS_MAX_BODY + 1; + $written = @fwrite($stream, $request) === strlen($request); + while ($written && !feof($stream) && strlen($response) < $limit) { + $left = $deadline - microtime(true); + if ($left <= 0) { + $timedOut = true; + break; + } + stream_set_timeout($stream, (int) $left, (int) (($left - (int) $left) * 1000000)); + $chunk = @fread($stream, min(65536, $limit - strlen($response))); + if ($chunk === false || stream_get_meta_data($stream)['timed_out']) { + $timedOut = true; + break; + } + $response .= $chunk; + } + $complete = feof($stream); fclose($stream); - $status = $meta['wrapper_data'][0] ?? ''; - if (!is_string($status) || !preg_match('#^HTTP/\S+ 200( |$)#', $status)) { - error_log('getusers: ' . (is_string($status) && $status !== '' ? $status : 'no status')); + if (!$written || $timedOut) { + error_log('getusers: ' . ($written ? 'timeout' : 'cannot send the request')); + return null; + } + $end = strpos($response, "\r\n\r\n"); + $status = $end === false ? '' : strstr($response, "\r\n", true); + if (!preg_match('#^HTTP/\S+ 200( |$)#', $status)) { + error_log('getusers: ' . ($status !== '' ? $status : 'no status')); return null; } - if ($body === false || $meta['timed_out'] || strlen($body) > GETUSERS_MAX_BODY) { + $body = substr($response, $end + 4); + if (!$complete || strlen($body) > GETUSERS_MAX_BODY) { error_log('getusers: incomplete or too large response'); return null; } diff --git a/tests/http-import.php b/tests/http-import.php index f596e7d3..c47092a5 100644 --- a/tests/http-import.php +++ b/tests/http-import.php @@ -465,7 +465,7 @@ function member_rows($database) } }; if ($mode === 'selfsigned' || $mode === 'wrongname') { - with_expected_diagnostics("refused $mode certificate", [['getusers.php', 'fopen(']], $requests); + with_expected_diagnostics("refused $mode certificate", [['getusers.php', 'stream_socket_client(']], $requests); } else { $requests(); } diff --git a/tests/reference/membership/server.php b/tests/reference/membership/server.php index 5a2d7229..b00d4fd4 100644 --- a/tests/reference/membership/server.php +++ b/tests/reference/membership/server.php @@ -36,6 +36,9 @@ * stall the member list, but only its first half, then nothing * for 3 seconds before the connection closes (a read * timeout; GetUsersTest) + * trickle the member list in 8 parts, one per second (each read + * is quick, the whole response is not; GetUsersTest) + * tricklehead as trickle, but 8 extra header lines, one per second * /__stub/list serves the member list on both ports (the redirect targets) * and counts its requests: GET http://.../__stub/list-requests answers the * count since the last mode switch, so the tests can prove that no redirect @@ -55,7 +58,7 @@ $listRequestsFile = '/tmp/pgacc-membership-stub-list-requests'; $membersRequestsFile = '/tmp/pgacc-membership-stub-members-requests'; $modes = ['ok', 'malformed', 'empty', 'invalid-row', 'duplicate', 'bad-uuid', 'flow', 'overflow', 'body', - 'redirect', 'redirect-http', 'selfsigned', 'wrongname', 'error', 'stall']; + 'redirect', 'redirect-http', 'selfsigned', 'wrongname', 'error', 'stall', 'trickle', 'tricklehead']; $membersToken = (require '/app/tests/runtime/test-sync-secrets.php')['members_token']; $certificates = [ 'selfsigned' => '/etc/pgacc-test-tls/selfsigned.pem', @@ -209,6 +212,19 @@ function membership_stub_response($secure, $method, $uri, $authorization, $body, if ($secure && $status === '200 OK' && strpos($uri, '/members.php') === 0 && membership_stub_mode($modeFile) === 'stall') { @fwrite($client, $head . substr($responseBody, 0, intdiv(strlen($responseBody), 2))); sleep(3); + } elseif ($secure && $status === '200 OK' && strpos($uri, '/members.php') === 0 + && in_array(membership_stub_mode($modeFile), ['trickle', 'tricklehead'], true)) { + $parts = membership_stub_mode($modeFile) === 'trickle' + ? array_merge([$head], str_split($responseBody, (int) ceil(strlen($responseBody) / 8))) + : array_merge(["HTTP/1.0 $status\r\n"], array_fill(0, 8, "X-Pad: a\r\n"), [substr($head, strlen("HTTP/1.0 $status\r\n")) . $responseBody]); + foreach ($parts as $i => $part) { + if ($i > 0) { + sleep(1); + } + if (@fwrite($client, $part) === false) { + break; + } + } } else { @fwrite($client, $head . $responseBody); } diff --git a/tests/unit/GetUsersTest.php b/tests/unit/GetUsersTest.php index ad39f981..5cd13e93 100644 --- a/tests/unit/GetUsersTest.php +++ b/tests/unit/GetUsersTest.php @@ -186,6 +186,33 @@ public function testATimedOutResponseIsRefused() self::assertNull($body === null ? null : strlen($body)); } + // The timeout is overall: a response whose headers or body arrive in + // parts, each well within the timeout, is refused at the deadline. + public static function trickleProvider() + { + return [ + 'body' => ['trickle'], + 'headers' => ['tricklehead'], + ]; + } + + #[PHPUnit\Framework\Attributes\DataProvider('trickleProvider')] + public function testATrickledResponseIsRefusedAtTheDeadline($mode) + { + $config = getusers_config('sync-secrets.php'); + MembershipStub::mode($mode); + $start = microtime(true); + try { + $body = getusers_fetch($config, 2); + $elapsed = microtime(true) - $start; + } finally { + // Waits until the stub has given up on the response. + MembershipStub::reset(); + } + self::assertNull($body === null ? null : strlen($body)); + self::assertLessThan(4, $elapsed); + } + public function testTheMembersCafileIsTheTrustAnchor() { // The self-signed certificate of the stub is accepted when it is the From 80ca8741e70005455ce9fd96afdc307a952dbe90 Mon Sep 17 00:00:00 2001 From: PeterTheOne Date: Sun, 1 Nov 2026 13:36:39 +0100 Subject: [PATCH 7/8] Remove what only the old membership exchange used; $datakey unused With both directions on sync v2 nothing reads $datakey: drop membership_cipher_params() and its mutants, $datakey of the test and reference constants, and the $datakey placeholder that the playbook wrote into a new constants.php. tests/sync-secrets-template.sh now requires both readers (sync_api_config() and getusers_config()). Docs say what is true with both PRs in: both directions on internal addresses, no public name or CA bundle, allow_url_fopen not needed by getusers.php. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ UPGRADING.md | 3 ++- deploy/README.md | 6 ++--- deploy/ansible/playbook.yml | 8 ++----- functions.php | 6 ----- tests/README.md | 4 ++-- tests/mutation/targets/receipt-crypto.php | 6 ----- tests/reference/fixtures/extra.sql | 2 +- .../reference/runtime/reference-constants.php | 4 +--- tests/runtime/test-constants.php | 3 --- tests/sync-secrets-template.sh | 23 +++++-------------- tests/unit/CryptoTest.php | 2 +- 12 files changed, 22 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08dd5959..2dc2595d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,10 @@ See [UPGRADING.md](UPGRADING.md), "Sync v2 (membership sync)". member's uuid; the member-fee page links profiles by `user_uuid`, the ledger listing and the voucher form show the member id as text instead of a link. `membership_decrypt()` is removed. +- With both directions on sync v2 nothing reads `$datakey` of + `constants.php` any more: `membership_cipher_params()` is removed, the + playbook of `deploy/` no longer writes a `$datakey` into a new + `constants.php`, and an existing `$datakey` line is ignored. ### Changed diff --git a/UPGRADING.md b/UPGRADING.md index eacf8c66..064ada80 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -156,7 +156,8 @@ curl --cacert admidio-addons-tls.crt -H 'Authorization: Bearer ' \ With both directions on sync v2 nothing reads `$datakey` of `constants.php` any more (it was the key of the encrypted exports). `constants.php` needs only `$key`; an existing `$datakey` line is ignored and can stay or be -removed. +removed. The playbook of `deploy/` no longer writes one into a new +`constants.php`. ## Document root `public/` (deployment change) diff --git a/deploy/README.md b/deploy/README.md index ddfdacb5..d70e506e 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -66,7 +66,7 @@ What it sets up: | Packages | nginx; PostgreSQL 18 from apt.postgresql.org (set up with `apt.postgresql.org.sh` of Debian's `postgresql-common`); PHP 8.5 (`php8.5-fpm`, `-cli`, `-pgsql`, `-mbstring`) from packages.sury.org with its keyring package `debsuryorg-archive-keyring`. It checks the PHP extensions `pgsql`, `mbstring`, `iconv`, `zlib`, `sodium`, `openssl`. | | Users | `pgacc` runs PHP (the PHP-FPM pool) and is the database role. `pgacc-deploy` owns the releases and may run `systemctl reload php8.5-fpm.service` with sudo, nothing else. Both are system users without a login shell. | | Layout | `/srv/pgacc/releases/v/` and the symlink `/srv/pgacc/current` belong to `pgacc-deploy`; PHP can read them but not write. `/srv/pgacc/shared/files/` (receipts) belongs to `pgacc` (mode 0700). `/srv/pgacc/shared/constants.php` is `root:pgacc` 0640: PHP reads it, nobody but root writes it. PHP errors go to `/var/log/pgacc/php-error.log` (rotated weekly). | -| `constants.php` | Created only if there is none, with a random `$key` and a random placeholder `$datakey` (replace it with the key shared with the membership system). The playbook prints a notice when it creates one. An existing file is never changed (only its owner and mode). | +| `constants.php` | Created only if there is none, with a random `$key` (the only setting it needs; `$datakey`, the key of the old encrypted membership exports, is no longer read). The playbook prints a notice when it creates one. An existing file is never changed (only its owner and mode). | | Sync settings | `/srv/pgacc/shared/sync-secrets.php` (`root:pgacc` 0640), written from the inventory on every run (see "Membership system"); `/etc/pgacc` holds the certificates of the sync. | | PHP-FPM | Pool `pgacc` (socket `/run/php/pgacc-fpm.sock`, `display_errors` off, errors logged); Debian's default pool `www` is removed. `90-pgacc.ini`: `expose_php` off, `cgi.fix_pathinfo=0`, time zone, 20M uploads, 256M memory. `allow_url_fopen` stays on (Debian's default); `getusers.php` does not need it (it opens its own TLS connection). Reloaded only when this configuration changes. | | nginx | Port 80, `server_name _`, document root `/srv/pgacc/current/public` (only `public/` is served; the code, `constants.php` and `files/` are in the release root, see [UPGRADING.md](../UPGRADING.md), "Document root `public/`"), PHP with the resolved release path (`$realpath_root`) and `SERVER_NAME` set to the request's `Host` (the proxy must pass the public host name; `index.php` redirects to it). The short page addresses the application links to (`/donations`, `/kdonations`, `/spendings`, `/wk`, `/transactions`, `/vreport`, `/tinyreport`, each with an optional query string) are rewritten to `index.php?action=`. Only the trusted proxies and the host itself may connect, so `X-Forwarded-Proto` is trusted only from them. Allow list: only `/`, `index.php`, `style.css`, `js/*.js`, `icons/*.png` and the short page addresses are served, anything else answers 404; as a second line of defence dot files and backup, editor and dump copies (names ending in `~`, `.bak`, `.orig`, `.save`, `.swp`, `.sql`, `.tar.gz` and the like, or with something after `.php`, such as `constants.php.bak`) answer 403. Caching: the static files (`style.css`, `js/*.js`, `icons/*.png`) get `Cache-Control: no-cache`, so browsers revalidate them on every use (ETag/`Last-Modified`, a 304 if unchanged) and pick up a deploy on the next page view; the asset URLs are not versioned yet. PHP responses get `Cache-Control: private, no-store` unless the application sets its own Cache-Control, which is kept (the application sets none at present); pages after login hold personal and financial data. The default site is disabled. | @@ -95,8 +95,8 @@ the database, so the database comes before the first deploy. Order: 1. Run the playbook (a normal run, without `pgacc_fresh_install`). 2. Replace `shared/constants.php` with the existing one (owner `root`, group `pgacc`, mode 0640) and check that it loads, without printing the keys: - `sudo -u pgacc php -r 'include "/srv/pgacc/shared/constants.php"; echo strlen($key), " ", strlen($datakey), PHP_EOL;'` - (two non-zero lengths). + `sudo -u pgacc php -r 'include "/srv/pgacc/shared/constants.php"; echo strlen($key), PHP_EOL;'` + (a non-zero length). 3. Create the role and database and restore the dump (below). 4. Copy the receipts into `shared/files/` and fix owner and mode (a tar from the old server keeps its owner and modes): diff --git a/deploy/ansible/playbook.yml b/deploy/ansible/playbook.yml index 2789248b..40f0f605 100644 --- a/deploy/ansible/playbook.yml +++ b/deploy/ansible/playbook.yml @@ -38,9 +38,8 @@ ansible.builtin.debug: msg: >- Generated /srv/pgacc/shared/constants.php with a new random $key. - Copy it off this host now. Replace $datakey with the membership - key. When moving an installation, replace the file with the old one - before the first deploy. + Copy it off this host now. When moving an installation, replace + the file with the old one before the first deploy. tasks: - name: Check the settings @@ -198,9 +197,6 @@ .v2.aes`, refusals without a valid key), `ReceiptStorageTest.php` (v2 format against `tests/fixtures/receipt-v2/`, short reads via `ShortReadStream.php`, and the 20 MB memory check diff --git a/tests/mutation/targets/receipt-crypto.php b/tests/mutation/targets/receipt-crypto.php index 77473fe0..8180b518 100644 --- a/tests/mutation/targets/receipt-crypto.php +++ b/tests/mutation/targets/receipt-crypto.php @@ -70,12 +70,6 @@ ['id' => 'receipt-decrypt-params-swapped', 'search' => " return rijndael256_decrypt(\$cipherKey, \$data, \$iv);\n}\n\n/*\n * Receipt storage", 'replace' => " return rijndael256_decrypt(\$iv, \$data, \$cipherKey);\n}\n\n/*\n * Receipt storage", 'rationale' => 'Decryption passes key and IV in the same order as encryption.'], - ['id' => 'membership-key-not-hashed', - 'search' => 'return [md5($datakey), md5(md5($datakey))];', 'replace' => 'return [md5(md5($datakey)), md5(md5($datakey))];', - 'rationale' => 'The membership key is md5(datakey).'], - ['id' => 'membership-iv-hashed-once', - 'search' => 'return [md5($datakey), md5(md5($datakey))];', 'replace' => 'return [md5($datakey), md5($datakey)];', - 'rationale' => 'The membership IV is md5(md5(datakey)).'], // Receipt storage helpers (functions.php). ['id' => 'key-short-accepted', diff --git a/tests/reference/fixtures/extra.sql b/tests/reference/fixtures/extra.sql index 959be53b..919892b0 100644 --- a/tests/reference/fixtures/extra.sql +++ b/tests/reference/fixtures/extra.sql @@ -52,7 +52,7 @@ INSERT INTO vouchers ( ) VALUES -- Membership fees after the fixed "now" year's previous October - -- (mb.php): member ids from tests/reference/membership/adm_names.tsv. + -- (mb.php): member ids from tests/reference/membership/members.json. (201, 2001, 1, 2, true, 9001, 'AT000000000000009001', 'Anna Synthetisch-Müller', 'Teststraße 1', '1010', 'Wien', 2400, 'TEST-ACCOUNT-1', 'MB 2026', true, true, false, timestamp '2025-11-03 00:00:00', 'reviewer-a', 'reviewer-b', 2, 0, 1, '', false, ''), diff --git a/tests/reference/runtime/reference-constants.php b/tests/reference/runtime/reference-constants.php index e223ae15..7a8aa666 100644 --- a/tests/reference/runtime/reference-constants.php +++ b/tests/reference/runtime/reference-constants.php @@ -1,7 +1,5 @@ str_repeat('a', 64), 'payments_peers' => ['192. $members = ['members_url' => 'https://192.0.2.20:8443/members.php', 'members_token' => str_repeat('b', 64), 'members_cafile' => '/etc/pgacc/admidio-addons-tls.crt']; $cases = ['payments' => $payments, 'members' => $members, 'both' => $payments + $members]; -$readers = []; -if (is_file('src/sync-api.php')) { - require 'src/sync-api.php'; - $readers['sync_api_config'] = array_keys($payments); -} -if (is_file('getusers.php') && strpos(file_get_contents('getusers.php'), 'function getusers_config(') !== false) { - require 'getusers.php'; - $readers['getusers_config'] = array_keys($members); -} -if ($readers === []) { - echo "FAIL: no reader of sync-secrets.php in this checkout\n"; - exit(1); -} +require 'src/sync-api.php'; +require 'getusers.php'; +$readers = ['sync_api_config' => array_keys($payments), 'getusers_config' => array_keys($members)]; $failed = 0; foreach ($cases as $name => $expected) { $file = "/out/$name.php"; diff --git a/tests/unit/CryptoTest.php b/tests/unit/CryptoTest.php index ac5fc014..18bef368 100644 --- a/tests/unit/CryptoTest.php +++ b/tests/unit/CryptoTest.php @@ -5,7 +5,7 @@ * padding) in functions.php. The expected bytes in * tests/fixtures/mcrypt/vectors.json were produced by the real mcrypt * extension (see tests/fixtures/mcrypt/generate-vectors.php), so existing - * receipt files and the membership export stay readable. + * receipt files stay readable. */ final class CryptoTest extends FunctionsTestCase From e29d66ba5b591ddaaf224359e13a84bf6b572a7d Mon Sep 17 00:00:00 2001 From: PeterTheOne Date: Sun, 1 Nov 2026 13:43:47 +0100 Subject: [PATCH 8/8] getusers.php: refuse a body that does not match Content-Length As accsync.php of the add-ons: every Content-Length header, if there is one, must be 1-18 digits and equal the body length; otherwise the fetch fails closed on the same error path. Tests (red first): a 200 body cut short by an early close (no timeout), a longer body and a malformed value (stub modes short, long, badlength). Also for the mutation and changed-line gates of the new HTTP client: the four getusers mutants that still searched the old stream-wrapper code match the socket client; new mutants for the deadline, the URL checks and the Content-Length check; tests for a URL with user info, without a host, with http, and the stall test refuses at the deadline. The deadline is a clamped per-read timeout (no separate branch), the redundant password check is gone (a password always comes with a user), and the timed_out mutant is documented as equivalent (fread() returns false on a TLS read timeout). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +- UPGRADING.md | 3 +- deploy/README.md | 4 +- getusers.php | 25 +++++++---- tests/mutation/README.md | 4 +- tests/mutation/targets/import-checks.php | 56 ++++++++++++++++++++---- tests/reference/membership/server.php | 16 ++++++- tests/unit/GetUsersTest.php | 43 +++++++++++++++++- 8 files changed, 130 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dc2595d..23a1db15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,7 +52,8 @@ See [UPGRADING.md](UPGRADING.md), "Sync v2 (membership sync)". `/etc/pgacc/admidio-addons-tls.crt`), empty by default, so the member list is off and those pages fail with "Mitgliederliste nicht konfiguriert!". The fetch requires a verified certificate, no redirect, - HTTP 200 and a complete body of at most 4 MiB within 20 seconds, and + HTTP 200 and a complete body of at most 4 MiB within 20 seconds that + matches its `Content-Length` (if sent: 1-18 digits), and refuses the whole list if a row is malformed or a member id or uuid appears twice (fail closed as before). The member list stores each member's uuid; the member-fee page links profiles by `user_uuid`, the diff --git a/UPGRADING.md b/UPGRADING.md index 064ada80..cf500ab4 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -128,7 +128,8 @@ list". - The fetch verifies the certificate and its name or address against `members_cafile` only, sends `Authorization: Bearer `, follows no redirects, times out after 20 seconds and needs HTTP 200 with a complete - body of at most 4 MiB. The list must be valid as a whole + body of at most 4 MiB that matches its `Content-Length` header, if there + is one (1-18 digits; anything else fails). The list must be valid as a whole (`[{"id": int, "uuid": string, "name": string, "lo": int|null, "paid": 0|1}]`, exactly these fields, a positive id and a UUID per member, none twice); otherwise "Daten von Mitgliederverwaltung ungültig!" and nothing is diff --git a/deploy/README.md b/deploy/README.md index d70e506e..eb38d826 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -331,7 +331,9 @@ curl --cacert admidio-addons-tls.crt -H 'Authorization: Bearer ' \ `getusers.php` sends `Authorization: Bearer `, verifies the certificate and its name or address against `members_cafile` only (not the system's CAs), follows no redirects, waits at most 20 seconds and accepts -only HTTP 200 with a complete body of at most 4 MiB and a valid list: +only HTTP 200 with a complete body of at most 4 MiB (equal to every +`Content-Length` header, if there is one; a value that is not 1-18 digits +fails) and a valid list: every row with exactly these fields, a positive id and a UUID that no other row has. Otherwise the list is not loaded and the page stops with an error (fail closed); without the settings the error is "Mitgliederliste nicht diff --git a/getusers.php b/getusers.php index 2c8437e5..1c6da10f 100644 --- a/getusers.php +++ b/getusers.php @@ -72,14 +72,15 @@ function getusers_config($file) // an error), so the list never comes from another host or over plain HTTP. // Only 200 is accepted, with a complete body of at most GETUSERS_MAX_BODY // bytes (a response not complete by the deadline is refused, not returned -// in part). $timeout: seconds for connection, headers and body together +// in part) that matches every Content-Length header, if there is one. $timeout: seconds for connection, headers and body together // (PHP's own stream timeout applies to each read only; the tests pass less). // The token is never logged. function getusers_fetch($config, $timeout = 20) { $deadline = microtime(true) + $timeout; $url = parse_url($config['members_url']); - if (!is_array($url) || ($url['scheme'] ?? '') !== 'https' || !isset($url['host']) || isset($url['user']) || isset($url['pass'])) { + // No user info (a password always comes with a user, if only an empty one). + if (!is_array($url) || ($url['scheme'] ?? '') !== 'https' || !isset($url['host']) || isset($url['user'])) { error_log('getusers: not an https URL'); return null; } @@ -109,12 +110,10 @@ function getusers_fetch($config, $timeout = 20) $limit = 65536 + GETUSERS_MAX_BODY + 1; $written = @fwrite($stream, $request) === strlen($request); while ($written && !feof($stream) && strlen($response) < $limit) { - $left = $deadline - microtime(true); - if ($left <= 0) { - $timedOut = true; - break; - } - stream_set_timeout($stream, (int) $left, (int) (($left - (int) $left) * 1000000)); + // Microseconds to the deadline, at least 1: a timeout of 0 would + // mean none for a TLS stream; past the deadline the read times out. + $left = max(1, (int) (($deadline - microtime(true)) * 1000000)); + stream_set_timeout($stream, intdiv($left, 1000000), $left % 1000000); $chunk = @fread($stream, min(65536, $limit - strlen($response))); if ($chunk === false || stream_get_meta_data($stream)['timed_out']) { $timedOut = true; @@ -139,6 +138,16 @@ function getusers_fetch($config, $timeout = 20) error_log('getusers: incomplete or too large response'); return null; } + // Every Content-Length header (if any) must be digits only and equal to + // the body length (a body cut short by an early close is refused); a + // malformed value fails closed. + preg_match_all('/^content-length:[ \t]*([^\r\n]*?)[ \t]*\r?$/im', substr($response, 0, $end), $lengths); + foreach ($lengths[1] as $length) { + if (!preg_match('/^[0-9]{1,18}$/D', $length) || (int) $length !== strlen($body)) { + error_log('getusers: body length does not match Content-Length'); + return null; + } + } return $body; } diff --git a/tests/mutation/README.md b/tests/mutation/README.md index ffa4d951..84a18519 100644 --- a/tests/mutation/README.md +++ b/tests/mutation/README.md @@ -428,7 +428,9 @@ Accepted equivalents (reasons in the target files): - `import-checks`: `upload-row-check-removed`, `upload-update-unscoped`, `upload-update-any-voucher` (the scoped row check before the finalized check already refuses those rows), `upload-update-ignores-previous-file` and - `import2-update-ignores-file` (differ only under a concurrent change). + `import2-update-ignores-file` (differ only under a concurrent change), + `members-timed-out-body-accepted` (on a TLS stream `fread()` returns false + on a read timeout, which `getusers_fetch()` refuses already). - `report-prevcond`: `prevcond-passes-prev-cond` (`unit_report()` never reads its first parameter). - `output-escaping`: the `html_escape()` around the `vreport.php` and `tinyreport.php` account links (they hold only a path and a `rawurlencode()`d value). diff --git a/tests/mutation/targets/import-checks.php b/tests/mutation/targets/import-checks.php index 7cd89330..92f8eb88 100644 --- a/tests/mutation/targets/import-checks.php +++ b/tests/mutation/targets/import-checks.php @@ -198,7 +198,7 @@ [ 'id' => 'members-error-status-accepted', 'file' => 'getusers.php', - 'search' => " if (!is_string(\$status) || !preg_match('#^HTTP/\\S+ 200( |\$)#', \$status)) {", + 'search' => " if (!preg_match('#^HTTP/\\S+ 200( |\$)#', \$status)) {", 'replace' => ' if (false) {', 'rationale' => 'A failed fetch (HTTP error status, redirect) stops with its own error.', ], @@ -219,9 +219,12 @@ [ 'id' => 'members-timed-out-body-accepted', 'file' => 'getusers.php', - 'search' => " || \$meta['timed_out']", - 'replace' => '', + 'search' => "if (\$chunk === false || stream_get_meta_data(\$stream)['timed_out']) {", + 'replace' => 'if ($chunk === false) {', 'rationale' => 'A read that timed out is refused, not returned in part.', + 'equivalent' => ['reason' => 'On a TLS stream PHP 8.5 fread() returns false when the read ' + . 'times out, so the $chunk === false test already refuses it (the stall test passes ' + . 'with the mutant); timed_out is kept as a second check.'], ], [ 'id' => 'members-broken-config-fatal', @@ -231,11 +234,25 @@ 'rationale' => 'A sync-secrets.php that does not load fails closed, not with a fatal error.', ], [ - 'id' => 'members-redirect-followed', + 'id' => 'members-deadline-ignored', + 'file' => 'getusers.php', + 'search' => '$left = max(1, (int) (($deadline - microtime(true)) * 1000000));', + 'replace' => '$left = 20000000;', + 'rationale' => 'The timeout is overall: a response that trickles in is refused at the deadline.', + ], + [ + 'id' => 'members-url-scheme-unchecked', + 'file' => 'getusers.php', + 'search' => " || (\$url['scheme'] ?? '') !== 'https'", + 'replace' => '', + 'rationale' => 'Only an https URL is fetched, also when getusers_fetch() is called directly.', + ], + [ + 'id' => 'members-url-user-accepted', 'file' => 'getusers.php', - 'search' => "'follow_location' => 0", - 'replace' => "'follow_location' => 1", - 'rationale' => 'Redirects are not followed (no other host, no plain HTTP).', + 'search' => " || isset(\$url['user'])", + 'replace' => '', + 'rationale' => 'A URL with user info (a user or a password) is refused.', ], [ 'id' => 'members-peer-name-unchecked', @@ -254,10 +271,31 @@ [ 'id' => 'members-token-not-sent', 'file' => 'getusers.php', - 'search' => "'header' => 'Authorization: Bearer ' . \$config['members_token'] . \"\\r\\nAccept: application/json\\r\\n\",", - 'replace' => "'header' => \"Accept: application/json\\r\\n\",", + 'search' => ". 'Authorization: Bearer ' . \$config['members_token'] . \"\\r\\nAccept: application/json", + 'replace' => ". \"Accept: application/json", 'rationale' => 'The request carries the configured token.', ], + [ + 'id' => 'members-content-length-ignored', + 'file' => 'getusers.php', + 'search' => ' foreach ($lengths[1] as $length) {', + 'replace' => ' foreach ([] as $length) {', + 'rationale' => 'A body that does not match its Content-Length (cut short, longer) is refused.', + ], + [ + 'id' => 'members-content-length-format-unchecked', + 'file' => 'getusers.php', + 'search' => "!preg_match('/^[0-9]{1,18}\$/D', \$length) || ", + 'replace' => '', + 'rationale' => 'A Content-Length that is not 1-18 digits fails closed.', + ], + [ + 'id' => 'members-content-length-case-sensitive', + 'file' => 'getusers.php', + 'search' => "[ \\t]*\\r?\$/im'", + 'replace' => "[ \\t]*\\r?\$/m'", + 'rationale' => 'Header names are case-insensitive: Content-Length is found in any case.', + ], [ 'id' => 'members-plain-http-url-accepted', 'file' => 'getusers.php', diff --git a/tests/reference/membership/server.php b/tests/reference/membership/server.php index b00d4fd4..9eb2dd93 100644 --- a/tests/reference/membership/server.php +++ b/tests/reference/membership/server.php @@ -36,6 +36,11 @@ * stall the member list, but only its first half, then nothing * for 3 seconds before the connection closes (a read * timeout; GetUsersTest) + * short the member list with its full Content-Length, but only + * its first half, then the connection closes at once (a + * cut-off body, no timeout; GetUsersTest) + * long the member list with a Content-Length one byte less + * badlength the member list with the Content-Length "x" * trickle the member list in 8 parts, one per second (each read * is quick, the whole response is not; GetUsersTest) * tricklehead as trickle, but 8 extra header lines, one per second @@ -58,7 +63,7 @@ $listRequestsFile = '/tmp/pgacc-membership-stub-list-requests'; $membersRequestsFile = '/tmp/pgacc-membership-stub-members-requests'; $modes = ['ok', 'malformed', 'empty', 'invalid-row', 'duplicate', 'bad-uuid', 'flow', 'overflow', 'body', - 'redirect', 'redirect-http', 'selfsigned', 'wrongname', 'error', 'stall', 'trickle', 'tricklehead']; + 'redirect', 'redirect-http', 'selfsigned', 'wrongname', 'error', 'stall', 'short', 'long', 'badlength', 'trickle', 'tricklehead']; $membersToken = (require '/app/tests/runtime/test-sync-secrets.php')['members_token']; $certificates = [ 'selfsigned' => '/etc/pgacc-test-tls/selfsigned.pem', @@ -207,11 +212,18 @@ function membership_stub_response($secure, $method, $uri, $authorization, $body, file_put_contents($pgaccStubLog, $method . ' ' . $uri . "\n", FILE_APPEND | LOCK_EX); } list($status, $responseBody) = membership_stub_response($secure, $method, $uri, $authorization, $body, $modeFile, $bodyFile, $modes); - $head = "HTTP/1.0 $status\r\nContent-Type: text/plain\r\nContent-Length: " . strlen($responseBody) + $length = (string) strlen($responseBody); + if ($secure && $status === '200 OK' && strpos($uri, '/members.php') === 0) { + $lengths = ['long' => (string) (strlen($responseBody) - 1), 'badlength' => $length . 'x']; + $length = $lengths[membership_stub_mode($modeFile)] ?? $length; + } + $head = "HTTP/1.0 $status\r\nContent-Type: text/plain\r\nContent-Length: " . $length . "\r\nConnection: close\r\n\r\n"; if ($secure && $status === '200 OK' && strpos($uri, '/members.php') === 0 && membership_stub_mode($modeFile) === 'stall') { @fwrite($client, $head . substr($responseBody, 0, intdiv(strlen($responseBody), 2))); sleep(3); + } elseif ($secure && $status === '200 OK' && strpos($uri, '/members.php') === 0 && membership_stub_mode($modeFile) === 'short') { + @fwrite($client, $head . substr($responseBody, 0, intdiv(strlen($responseBody), 2))); } elseif ($secure && $status === '200 OK' && strpos($uri, '/members.php') === 0 && in_array(membership_stub_mode($modeFile), ['trickle', 'tricklehead'], true)) { $parts = membership_stub_mode($modeFile) === 'trickle' diff --git a/tests/unit/GetUsersTest.php b/tests/unit/GetUsersTest.php index 5cd13e93..771a7e18 100644 --- a/tests/unit/GetUsersTest.php +++ b/tests/unit/GetUsersTest.php @@ -137,6 +137,13 @@ public static function refusedFetchProvider() // but members_cafile is another certificate: only that one counts. 'certificate not from members_cafile' => ['ok', ['members_cafile' => '/etc/pgacc-test-tls/selfsigned.pem']], 'another token (403)' => ['ok', ['members_token' => 'synthetic-wrong-token']], + // getusers_fetch() checks the URL itself: each of these would + // otherwise reach the stub (https on port 443) and get the list. + 'http URL' => ['ok', ['members_url' => 'http://mitglieder.piratenpartei.at/members.php']], + 'user in the URL' => ['ok', ['members_url' => 'https://synthetic@mitglieder.piratenpartei.at/members.php']], + 'password in the URL' => ['ok', ['members_url' => 'https://:synthetic@mitglieder.piratenpartei.at/members.php']], + 'URL without a host' => ['ok', ['members_url' => 'https:/members.php']], + 'URL that does not parse' => ['ok', ['members_url' => 'https:///members.php']], ]; } @@ -173,17 +180,51 @@ public function testATooLargeResponseIsRefused() } // A response that stops in the middle of the body (the stub's "stall" - // mode) is refused when the read times out, not returned in part. + // mode) is refused when the read times out, not returned in part, and + // at the deadline, not only once the stub closes the connection (after + // 3 seconds; the Content-Length check would refuse it then too). public function testATimedOutResponseIsRefused() { $config = getusers_config('sync-secrets.php'); MembershipStub::mode('stall'); + $start = microtime(true); try { $body = getusers_fetch($config, 1); + $elapsed = microtime(true) - $start; + } finally { + MembershipStub::reset(); + } + self::assertNull($body === null ? null : strlen($body)); + self::assertLessThan(2.5, $elapsed); + } + + // A 200 response whose body does not match its Content-Length is + // refused, not returned: cut short by an early close (no timeout), + // longer than the header says, or a value that is not 1-18 digits. + public static function contentLengthProvider() + { + return [ + 'body cut short by an early close' => ['short'], + 'body longer than Content-Length' => ['long'], + 'Content-Length malformed' => ['badlength'], + ]; + } + + #[PHPUnit\Framework\Attributes\DataProvider('contentLengthProvider')] + public function testABodyNotMatchingContentLengthIsRefused($mode) + { + $config = getusers_config('sync-secrets.php'); + MembershipStub::mode($mode); + $start = microtime(true); + try { + $body = getusers_fetch($config, 10); + $elapsed = microtime(true) - $start; } finally { MembershipStub::reset(); } self::assertNull($body === null ? null : strlen($body)); + // Refused because of the length, not at the deadline. + self::assertLessThan(5, $elapsed); } // The timeout is overall: a response whose headers or body arrive in