mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-18 08:31:20 +00:00
[misc] add tests for web replying with a 403 for joinProject
This commit is contained in:
parent
1ff9c1e71b
commit
d2a2b9d46e
3 changed files with 90 additions and 0 deletions
|
@ -176,6 +176,69 @@ describe('joinProject', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('when not authorized and web replies with a 403', function () {
|
||||||
|
before(function (done) {
|
||||||
|
return async.series(
|
||||||
|
[
|
||||||
|
(cb) => {
|
||||||
|
return FixturesManager.setUpProject(
|
||||||
|
{
|
||||||
|
project_id: 'forbidden',
|
||||||
|
privilegeLevel: 'owner',
|
||||||
|
project: {
|
||||||
|
name: 'Test Project'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(e, { project_id, user_id }) => {
|
||||||
|
this.project_id = project_id
|
||||||
|
this.user_id = user_id
|
||||||
|
cb(e)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
|
(cb) => {
|
||||||
|
this.client = RealTimeClient.connect()
|
||||||
|
this.client.on('connectionAccepted', cb)
|
||||||
|
},
|
||||||
|
|
||||||
|
(cb) => {
|
||||||
|
this.client.emit(
|
||||||
|
'joinProject',
|
||||||
|
{ project_id: this.project_id },
|
||||||
|
(error, project, privilegeLevel, protocolVersion) => {
|
||||||
|
this.error = error
|
||||||
|
this.project = project
|
||||||
|
this.privilegeLevel = privilegeLevel
|
||||||
|
this.protocolVersion = protocolVersion
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
],
|
||||||
|
done
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return an error', function () {
|
||||||
|
this.error.message.should.equal(
|
||||||
|
'Something went wrong in real-time service'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not have joined the project room', function (done) {
|
||||||
|
RealTimeClient.getConnectedClient(
|
||||||
|
this.client.socket.sessionid,
|
||||||
|
(error, client) => {
|
||||||
|
expect(Array.from(client.rooms).includes(this.project_id)).to.equal(
|
||||||
|
false
|
||||||
|
)
|
||||||
|
done()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
return describe('when over rate limit', function () {
|
return describe('when over rate limit', function () {
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
return async.series(
|
return async.series(
|
||||||
|
|
|
@ -38,6 +38,9 @@ module.exports = MockWebServer = {
|
||||||
joinProjectRequest(req, res, next) {
|
joinProjectRequest(req, res, next) {
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
const { user_id } = req.query
|
const { user_id } = req.query
|
||||||
|
if (project_id === 'forbidden') {
|
||||||
|
return res.status(403).send()
|
||||||
|
}
|
||||||
if (project_id === 'rate-limited') {
|
if (project_id === 'rate-limited') {
|
||||||
return res.status(429).send()
|
return res.status(429).send()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -91,6 +91,30 @@ describe('WebApiManager', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('when web replies with a 403', function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
this.request.post = sinon
|
||||||
|
.stub()
|
||||||
|
.callsArgWith(1, null, { statusCode: 403 }, null)
|
||||||
|
this.WebApiManager.joinProject(
|
||||||
|
this.project_id,
|
||||||
|
this.user_id,
|
||||||
|
this.callback
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should call the callback with an error', function () {
|
||||||
|
this.callback
|
||||||
|
.calledWith(
|
||||||
|
sinon.match({
|
||||||
|
message: 'non-success status code from web',
|
||||||
|
info: { statusCode: 403 }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.should.equal(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('with an error from web', function () {
|
describe('with an error from web', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.request.post = sinon
|
this.request.post = sinon
|
||||||
|
|
Loading…
Reference in a new issue