Skip to content

Commit 11ec0ca

Browse files
authored
Merge pull request #1095 from andypols/fix-dos-when-pushing-unkown-repo
fix: prevent DOS when checking an unknown repo
2 parents b6dd0f1 + 6c521a5 commit 11ec0ca

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/db/db.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const chai = require('chai');
2+
const sinon = require('sinon');
3+
const db = require('../../src/db');
4+
5+
const { expect } = chai;
6+
7+
describe('db', () => {
8+
afterEach(() => {
9+
sinon.restore();
10+
});
11+
12+
describe('isUserPushAllowed', () => {
13+
it('returns true if user is in canPush', async () => {
14+
sinon.stub(db, 'getRepoByUrl').resolves({
15+
users: {
16+
canPush: ['alice'],
17+
canAuthorise: [],
18+
},
19+
});
20+
const result = await db.isUserPushAllowed('myrepo', 'alice');
21+
expect(result).to.be.true;
22+
});
23+
24+
it('returns true if user is in canAuthorise', async () => {
25+
sinon.stub(db, 'getRepoByUrl').resolves({
26+
users: {
27+
canPush: [],
28+
canAuthorise: ['bob'],
29+
},
30+
});
31+
const result = await db.isUserPushAllowed('myrepo', 'bob');
32+
expect(result).to.be.true;
33+
});
34+
35+
it('returns false if user is in neither', async () => {
36+
sinon.stub(db, 'getRepoByUrl').resolves({
37+
users: {
38+
canPush: [],
39+
canAuthorise: [],
40+
},
41+
});
42+
const result = await db.isUserPushAllowed('myrepo', 'charlie');
43+
expect(result).to.be.false;
44+
});
45+
46+
it('returns false if repo is not registered', async () => {
47+
sinon.stub(db, 'getRepoByUrl').resolves(null);
48+
const result = await db.isUserPushAllowed('myrepo', 'charlie');
49+
expect(result).to.be.false;
50+
});
51+
});
52+
});

0 commit comments

Comments
 (0)