[misc] test/unit: fix typos and assertion of error messages

Sinon does not check the contents of the passed error when checked via
 sinon.stub().calledWith.
```
callback = sinon.stub()
callback(new Error("some message"))
  .calledWith(new Error("completely different message"))
  === true
```

Cherry-pick plus an additional patch for the joinProject bail-out.
(cherry picked from commit d9570fee70701a5f431c39fdbec5f8bc5a7843fe)
This commit is contained in:
Jakob Ackermann 2020-05-01 12:43:18 +02:00
parent 17d04b9041
commit 1095851dfe
3 changed files with 28 additions and 44 deletions

View file

@ -27,19 +27,19 @@ describe 'AuthorizationManager', ->
@AuthorizationManager.assertClientCanViewProject @client, (error) ->
expect(error).to.be.null
done()
it "should allow the readAndWrite privilegeLevel", (done) ->
@client.params.privilege_level = "readAndWrite"
@AuthorizationManager.assertClientCanViewProject @client, (error) ->
expect(error).to.be.null
done()
it "should allow the owner privilegeLevel", (done) ->
@client.params.privilege_level = "owner"
@AuthorizationManager.assertClientCanViewProject @client, (error) ->
expect(error).to.be.null
done()
it "should return an error with any other privilegeLevel", (done) ->
@client.params.privilege_level = "unknown"
@AuthorizationManager.assertClientCanViewProject @client, (error) ->
@ -52,19 +52,19 @@ describe 'AuthorizationManager', ->
@AuthorizationManager.assertClientCanEditProject @client, (error) ->
error.message.should.equal "not authorized"
done()
it "should allow the readAndWrite privilegeLevel", (done) ->
@client.params.privilege_level = "readAndWrite"
@AuthorizationManager.assertClientCanEditProject @client, (error) ->
expect(error).to.be.null
done()
it "should allow the owner privilegeLevel", (done) ->
@client.params.privilege_level = "owner"
@AuthorizationManager.assertClientCanEditProject @client, (error) ->
expect(error).to.be.null
done()
it "should return an error with any other privilegeLevel", (done) ->
@client.params.privilege_level = "unknown"
@AuthorizationManager.assertClientCanEditProject @client, (error) ->
@ -84,20 +84,16 @@ describe 'AuthorizationManager', ->
@client.params.privilege_level = "unknown"
it "should not allow access", () ->
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback
@callback
.calledWith(new Error("not authorised"))
.should.equal true
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, (err) ->
err.message.should.equal "not authorized"
describe "even when authorised at the doc level", ->
beforeEach (done) ->
@AuthorizationManager.addAccessToDoc @client, @doc_id, done
it "should not allow access", () ->
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback
@callback
.calledWith(new Error("not authorised"))
.should.equal true
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, (err) ->
err.message.should.equal "not authorized"
describe "when authorised at the project level", ->
beforeEach () ->
@ -105,10 +101,8 @@ describe 'AuthorizationManager', ->
describe "and not authorised at the document level", ->
it "should not allow access", () ->
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback
@callback
.calledWith(new Error("not authorised"))
.should.equal true
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, (err) ->
err.message.should.equal "not authorized"
describe "and authorised at the document level", ->
beforeEach (done) ->
@ -126,10 +120,8 @@ describe 'AuthorizationManager', ->
@AuthorizationManager.removeAccessToDoc @client, @doc_id, done
it "should deny access", () ->
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback
@callback
.calledWith(new Error("not authorised"))
.should.equal true
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, (err) ->
err.message.should.equal "not authorized"
describe "assertClientCanEditProjectAndDoc", ->
beforeEach () ->
@ -142,20 +134,16 @@ describe 'AuthorizationManager', ->
@client.params.privilege_level = "readOnly"
it "should not allow access", () ->
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback
@callback
.calledWith(new Error("not authorised"))
.should.equal true
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, (err) ->
err.message.should.equal "not authorized"
describe "even when authorised at the doc level", ->
beforeEach (done) ->
@AuthorizationManager.addAccessToDoc @client, @doc_id, done
it "should not allow access", () ->
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback
@callback
.calledWith(new Error("not authorised"))
.should.equal true
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, (err) ->
err.message.should.equal "not authorized"
describe "when authorised at the project level", ->
beforeEach () ->
@ -163,10 +151,8 @@ describe 'AuthorizationManager', ->
describe "and not authorised at the document level", ->
it "should not allow access", () ->
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback
@callback
.calledWith(new Error("not authorised"))
.should.equal true
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, (err) ->
err.message.should.equal "not authorized"
describe "and authorised at the document level", ->
beforeEach (done) ->
@ -184,7 +170,5 @@ describe 'AuthorizationManager', ->
@AuthorizationManager.removeAccessToDoc @client, @doc_id, done
it "should deny access", () ->
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback
@callback
.calledWith(new Error("not authorised"))
.should.equal true
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, (err) ->
err.message.should.equal "not authorized"

View file

@ -60,7 +60,7 @@ describe 'WebApiManager', ->
it "should call the callback with an error", ->
@callback
.calledWith(new Error("non-success code from web: 500"))
.calledWith(sinon.match({message: "non-success status code from web: 500"}))
.should.equal true
describe "with no data from web", ->
@ -70,7 +70,7 @@ describe 'WebApiManager', ->
it "should call the callback with an error", ->
@callback
.calledWith(new Error("no data returned from joinProject request"))
.calledWith(sinon.match({message: "no data returned from joinProject request"}))
.should.equal true
describe "when the project is over its rate limit", ->
@ -80,5 +80,5 @@ describe 'WebApiManager', ->
it "should call the callback with a TooManyRequests error code", ->
@callback
.calledWith(new CodedError("rate-limit hit when joining project", "TooManyRequests"))
.calledWith(sinon.match({message: "rate-limit hit when joining project", code: "TooManyRequests"}))
.should.equal true

View file

@ -119,7 +119,7 @@ describe 'WebsocketController', ->
it "should return an error", ->
@callback
.calledWith(new Error("not authorized"))
.calledWith(sinon.match({message: "not authorized"}))
.should.equal true
it "should not log an error", ->
@ -143,7 +143,7 @@ describe 'WebsocketController', ->
it "should return an error", ->
@callback
.calledWith(new Error("subscribe failed"))
.calledWith(sinon.match({message: "subscribe failed"}))
.should.equal true
@callback.args[0][0].message.should.equal "subscribe failed"
@ -369,7 +369,7 @@ describe 'WebsocketController', ->
@WebsocketController.joinDoc @client, @doc_id, -1, @options, @callback
it "should call the callback with an error", ->
@callback.calledWith(@err).should.equal true
@callback.calledWith(sinon.match({message: "not authorized"})).should.equal true
it "should not call the DocumentUpdaterManager", ->
@DocumentUpdaterManager.getDocument.called.should.equal false