SmtpLdapPasswordReentry.test.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * A saved SMTP or LDAP bind password only goes to the server it was entered
  3. * for: changing the server asks for it again, before the save is refused.
  4. */
  5. import { describe, it, expect, beforeEach } from 'vitest';
  6. import { screen } from '@testing-library/react';
  7. import userEvent from '@testing-library/user-event';
  8. import { http, HttpResponse } from 'msw';
  9. import { render } from '../utils';
  10. import { server } from '../mocks/server';
  11. import { EmailSettings } from '../../components/EmailSettings';
  12. import { LDAPSettings } from '../../components/LDAPSettings';
  13. const AGAIN = /the address changed: enter it again/i;
  14. describe('saved server passwords', () => {
  15. beforeEach(() => {
  16. server.use(
  17. http.get('*/api/v1/auth/smtp', () =>
  18. HttpResponse.json({
  19. smtp_host: 'smtp.example',
  20. smtp_port: 587,
  21. smtp_username: 'u',
  22. smtp_password: null,
  23. smtp_security: 'starttls',
  24. smtp_auth_enabled: true,
  25. smtp_from_email: 'a@example.com',
  26. smtp_from_name: 'BamBuddy',
  27. }),
  28. ),
  29. http.get('*/api/v1/auth/advanced-auth/status', () => HttpResponse.json({ advanced_auth_enabled: false, smtp_configured: true })),
  30. http.get('*/api/v1/settings/', () =>
  31. HttpResponse.json({
  32. ldap_enabled: false,
  33. ldap_server_url: 'ldaps://ldap.example:636',
  34. ldap_bind_dn: 'cn=svc,dc=example',
  35. ldap_bind_password: '',
  36. ldap_search_base: 'dc=example',
  37. ldap_user_filter: '(uid={username})',
  38. ldap_security: 'ldaps',
  39. ldap_group_mapping: '',
  40. ldap_auto_provision: false,
  41. ldap_default_group: '',
  42. }),
  43. ),
  44. http.get('*/api/v1/auth/ldap/status', () => HttpResponse.json({ ldap_enabled: false, ldap_configured: true })),
  45. http.get('*/api/v1/groups/', () => HttpResponse.json([])),
  46. );
  47. });
  48. it('asks for the SMTP password again when the server changes', async () => {
  49. const user = userEvent.setup();
  50. render(<EmailSettings />);
  51. const host = await screen.findByDisplayValue('smtp.example');
  52. expect(screen.queryByText(AGAIN)).not.toBeInTheDocument();
  53. await user.clear(host);
  54. await user.type(host, 'smtp.elsewhere.example');
  55. expect(screen.getByText(AGAIN)).toBeInTheDocument();
  56. });
  57. it('asks for the LDAP bind password again when the server changes', async () => {
  58. const user = userEvent.setup();
  59. render(<LDAPSettings />);
  60. const url = await screen.findByDisplayValue('ldaps://ldap.example:636');
  61. expect(screen.queryByText(AGAIN)).not.toBeInTheDocument();
  62. await user.clear(url);
  63. await user.type(url, 'ldap://ldap.elsewhere.example');
  64. expect(screen.getByText(AGAIN)).toBeInTheDocument();
  65. });
  66. });