HttpPermissionsPolicyTests.mjs 1.5 KB

1234567891011121314151617181920212223242526272829
  1. import { expect } from 'chai'
  2. import fetch from 'node-fetch'
  3. import Settings from '@overleaf/settings'
  4. const BASE_URL = `http://${process.env.HTTP_TEST_HOST || '127.0.0.1'}:23000`
  5. describe('HttpPermissionsPolicy', function () {
  6. it('should have permissions-policy header on user-facing pages', async function () {
  7. const response = await fetch(BASE_URL)
  8. expect(response.headers.get('permissions-policy')).to.equal(
  9. 'accelerometer=(), attribution-reporting=(), browsing-topics=(), camera=(), display-capture=(), encrypted-media=(), gamepad=(), geolocation=(), gyroscope=(), hid=(), identity-credentials-get=(), idle-detection=(), local-fonts=(), magnetometer=(), midi=(), otp-credentials=(), payment=(), picture-in-picture=(), screen-wake-lock=(), serial=(), storage-access=(), usb=(), window-management=(), xr-spatial-tracking=(), autoplay=(self "https://videos.ctfassets.net"), fullscreen=(self), on-device-speech-recognition=(self)'
  10. )
  11. })
  12. it('should not have permissions-policy header on requests for non-rendered content', async function () {
  13. const response = await fetch(`${BASE_URL}/dev/csrf`)
  14. expect(response.headers.get('permissions-policy')).to.be.null
  15. })
  16. describe('when permissions policy is disabled', function () {
  17. it('it adds no additional headers', async function () {
  18. Settings.useHttpPermissionsPolicy = false
  19. const response = await fetch(BASE_URL)
  20. expect(response.headers.get('permissions-policy')).to.be.null
  21. })
  22. })
  23. })