Просмотр исходного кода

Merge pull request #3920 from overleaf/as-fix-unsupported-middleware

Fix unsupported browser middleware

GitOrigin-RevId: 27dc8cef4747abba85a985c28865340bc5116ab7
Timothée Alby 5 лет назад
Родитель
Сommit
97f89f132c

+ 2 - 0
services/web/app/src/infrastructure/UnsupportedBrowserMiddleware.js

@@ -6,6 +6,8 @@ function unsupportedBrowserMiddleware(req, res, next) {
 
   const userAgent = req.headers['user-agent']
 
+  if (!userAgent) return next()
+
   const parser = Bowser.getParser(userAgent)
 
   // Allow bots through by only ignoring bots or unrecognised UA strings

+ 3 - 0
services/web/test/acceptance/config/settings.test.coffee

@@ -189,3 +189,6 @@ module.exports =
 	overleaf: true
 
 	reconfirmNotificationDays: 14
+
+	unsupportedBrowsers:
+		ie: '<=11'

+ 64 - 0
services/web/test/acceptance/src/UnsupportedBrowserTests.js

@@ -0,0 +1,64 @@
+const { expect } = require('chai')
+const User = require('./helpers/User')
+
+describe('UnsupportedBrowsers', function () {
+  beforeEach(function (done) {
+    this.user = new User()
+    this.user.login(done)
+  })
+
+  it('allows bots', function (done) {
+    this.user.request(
+      {
+        url: '/project',
+        headers: {
+          // Googlebot user agent
+          'user-agent':
+            'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
+        }
+      },
+      (error, response) => {
+        expect(error).to.not.exist
+        expect(response.statusCode).to.equal(200)
+        done()
+      }
+    )
+  })
+
+  it('allows supported browsers', function (done) {
+    this.user.request(
+      {
+        url: '/project',
+        headers: {
+          // Chrome 90 user agent
+          'user-agent':
+            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36'
+        }
+      },
+      (error, response) => {
+        expect(error).to.not.exist
+        expect(response.statusCode).to.equal(200)
+        done()
+      }
+    )
+  })
+
+  it('redirects unsupported browsers to unsupported page', function (done) {
+    this.user.request(
+      {
+        url: '/project',
+        headers: {
+          // IE11 user agent
+          'user-agent':
+            'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko'
+        }
+      },
+      (error, response) => {
+        expect(error).to.not.exist
+        expect(response.statusCode).to.equal(302)
+        expect(response.headers.location).to.equal('/unsupported-browser')
+        done()
+      }
+    )
+  })
+})