|
1 | | -/*global describe, it, beforeEach */ |
| 1 | +/*global describe, it, beforeEach, afterEach */ |
2 | 2 |
|
3 | 3 | var BpmAuth = require('../src/bpmAuth'); |
4 | 4 | var AuthBpmMock = require('../test/mockObjects/mockAlfrescoApi').ActivitiMock.Auth; |
5 | 5 | var expect = require('chai').expect; |
| 6 | +var sinon = require('sinon'); |
6 | 7 |
|
7 | 8 | describe('Bpm Auth test', function () { |
8 | 9 |
|
@@ -159,5 +160,43 @@ describe('Bpm Auth test', function () { |
159 | 160 | }); |
160 | 161 |
|
161 | 162 | }); |
| 163 | + |
| 164 | + describe('CSRF Token', function () { |
| 165 | + |
| 166 | + beforeEach(function() { |
| 167 | + this.setCsrfTokenStub = sinon.stub(BpmAuth.prototype, 'setCsrfToken'); |
| 168 | + }); |
| 169 | + |
| 170 | + afterEach(function() { |
| 171 | + this.setCsrfTokenStub.restore(); |
| 172 | + }); |
| 173 | + |
| 174 | + it('should be enabled by default', function (done) { |
| 175 | + this.authBpmMock.get200Response(); |
| 176 | + |
| 177 | + this.bpmAuth = new BpmAuth({ |
| 178 | + hostBpm: this.hostBpm |
| 179 | + }); |
| 180 | + |
| 181 | + this.bpmAuth.login('admin', 'admin').then(() => { |
| 182 | + expect(this.setCsrfTokenStub.called).to.be.equal(true); |
| 183 | + done(); |
| 184 | + }); |
| 185 | + }); |
| 186 | + |
| 187 | + it('should be disabled if disableCsrf is true', function (done) { |
| 188 | + this.authBpmMock.get200Response(); |
| 189 | + |
| 190 | + this.bpmAuth = new BpmAuth({ |
| 191 | + hostBpm: this.hostBpm, |
| 192 | + disableCsrf: true |
| 193 | + }); |
| 194 | + |
| 195 | + this.bpmAuth.login('admin', 'admin').then(() => { |
| 196 | + expect(this.setCsrfTokenStub.called).to.be.equal(false); |
| 197 | + done(); |
| 198 | + }); |
| 199 | + }); |
| 200 | + }); |
162 | 201 | }); |
163 | 202 | }); |
0 commit comments