bad-urls.test.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import * as assert from 'node:assert/strict';
  2. import { describe, it, before, after } from 'node:test';
  3. import nodejs from '../dist/index.js';
  4. import { loadFixture } from './test-utils.js';
  5. describe('Bad URLs', () => {
  6. /** @type {import('./test-utils').Fixture} */
  7. let fixture;
  8. let devPreview;
  9. before(async () => {
  10. fixture = await loadFixture({
  11. root: './fixtures/bad-urls/',
  12. output: 'server',
  13. adapter: nodejs({ mode: 'standalone' }),
  14. });
  15. await fixture.build();
  16. devPreview = await fixture.preview();
  17. });
  18. after(async () => {
  19. await devPreview.stop();
  20. });
  21. it('Does not crash on bad urls', async () => {
  22. const weirdURLs = [
  23. '/\\xfs.bxss.me%3Fastrojs.com/hello-world',
  24. '/asdasdasd@ax_zX=.zxczas🐥%/úadasd000%/',
  25. '%',
  26. '%80',
  27. '%c',
  28. '%c0%80',
  29. '%20foobar%',
  30. ];
  31. const statusCodes = [400, 404, 500];
  32. for (const weirdUrl of weirdURLs) {
  33. const fetchResult = await fixture.fetch(weirdUrl);
  34. assert.equal(
  35. statusCodes.includes(fetchResult.status),
  36. true,
  37. `${weirdUrl} returned something else than 400, 404, or 500`
  38. );
  39. }
  40. const stillWork = await fixture.fetch('/');
  41. const text = await stillWork.text();
  42. assert.equal(text, '<!DOCTYPE html>Hello!');
  43. });
  44. });