mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add acceptance test for unauthorized project joining
This commit is contained in:
parent
02c0a3a867
commit
dc60f2b736
3 changed files with 62 additions and 36 deletions
|
@ -16,7 +16,9 @@ module.exports = WebsocketController =
|
|||
if !privilegeLevel or privilegeLevel == ""
|
||||
err = new Error("not authorized")
|
||||
logger.error {err, project_id, user_id}, "user is not authorized to join project"
|
||||
return callback(err)
|
||||
# Don't send an error object since socket.io can apparently
|
||||
# only serialize JSON.
|
||||
return callback({message: err.message})
|
||||
|
||||
client.set("user_id", user_id)
|
||||
client.set("project_id", project_id)
|
||||
|
|
|
@ -6,39 +6,63 @@ RealTimeClient = require "./helpers/RealTimeClient"
|
|||
MockWebClient = require "./helpers/MockWebClient"
|
||||
|
||||
describe "joinProject", ->
|
||||
before (done) ->
|
||||
@user_id = "mock-user-id"
|
||||
@project_id = "mock-project-id"
|
||||
privileges = {}
|
||||
privileges[@user_id] = "owner"
|
||||
MockWebClient.createMockProject(@project_id, privileges, {
|
||||
name: "Test Project"
|
||||
})
|
||||
MockWebClient.run (error) =>
|
||||
throw error if error?
|
||||
RealTimeClient.setSession {
|
||||
user: { _id: @user_id }
|
||||
}, (error) =>
|
||||
describe "when authorized", ->
|
||||
before (done) ->
|
||||
@user_id = "mock-user-id"
|
||||
@project_id = "mock-project-id"
|
||||
privileges = {}
|
||||
privileges[@user_id] = "owner"
|
||||
MockWebClient.createMockProject(@project_id, privileges, {
|
||||
name: "Test Project"
|
||||
})
|
||||
MockWebClient.run (error) =>
|
||||
throw error if error?
|
||||
@client = RealTimeClient.connect()
|
||||
@client.emit "joinProject", {
|
||||
project_id: @project_id
|
||||
}, (error, @project, @privilegeLevel, @protocolVersion) =>
|
||||
RealTimeClient.setSession {
|
||||
user: { _id: @user_id }
|
||||
}, (error) =>
|
||||
throw error if error?
|
||||
done()
|
||||
|
||||
it "should get the project from web", ->
|
||||
MockWebClient.joinProject
|
||||
.calledWith(@project_id, @user_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return the project", ->
|
||||
@project.should.deep.equal {
|
||||
name: "Test Project"
|
||||
}
|
||||
|
||||
it "should return the privilege level", ->
|
||||
@privilegeLevel.should.equal "owner"
|
||||
|
||||
it "should return the protocolVersion", ->
|
||||
@protocolVersion.should.equal 2
|
||||
@client = RealTimeClient.connect()
|
||||
@client.emit "joinProject", {
|
||||
project_id: @project_id
|
||||
}, (error, @project, @privilegeLevel, @protocolVersion) =>
|
||||
throw error if error?
|
||||
done()
|
||||
|
||||
it "should get the project from web", ->
|
||||
MockWebClient.joinProject
|
||||
.calledWith(@project_id, @user_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return the project", ->
|
||||
@project.should.deep.equal {
|
||||
name: "Test Project"
|
||||
}
|
||||
|
||||
it "should return the privilege level", ->
|
||||
@privilegeLevel.should.equal "owner"
|
||||
|
||||
it "should return the protocolVersion", ->
|
||||
@protocolVersion.should.equal 2
|
||||
|
||||
describe "when not authorized", ->
|
||||
before (done) ->
|
||||
@user_id = "mock-user-id-2"
|
||||
@project_id = "mock-project-id-2"
|
||||
privileges = {}
|
||||
MockWebClient.createMockProject(@project_id, privileges, {
|
||||
name: "Test Project"
|
||||
})
|
||||
MockWebClient.run (error) =>
|
||||
throw error if error?
|
||||
RealTimeClient.setSession {
|
||||
user: { _id: @user_id }
|
||||
}, (error) =>
|
||||
throw error if error?
|
||||
@client = RealTimeClient.connect()
|
||||
@client.emit "joinProject", {
|
||||
project_id: @project_id
|
||||
}, (@error, @project, @privilegeLevel, @protocolVersion) =>
|
||||
done()
|
||||
|
||||
it "should return an error", ->
|
||||
@error.message.should.equal "not authorized"
|
||||
|
|
|
@ -85,5 +85,5 @@ describe 'WebsocketController', ->
|
|||
|
||||
it "should return an error", ->
|
||||
@callback
|
||||
.calledWith(new Error("not authorized"))
|
||||
.calledWith({message: "not authorized"})
|
||||
.should.equal true
|
Loading…
Reference in a new issue