roundcube-webmail-sso-config.test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import assert from 'node:assert/strict';
  2. import { readFile } from 'node:fs/promises';
  3. import test from 'node:test';
  4. const read = (path) => readFile(new URL(`../${path}`, import.meta.url), 'utf8');
  5. test('Roundcube SSO accepts the launch ticket from POST only', async () => {
  6. const plugin = await read('docker/roundcube/plugins/mailhub_sso/mailhub_sso.php');
  7. assert.match(plugin, /REQUEST_METHOD[^\n]+POST/);
  8. assert.match(plugin, /get_input_string\('mailhub_ticket',\s*rcube_utils::INPUT_POST\)/);
  9. assert.doesNotMatch(plugin, /\$_GET\s*\[/);
  10. assert.doesNotMatch(plugin, /\$_REQUEST\s*\[/);
  11. assert.match(plugin, /'task'\]\s*=\s*'login'/);
  12. assert.match(plugin, /'action'\]\s*=\s*'login'/);
  13. });
  14. test('Roundcube SSO keeps sensitive values out of output and error logging', async () => {
  15. const plugin = await read('docker/roundcube/plugins/mailhub_sso/mailhub_sso.php');
  16. assert.doesNotMatch(plugin, /\b(?:echo|print|print_r|var_dump|error_log)\b/);
  17. assert.doesNotMatch(plugin, /CURLOPT_VERBOSE\s*=>\s*true/);
  18. assert.match(plugin, /CURLOPT_FOLLOWLOCATION\s*=>\s*false/);
  19. assert.match(plugin, /Authorization: Bearer /);
  20. assert.match(plugin, /'credential'\s*=>\s*\$credential/);
  21. assert.match(plugin, /add_hook\('session_destroy'/);
  22. assert.match(plugin, /mailhub_sso\.ssofailed/);
  23. assert.match(plugin, /array_fill_keys\(array_keys\(\$args\),\s*null\)/);
  24. assert.match(plugin, /\$redirect\['_task'\]\s*=\s*'mail'/);
  25. assert.match(plugin, /\$redirect\['_mbox'\]\s*=\s*'INBOX'/);
  26. assert.doesNotMatch(plugin, /X-MailHub-SSO-Diagnostic/i);
  27. });
  28. test('Compose and examples use a dedicated file-backed Webmail SSO secret', async () => {
  29. const [compose, env, pluginConfig, docs] = await Promise.all([
  30. read('docker-compose.yml'),
  31. read('.env.example'),
  32. read('docker/roundcube/plugins/mailhub_sso/config.inc.php.dist'),
  33. read('docs/webmail-sso.md'),
  34. ]);
  35. assert.match(compose, /WEBMAIL_SSO_SECRET_FILE:\s*\/data\/secrets\/webmail_sso_secret/);
  36. assert.doesNotMatch(compose, /webmail_sso_secret:\s*\n\s+file:/);
  37. assert.doesNotMatch(compose, /^\s{2}roundcube:/m);
  38. assert.match(env, /^WEBMAIL_SSO_URL=\s*$/m);
  39. assert.match(env, /^WEBMAIL_SSO_READER_GID=1000$/m);
  40. assert.match(env, /WEBMAIL_SSO_TICKET_TTL_SECONDS=60/);
  41. assert.match(env, /WEBMAIL_SSO_CREDENTIAL_TTL_SECONDS=43200/);
  42. assert.match(pluginConfig, /mailhub_sso_secret_file'\]\s*=\s*'\/run\/secrets\/webmail_sso_secret'/);
  43. assert.match(pluginConfig, /mailhub_sso_audience'\]\s*=\s*'https:\/\//);
  44. assert.match(docs, /不运行 Roundcube/);
  45. assert.match(docs, /WEBMAIL_SSO_READER_GID=33/);
  46. assert.match(docs, /PHP 工作进程的实际主组 GID/);
  47. assert.doesNotMatch(docs, /group_add:/);
  48. assert.match(docs, /in\.ss5\.xyz:host-gateway/);
  49. });