UnsupportedBrowserTests.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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('redirects unsupported browsers from any page', function (done) {
  64. const url = '/foo/bar/baz'
  65. this.user.request(
  66. {
  67. 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) => {
  75. expect(error).to.not.exist
  76. expect(response.statusCode).to.equal(302)
  77. expect(response.headers.location).to.equal(
  78. '/unsupported-browser?fromURL=' + encodeURIComponent(url)
  79. )
  80. done()
  81. }
  82. )
  83. })
  84. it('should render the unsupported browser page for unsupported browser', function (done) {
  85. const url =
  86. '/unsupported-browser?fromURL=' + encodeURIComponent('/foo/bar/baz')
  87. this.user.request(
  88. {
  89. url,
  90. headers: {
  91. // IE11 user agent
  92. 'user-agent':
  93. 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko',
  94. },
  95. },
  96. (error, response) => {
  97. expect(error).to.not.exist
  98. expect(response.statusCode).to.equal(200)
  99. done()
  100. }
  101. )
  102. })
  103. it('shows the previous URL', function (done) {
  104. const url = '/project/60867f47174dfd13f1e00000'
  105. this.user.request(
  106. {
  107. url: '/unsupported-browser?fromURL=' + encodeURIComponent(url),
  108. headers: {
  109. // IE11 user agent
  110. 'user-agent':
  111. 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko',
  112. },
  113. },
  114. (error, response, body) => {
  115. expect(error).to.not.exist
  116. expect(response.statusCode).to.equal(200)
  117. expect(body).to.include('URL:')
  118. expect(body).to.include(url)
  119. done()
  120. }
  121. )
  122. })
  123. it('shows a sanitized URL', function (done) {
  124. const url = 'https://evil.com/the/pathname'
  125. this.user.request(
  126. {
  127. url: '/unsupported-browser?fromURL=' + encodeURIComponent(url),
  128. headers: {
  129. // IE11 user agent
  130. 'user-agent':
  131. 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko',
  132. },
  133. },
  134. (error, response, body) => {
  135. expect(error).to.not.exist
  136. expect(response.statusCode).to.equal(200)
  137. expect(body).to.include('URL:')
  138. expect(body).to.not.include('evil.com')
  139. expect(body).to.include('/the/pathname')
  140. done()
  141. }
  142. )
  143. })
  144. })