Skip to content

Commit 783256d

Browse files
committed
test: add rejection test cases
1 parent eb414fd commit 783256d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/testProxyRoute.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,36 @@ describe('proxy route filter middleware', () => {
2222
sinon.restore();
2323
});
2424

25+
it('should reject invalid git requests with 400', async () => {
26+
const res = await chai
27+
.request(app)
28+
.get('/owner/repo.git/invalid/path')
29+
.set('user-agent', 'git/2.42.0')
30+
.set('accept', 'application/x-git-upload-pack-request');
31+
32+
expect(res).to.have.status(400);
33+
expect(res.text).to.equal('Invalid request received');
34+
});
35+
36+
it('should handle blocked requests and return custom packet message', async () => {
37+
sinon.stub(chain, 'executeChain').resolves({
38+
blocked: true,
39+
blockedMessage: 'You shall not push!',
40+
error: false,
41+
});
42+
43+
const res = await chai
44+
.request(app)
45+
.get('/owner/repo.git/info/refs?service=git-upload-pack')
46+
.set('user-agent', 'git/2.42.0')
47+
.set('accept', 'application/x-git-upload-pack-request')
48+
.buffer();
49+
50+
expect(res.status).to.equal(200);
51+
expect(res.text).to.contain('You shall not push!');
52+
expect(res.headers['content-type']).to.include('application/x-git-receive-pack-result');
53+
expect(res.headers['x-frame-options']).to.equal('DENY');
54+
});
2555
});
2656
});
2757

0 commit comments

Comments
 (0)