Skip to content

Add the member list for Liquid (liquid-members.php) - #4

Merged
PeterTheOne merged 4 commits into
mainfrom
feature/liquid-members
Nov 1, 2026
Merged

PeterTheOne merged 4 commits into
mainfrom
feature/liquid-members

Conversation

@PeterTheOne

@PeterTheOne PeterTheOne commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Behaviour

  • New endpoint internal/liquid-members.php (code in liquid/members-api.php) on the existing internal listener, next to pgacc's members.php. It replaces adm1.php of the old membership system (public, shared-key encryption).
  • Same authentication as members.php, with its own secrets file (FastCGI parameter LIQUID_MEMBERS_SECRETS): the socket's address must be in the peer list and the request must carry the bearer token. Otherwise 403, empty body. Any later error: 503, empty body; the log gets only the exception class and code.
  • Each endpoint reads only its own secrets parameter, so Liquid's peer and token are refused by /members.php, and pgacc's by /liquid-members.php.
  • members_api_secrets and members_api_allowed move unchanged from pgacc/members-api.php into lib/internal-api.php, which both endpoints use. This is a pure refactor; members-test.php passes unchanged.

Data contract

200, application/json, ordered by id:
[{"id":1,"lo":38,"eligible":true,"email":"…","regions":["AT130"]}, …]

  • members, lo: exactly those of the view pgacc_members; liquid_members is built on it.
  • eligible (boolean): the rule of adm1.php. Field 35 must be on or before today, and either field 26 + 30 days ≥ today or field 35 + 30 days ≥ today. Both fields count only as real calendar dates (DATE_FORMAT(STR_TO_DATE(v)) = v, and no zero year, month or day whatever the SQL mode). So "paid until 31 Dec" is eligible through 30 Jan and not on 31 Jan.
  • email: field 12, or field 33 when field 12 is mitglied@piratenpartei.at. It is set only when the member is eligible, otherwise null. An address outside Liquid's rule is sent as null, and the member is still listed. The rule is the same regular expression as the consumer's member_sync() (Member sync from Admidio (replaces getaccounts.php) uniliquid/core#5): a plain local@domain with a dotted domain, no quoted local parts and no IP literals, at most 254 characters. The member stays listed because one such address would make Liquid reject the whole list.
  • regions: the distinct, sorted NUTS codes of postcode fields 4 and 39 (trimmed, exact match) from the new table liquid_region_plz. Members without one get [].
  • liquid/liquid_region_plz.sql holds 85 postcodes: AT130 has 23, AT221 has 62. The file is idempotent: CREATE TABLE IF NOT EXISTS, then DELETE + INSERT in one transaction.
  • Apply in this order: pgacc_members.sql → liquid_region_plz.sql → liquid_members.sql. The reader 'liquid_members'@'localhost' has SELECT on the view only. The view is SQL SECURITY DEFINER.

Tests

tests/liquid-members-test.php adds 97 checks, all with synthetic data. The harness mounts ../liquid, adds the user to users.sql, and grants.sh applies the files in the explicit order above.

  • Refusals (403): the same cases as for members.php, plus the cross-endpoint cases in both directions, also through the entry point.
  • Errors (503): three cases, plus pgacc's reader trying the Liquid view. The test also checks that the log has only the class and code.
  • Grants: the Liquid reader sees only its view, not the adm_* tables, pgacc_members, the accsync view or the region table. pgacc's reader sees neither the Liquid view nor the region table.
  • View:
    • the same members and LO as pgacc_members;
    • the email fallback 12→33, the email only when eligible, and the invalid, overlong and apostrophe cases;
    • eligibility boundaries: field 35 tomorrow or today, ±30/31 days for fields 35 and 26, 31 Dec → 30 Jan yes and 31 Jan no, paid without field 35 → no;
    • calendar-invalid, zero-component, unpadded, trailing-text and other-format dates, and leap days;
    • regions: Vienna + Graz → both, the same code twice → once, unknown or 01010 → [], spaces trimmed, a postcode with two codes → both;
    • the region file applied twice → the same 85 rows.
  • Entry point: tested through PHP's built-in web server: 200 with Content-Type, and 403 in the refusal cases.
  • tests/run.sh: all three test files pass.
  • Line coverage: pcov, run locally and not in CI, covers every changed line. liquid_members_api_main() is covered by the entry-point test, which runs in a separate process.
  • Mutation: one small local run on the changed lines only, 16 mutants, not in CI. One mutant survived the check on field 26's date format; a test with trailing text (2026-12-31x) was added for it. After the switch to the consumer's regex, a second small run on the email lines found that the /D modifier (an end anchor like PostgreSQL's) was not pinned by any test, so a trailing-newline test was added. The <= 254 check is now load-bearing and tested.

Review

Astra found one issue (P2): zero-component dates such as 0000-00-00 or 2026-06-00 passed the check, because the SQL mode has no NO_ZERO_DATE/NO_ZERO_IN_DATE. A zero accreditation date then made a paid member eligible. The regression tests were red first; the fix is in the second commit.

Opus review, fixed in the third commit:

  • liquid_region_plz now has the Admidio tables' collation (utf8, utf8_unicode_ci). Before, the join failed ("Illegal mix of collations") on a utf8_general_ci database default. A test reproduced this red first.
  • The date comment is honest about ALLOW_INVALID_DATES.
  • The redundant zero-component guard on field 26 is dropped, since adding 30 days to such a value gives NULL; the tests pin this.
  • grants.sh keeps the pgacc/*.sql glob.

Astra found nothing on that commit.

Deliberate deviation (email): adm1.php used field 33 only if it had more than 4 characters, otherwise it kept mitglied@piratenpartei.at. Here a missing or empty field 33 gives null, so no Liquid account gets the generic address. The comparison with that address ignores case and trailing spaces (the collation). This is documented in the README.

⚠ Owner decision needed

Owner decision needed: the 85 postcode→NUTS rows from the old nutsplz table (origin and licence undocumented; plain geographic facts). They come from the old membership system's nutsplz table, rows AT130 and AT221 only. If they should not be published in this GPL-2.0-only repository, the two lists can be compiled by hand from the Post's public postcode directory before merging.

🤖 Generated with Claude Code

PeterTheOne and others added 4 commits November 1, 2026 21:39
Liquid fetches the active members from the internal listener, as pgacc
does from members.php: TLS, its own token and peer list, 403 or 503 with
an empty body. The view liquid_members is built on pgacc_members (same
members and LO) and adds eligibility as adm1.php of the old membership
system (accredited, and paid or trial month, +30 days, calendar dates
only), the email (field 12, or 33 for mitglied@piratenpartei.at; only
when eligible; an invalid one is sent as null) and the regions (NUTS
codes of postcode fields 4 and 39 from the new table liquid_region_plz:
AT130 and AT221, 85 postcodes).

The token and peer check moves unchanged from pgacc/members-api.php into
lib/internal-api.php, shared by both endpoints. The tests apply the SQL
files in the deployment's order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without NO_ZERO_DATE/NO_ZERO_IN_DATE in the SQL mode, values such as
0000-00-00 or 2026-06-00 pass STR_TO_DATE and the format round trip; a
zero accreditation date then compared as past and made a paid member
eligible. Reject zero components explicitly in fields 35 and 26.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- liquid_region_plz gets the Admidio tables' character set and collation
  (utf8, utf8_unicode_ci): with another database default the join with
  adm_user_data failed with "Illegal mix of collations". Tested with a
  utf8mb3_general_ci database default.
- The date comment in liquid_members.sql no longer overclaims
  (ALLOW_INVALID_DATES); the redundant zero-component guard on field 26
  is dropped (adding 30 days to such a value gives NULL; tested).
- README: the deliberate difference from adm1.php's email fallback.
- tests/grants.sh keeps the pgacc/*.sql glob.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Liquid's member_sync() rejects the whole list for an email that is not
a plain local@domain with a dotted domain; PHP's FILTER_VALIDATE_EMAIL
also accepts quoted local parts and IP literals. The producer now uses
the consumer's regular expression (same pattern, /D for PostgreSQL's
end anchor) and sends null otherwise. Tested: quoted local part, IP
literal, domain without a dot, trailing newline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PeterTheOne
PeterTheOne merged commit 23a0391 into main Nov 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant