[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

@ -84,20 +84,16 @@ describe 'AuthorizationManager', ->
@client.params.privilege_level = "unknown" @client.params.privilege_level = "unknown"
it "should not allow access", () -> it "should not allow access", () ->
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback @AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, (err) ->
@callback err.message.should.equal "not authorized"
.calledWith(new Error("not authorised"))
.should.equal true
describe "even when authorised at the doc level", -> describe "even when authorised at the doc level", ->
beforeEach (done) -> beforeEach (done) ->
@AuthorizationManager.addAccessToDoc @client, @doc_id, done @AuthorizationManager.addAccessToDoc @client, @doc_id, done
it "should not allow access", () -> it "should not allow access", () ->
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback @AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, (err) ->
@callback err.message.should.equal "not authorized"
.calledWith(new Error("not authorised"))
.should.equal true
describe "when authorised at the project level", -> describe "when authorised at the project level", ->
beforeEach () -> beforeEach () ->
@ -105,10 +101,8 @@ describe 'AuthorizationManager', ->
describe "and not authorised at the document level", -> describe "and not authorised at the document level", ->
it "should not allow access", () -> it "should not allow access", () ->
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback @AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, (err) ->
@callback err.message.should.equal "not authorized"
.calledWith(new Error("not authorised"))
.should.equal true
describe "and authorised at the document level", -> describe "and authorised at the document level", ->
beforeEach (done) -> beforeEach (done) ->
@ -126,10 +120,8 @@ describe 'AuthorizationManager', ->
@AuthorizationManager.removeAccessToDoc @client, @doc_id, done @AuthorizationManager.removeAccessToDoc @client, @doc_id, done
it "should deny access", () -> it "should deny access", () ->
@AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, @callback @AuthorizationManager.assertClientCanViewProjectAndDoc @client, @doc_id, (err) ->
@callback err.message.should.equal "not authorized"
.calledWith(new Error("not authorised"))
.should.equal true
describe "assertClientCanEditProjectAndDoc", -> describe "assertClientCanEditProjectAndDoc", ->
beforeEach () -> beforeEach () ->
@ -142,20 +134,16 @@ describe 'AuthorizationManager', ->
@client.params.privilege_level = "readOnly" @client.params.privilege_level = "readOnly"
it "should not allow access", () -> it "should not allow access", () ->
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback @AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, (err) ->
@callback err.message.should.equal "not authorized"
.calledWith(new Error("not authorised"))
.should.equal true
describe "even when authorised at the doc level", -> describe "even when authorised at the doc level", ->
beforeEach (done) -> beforeEach (done) ->
@AuthorizationManager.addAccessToDoc @client, @doc_id, done @AuthorizationManager.addAccessToDoc @client, @doc_id, done
it "should not allow access", () -> it "should not allow access", () ->
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback @AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, (err) ->
@callback err.message.should.equal "not authorized"
.calledWith(new Error("not authorised"))
.should.equal true
describe "when authorised at the project level", -> describe "when authorised at the project level", ->
beforeEach () -> beforeEach () ->
@ -163,10 +151,8 @@ describe 'AuthorizationManager', ->
describe "and not authorised at the document level", -> describe "and not authorised at the document level", ->
it "should not allow access", () -> it "should not allow access", () ->
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback @AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, (err) ->
@callback err.message.should.equal "not authorized"
.calledWith(new Error("not authorised"))
.should.equal true
describe "and authorised at the document level", -> describe "and authorised at the document level", ->
beforeEach (done) -> beforeEach (done) ->
@ -184,7 +170,5 @@ describe 'AuthorizationManager', ->
@AuthorizationManager.removeAccessToDoc @client, @doc_id, done @AuthorizationManager.removeAccessToDoc @client, @doc_id, done
it "should deny access", () -> it "should deny access", () ->
@AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, @callback @AuthorizationManager.assertClientCanEditProjectAndDoc @client, @doc_id, (err) ->
@callback err.message.should.equal "not authorized"
.calledWith(new Error("not authorised"))
.should.equal true

View file

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

View file

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