UnsupportedBrowserTests.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const { expect } = require('chai')
  2. const User = require('./helpers/User')
  3. describe('UnsupportedBrowsers', function () {
  4. beforeEach(function (done) {
  5. this.user = new User()
  6. this.user.login(done)
  7. })
  8. it('allows bots', function (done) {
  9. this.user.request(
  10. {
  11. url: '/project',
  12. headers: {
  13. // Googlebot user agent
  14. 'user-agent':
  15. 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
  16. },
  17. },
  18. (error, response) => {
  19. expect(error).to.not.exist
  20. expect(response.statusCode).to.equal(200)
  21. done()
  22. }
  23. )
  24. })
  25. it('allows supported browsers', function (done) {
  26. this.user.request(
  27. {
  28. url: '/project',
  29. headers: {
  30. // Chrome 90 user agent
  31. 'user-agent':
  32. 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36',
  33. },
  34. },
  35. (error, response) => {
  36. expect(error).to.not.exist
  37. expect(response.statusCode).to.equal(200)
  38. done()
  39. }
  40. )
  41. })
  42. it('redirects unsupported browsers to unsupported page', function (done) {
  43. const url = '/project'
  44. this.user.request(
  45. {
  46. url,
  47. headers: {
  48. // IE11 user agent
  49. 'user-agent':
  50. 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko',
  51. },
  52. },
  53. (error, response) => {
  54. expect(error).to.not.exist
  55. expect(response.statusCode).to.equal(302)
  56. expect(response.headers.location).to.equal(
  57. '/unsupported-browser?fromURL=' + encodeURIComponent(url)
  58. )
  59. done()
  60. }
  61. )
  62. })
  63. it('shows the previous URL', function (done) {
  64. const url = '/project/60867f47174dfd13f1e00000'
  65. this.user.request(
  66. {
  67. url: '/unsupported-browser?fromURL=' + encodeURIComponent(url),
  68. headers: {
  69. // IE11 user agent
  70. 'user-agent':
  71. 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko',
  72. },
  73. },
  74. (error, response, body) => {
  75. expect(error).to.not.exist
  76. expect(response.statusCode).to.equal(200)
  77. expect(body).to.include('URL:')
  78. expect(body).to.include(url)
  79. done()
  80. }
  81. )
  82. })
  83. it('shows a sanitized URL', function (done) {
  84. const url = 'https://evil.com/the/pathname'
  85. this.user.request(
  86. {
  87. url: '/unsupported-browser?fromURL=' + encodeURIComponent(url),
  88. headers: {
  89. // IE11 user agent
  90. 'user-agent':
  91. 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko',
  92. },
  93. },
  94. (error, response, body) => {
  95. expect(error).to.not.exist
  96. expect(response.statusCode).to.equal(200)
  97. expect(body).to.include('URL:')
  98. expect(body).to.not.include('evil.com')
  99. expect(body).to.include('/the/pathname')
  100. done()
  101. }
  102. )
  103. })
  104. })