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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. });
  24. test('Compose and examples use a dedicated file-backed Webmail SSO secret', async () => {
  25. const [compose, env, pluginConfig, docs] = await Promise.all([
  26. read('docker-compose.yml'),
  27. read('.env.example'),
  28. read('docker/roundcube/plugins/mailhub_sso/config.inc.php.dist'),
  29. read('docs/webmail-sso.md'),
  30. ]);
  31. assert.match(compose, /WEBMAIL_SSO_SECRET_FILE:\s*\/data\/secrets\/webmail_sso_secret/);
  32. assert.doesNotMatch(compose, /webmail_sso_secret:\s*\n\s+file:/);
  33. assert.doesNotMatch(compose, /^\s{2}roundcube:/m);
  34. assert.match(env, /^WEBMAIL_SSO_URL=\s*$/m);
  35. assert.match(env, /WEBMAIL_SSO_TICKET_TTL_SECONDS=60/);
  36. assert.match(env, /WEBMAIL_SSO_CREDENTIAL_TTL_SECONDS=43200/);
  37. assert.match(pluginConfig, /mailhub_sso_secret_file'\]\s*=\s*'\/run\/secrets\/webmail_sso_secret'/);
  38. assert.match(pluginConfig, /mailhub_sso_audience'\]\s*=\s*'https:\/\//);
  39. assert.match(docs, /不运行 Roundcube/);
  40. });