AdminEmailTests.mjs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import OError from '@overleaf/o-error'
  2. import { expect } from 'chai'
  3. import async from 'async'
  4. import User from './helpers/User.mjs'
  5. describe('AdminEmails', function () {
  6. beforeEach(function (done) {
  7. this.timeout(5000)
  8. done()
  9. })
  10. describe('an admin with an invalid email address', function () {
  11. before(function (done) {
  12. this.badUser = new User({ email: 'alice@evil.com' })
  13. async.series(
  14. [
  15. cb => this.badUser.ensureUserExists(cb),
  16. cb => this.badUser.ensureAdmin(cb),
  17. ],
  18. done
  19. )
  20. })
  21. it('should block the user', function (done) {
  22. this.badUser.login(err => {
  23. // User.login refreshes the csrf token after login.
  24. // Seeing the csrf token request fail "after login" indicates a successful login.
  25. expect(OError.getFullStack(err)).to.match(/TaggedError: after login/)
  26. expect(OError.getFullStack(err)).to.match(
  27. /get csrf token failed: status=500 /
  28. )
  29. this.badUser.getProjectListPage((err, statusCode) => {
  30. expect(err).to.not.exist
  31. expect(statusCode).to.equal(500)
  32. done()
  33. })
  34. })
  35. })
  36. })
  37. describe('an admin with a valid email address', function () {
  38. before(function (done) {
  39. this.goodUser = new User({ email: 'alice@example.com' })
  40. async.series(
  41. [
  42. cb => this.goodUser.ensureUserExists(cb),
  43. cb => this.goodUser.ensureAdmin(cb),
  44. ],
  45. done
  46. )
  47. })
  48. it('should not block the user', function (done) {
  49. this.goodUser.login(err => {
  50. expect(err).to.not.exist
  51. this.goodUser.getProjectListPage((err, statusCode) => {
  52. expect(err).to.not.exist
  53. expect(statusCode).to.equal(200)
  54. done()
  55. })
  56. })
  57. })
  58. })
  59. })