externalCameraTest.test.ts 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * The camera test sends the camera URL, which may carry the camera login, in
  3. * its body: a query string ends up in the server's access log.
  4. */
  5. import { describe, it, expect, afterEach } from 'vitest';
  6. import { http, HttpResponse } from 'msw';
  7. import { server } from '../mocks/server';
  8. import { api } from '../../api/client';
  9. afterEach(() => server.resetHandlers());
  10. describe('testExternalCamera', () => {
  11. it('sends the URL in the body, not the query', async () => {
  12. let seenUrl = '';
  13. let body: unknown = null;
  14. server.use(
  15. http.post('*/api/v1/printers/:id/camera/external/test', async ({ request }) => {
  16. seenUrl = request.url;
  17. body = await request.json();
  18. return HttpResponse.json({ success: true });
  19. }),
  20. );
  21. await api.testExternalCamera(3, 'rtsp://cam:pw123@10.0.0.5/s', 'rtsp');
  22. expect(seenUrl).not.toContain('pw123');
  23. expect(new URL(seenUrl).search).toBe('');
  24. expect(body).toEqual({ url: 'rtsp://cam:pw123@10.0.0.5/s', camera_type: 'rtsp' });
  25. });
  26. });