diff --git a/.eslintrc.json b/.eslintrc.json index dc9bc7f..9a221c3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -81,7 +81,8 @@ { "accessibility": "explicit" } - ] + ], + "@typescript-eslint/no-floating-promises": "error" }, "ignorePatterns": [ "jest.config.js", @@ -106,4 +107,4 @@ } } ] -} \ No newline at end of file +} diff --git a/test/CsrfProtectionComponent.test.ts b/test/CsrfProtectionComponent.test.ts index 1d30a0d..33999f2 100644 --- a/test/CsrfProtectionComponent.test.ts +++ b/test/CsrfProtectionComponent.test.ts @@ -39,21 +39,19 @@ describe('Test CSRF protection', () => { test('no csrf token should be in session at first', (done) => { const agent = supertest(app.getExpressApp()); agent.post('/') - .expect(401, (err, res) => { - if (err) return done(err); - + .expect(401) + .then(res => { expect(res.text).toContain(`You weren't assigned any CSRF token.`); cookies = res.get('Set-Cookie'); agent.get('/') .set('Cookie', cookies) - .expect(200, (err, res) => { - if (err) return done(err); - + .expect(200) + .then(res => { csrf = res.text; done(); - }); - }); + }).catch(done.fail); + }).catch(done.fail); }); test('sending no csrf token should fail', (done) => { @@ -63,12 +61,10 @@ describe('Test CSRF protection', () => { agent.post('/') .set('Cookie', cookies) .expect(401) - .end((err, res) => { - if (err) return done(err); - + .then((res) => { expect(res.text).toContain(`You didn't provide any CSRF token.`); done(); - }); + }).catch(done.fail); }); test('sending an invalid csrf token should fail', (done) => { @@ -79,12 +75,11 @@ describe('Test CSRF protection', () => { .set('Cookie', cookies) .set('Content-Type', 'application/json') .send({csrf: 'not_a_valid_csrf'}) - .expect(401, (err, res) => { - if (err) return done(err); - + .expect(401) + .then(res => { expect(res.text).toContain(`Tokens don't match.`); done(); - }); + }).catch(done.fail); }); test('sending a valid csrf token should success', (done) => { @@ -95,6 +90,8 @@ describe('Test CSRF protection', () => { .set('Cookie', cookies) .set('Content-Type', 'application/json') .send({csrf: csrf}) - .expect(200, done); + .expect(200) + .then(() => done()) + .catch(done.fail); }); });