mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-05 15:19:02 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -3,8 +3,8 @@ const { expect } = require('chai')
|
||||
const modulePath = '../../../../app/src/infrastructure/SessionStoreManager.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('SessionStoreManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('SessionStoreManager', function () {
|
||||
beforeEach(function () {
|
||||
this.SessionStoreManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'@overleaf/metrics': (this.Metrics = { inc: sinon.stub() })
|
||||
@@ -17,34 +17,34 @@ describe('SessionStoreManager', function() {
|
||||
})
|
||||
}
|
||||
})
|
||||
describe('enableValidationToken', function() {
|
||||
beforeEach(function() {
|
||||
describe('enableValidationToken', function () {
|
||||
beforeEach(function () {
|
||||
this.originalGenerate = this.sessionStore.generate
|
||||
this.SessionStoreManager.enableValidationToken(this.sessionStore)
|
||||
})
|
||||
it('should set up a wrapper around the generate function', function() {
|
||||
it('should set up a wrapper around the generate function', function () {
|
||||
expect(this.sessionStore.generate).to.not.equal(this.originalGenerate)
|
||||
})
|
||||
it('should add a validationToken when the generate function is called', function() {
|
||||
it('should add a validationToken when the generate function is called', function () {
|
||||
this.req = { sessionID: '123456789' }
|
||||
this.sessionStore.generate(this.req)
|
||||
expect(this.req.session.validationToken).to.equal('v1:6789')
|
||||
})
|
||||
it('should not allow the token to be overwritten', function() {
|
||||
it('should not allow the token to be overwritten', function () {
|
||||
this.req = { sessionID: '123456789' }
|
||||
this.sessionStore.generate(this.req)
|
||||
this.req.session.validationToken = 'try-to-overwrite-token'
|
||||
expect(this.req.session.validationToken).to.equal('v1:6789')
|
||||
})
|
||||
})
|
||||
describe('validationMiddleware', function() {
|
||||
this.beforeEach(function() {
|
||||
describe('validationMiddleware', function () {
|
||||
this.beforeEach(function () {
|
||||
this.SessionStoreManager.enableValidationToken(this.sessionStore)
|
||||
this.req = { sessionID: '123456789' }
|
||||
this.next = sinon.stub()
|
||||
this.sessionStore.generate(this.req)
|
||||
})
|
||||
it('should accept the request when the session id matches the validation token', function() {
|
||||
it('should accept the request when the session id matches the validation token', function () {
|
||||
this.SessionStoreManager.validationMiddleware(
|
||||
this.req,
|
||||
this.res,
|
||||
@@ -52,7 +52,7 @@ describe('SessionStoreManager', function() {
|
||||
)
|
||||
expect(this.next).to.be.calledWithExactly()
|
||||
})
|
||||
it('should destroy the session and return an error when the session id does not match the validation token', function() {
|
||||
it('should destroy the session and return an error when the session id does not match the validation token', function () {
|
||||
this.req.sessionID = 'abcdefghijklmnopqrstuvwxyz'
|
||||
this.next = sinon.stub()
|
||||
this.SessionStoreManager.validationMiddleware(
|
||||
@@ -67,7 +67,7 @@ describe('SessionStoreManager', function() {
|
||||
.and(sinon.match.has('message', 'invalid session'))
|
||||
)
|
||||
})
|
||||
it('should accept the request when the session does not have a validation token', function() {
|
||||
it('should accept the request when the session does not have a validation token', function () {
|
||||
this.req = { sessionID: '123456789', session: {} }
|
||||
this.next = sinon.stub()
|
||||
this.SessionStoreManager.validationMiddleware(
|
||||
@@ -78,21 +78,21 @@ describe('SessionStoreManager', function() {
|
||||
expect(this.next).to.be.calledWithExactly()
|
||||
})
|
||||
})
|
||||
describe('hasValidationToken', function() {
|
||||
this.beforeEach(function() {
|
||||
describe('hasValidationToken', function () {
|
||||
this.beforeEach(function () {
|
||||
this.req = { sessionID: '123456789' }
|
||||
})
|
||||
it('should return true when the session is valid', function() {
|
||||
it('should return true when the session is valid', function () {
|
||||
this.req.session = { validationToken: 'v1:6789' }
|
||||
const result = this.SessionStoreManager.hasValidationToken(this.req)
|
||||
expect(result).to.equal(true)
|
||||
})
|
||||
it('should return false when the session is valid', function() {
|
||||
it('should return false when the session is valid', function () {
|
||||
this.req.session = { validationToken: 'v1:abcd' }
|
||||
const result = this.SessionStoreManager.hasValidationToken(this.req)
|
||||
expect(result).to.equal(true)
|
||||
})
|
||||
it('should return false when the validation token is missing', function() {
|
||||
it('should return false when the validation token is missing', function () {
|
||||
this.req.session = {}
|
||||
const result = this.SessionStoreManager.hasValidationToken(this.req)
|
||||
expect(result).to.equal(false)
|
||||
|
||||
Reference in New Issue
Block a user