Browse Source

eslint: add no-floating-promises

swaf-creation
Alice Gaudon 4 months ago
parent
commit
a98c06fa92
2 changed files with 17 additions and 19 deletions
  1. +3
    -2
      .eslintrc.json
  2. +14
    -17
      test/CsrfProtectionComponent.test.ts

+ 3
- 2
.eslintrc.json View File

@ -81,7 +81,8 @@
{
"accessibility": "explicit"
}
]
],
"@typescript-eslint/no-floating-promises": "error"
},
"ignorePatterns": [
"jest.config.js",
@ -106,4 +107,4 @@
}
}
]
}
}

+ 14
- 17
test/CsrfProtectionComponent.test.ts View File

@ -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);
});
});

Loading…
Cancel
Save