Files
nextcloud/php/tests/seed-desec-mock-config.php
T
Simon L. 4c8012adcd test(desec): end-to-end Playwright coverage against a local mock
- desec-mock.mjs: a dependency-free Node mock of the deSEC API endpoints the code
  uses, with the real status-code semantics (202 on account creation, 403 until
  verified then 200 + token, 201/409 on domain creation) plus /__control hooks to
  verify and reset state.
- desec-register.spec.js / desec-existing.spec.js drive the real AIO UI through
  the register -> verify -> domain flow and the existing-account login flow;
  desec-helpers.js holds the shared login helper. Each scenario ends by setting a
  domain, so they run as separate CI steps with a re-seed in between.
- seed-desec-mock-config.php points desec_api_base / desec_update_url at the mock
  (config key only, no env override, so production is unaffected) and seeds a
  known master password, since seeding configuration.json makes AIO consider
  itself already installed and /setup no longer shows a generated password.
- Both Playwright workflows start the mock, mount ./community-containers so the
  caddy/dnsmasq definitions enabled by the flow are present, seed the config, and
  run the two deSEC specs with a re-seed between them.

Co-Authored-By: szaimen <42591237+szaimen@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Simon L. <szaimen@e.mail.de>
2026-06-18 13:19:16 +02:00

55 lines
2.5 KiB
PHP

<?php
// Test helper: point the running mastercontainer's deSEC integration at a local mock by
// writing the (config-only) desec_api_base / desec_update_url keys into configuration.json.
// Run inside the mastercontainer via `docker exec` from the Playwright CI workflows; there
// is no env override for these on purpose (see ConfigurationManager::$desecApiBase).
//
// Writing configuration.json makes Setup::CanBeInstalled() return false, so /setup no longer
// renders the initial-password page and no master password is generated. To keep the deSEC
// Playwright test able to log in, this helper also seeds a known master password (passed via
// the AIO_TEST_PASSWORD env var) that the test then uses directly. The password is stored in
// plaintext, which matches how AIO compares it (AuthManager::CheckCredentials uses
// hash_equals against the plaintext config value).
//
// Re-running this helper also RESETS the deSEC-specific state (domain, desec_email and the
// DESEC_TOKEN / DESEC_PASSWORD secrets) so that a deSEC flow which already registered a domain
// in a previous test does not bleed into the next test (where the registration UI only renders
// while no domain is set). The Playwright deSEC scenarios are therefore each run as a separate
// CI step with a re-seed in between (see the Playwright workflows). Other config and secrets
// are preserved.
//
// Usage: AIO_TEST_PASSWORD=... php seed-desec-mock-config.php <api_base> <update_url>
declare(strict_types=1);
$apiBase = $argv[1] ?? '';
$updateUrl = $argv[2] ?? '';
if ($apiBase === '' || $updateUrl === '') {
fwrite(STDERR, "usage: php seed-desec-mock-config.php <api_base> <update_url>\n");
exit(1);
}
$password = getenv('AIO_TEST_PASSWORD');
if ($password === false || $password === '') {
fwrite(STDERR, "AIO_TEST_PASSWORD env var must be set to the master password to seed\n");
exit(1);
}
$file = '/mnt/docker-aio-config/data/configuration.json';
$config = is_file($file) ? json_decode((string)file_get_contents($file), true) : [];
if (!is_array($config)) {
$config = [];
}
$config['desec_api_base'] = $apiBase;
$config['desec_update_url'] = $updateUrl;
$config['password'] = $password;
// Reset any deSEC state from a previous test run so the registration UI renders again.
unset($config['domain'], $config['desec_email']);
if (isset($config['secrets']) && is_array($config['secrets'])) {
unset($config['secrets']['DESEC_TOKEN'], $config['secrets']['DESEC_PASSWORD']);
}
file_put_contents($file, json_encode($config, JSON_PRETTY_PRINT));
echo "Seeded deSEC mock config into $file\n";