Skip to content

Commit 79c1ec9

Browse files
committed
test: add valid request tests (valid/invalid repo)
1 parent 783256d commit 79c1ec9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/testProxyRoute.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,43 @@ describe('proxy route filter middleware', () => {
5252
expect(res.headers['content-type']).to.include('application/x-git-receive-pack-result');
5353
expect(res.headers['x-frame-options']).to.equal('DENY');
5454
});
55+
56+
describe('when request is valid and not blocked', () => {
57+
it('should return error if repo is not found', async () => {
58+
sinon.stub(chain, 'executeChain').resolves({
59+
blocked: false,
60+
blockedMessage: '',
61+
error: false,
62+
});
63+
64+
const res = await chai
65+
.request(app)
66+
.get('/owner/repo.git/info/refs?service=git-upload-pack')
67+
.set('user-agent', 'git/2.42.0')
68+
.set('accept', 'application/x-git-upload-pack-request')
69+
.buffer();
70+
71+
expect(res.status).to.equal(401);
72+
expect(res.text).to.equal('Repository not found.');
73+
});
74+
75+
it('should pass through if repo is found', async () => {
76+
sinon.stub(chain, 'executeChain').resolves({
77+
blocked: false,
78+
blockedMessage: '',
79+
error: false,
80+
});
81+
82+
const res = await chai
83+
.request(app)
84+
.get('/finos/git-proxy.git/info/refs?service=git-upload-pack')
85+
.set('user-agent', 'git/2.42.0')
86+
.set('accept', 'application/x-git-upload-pack-request')
87+
.buffer();
88+
89+
expect(res.status).to.equal(200);
90+
expect(res.text).to.contain('git-upload-pack');
91+
});
5592
});
5693
});
5794

0 commit comments

Comments
 (0)