Skip to content

Commit 37d9464

Browse files
committed
fix: fix blocked request test
1 parent 735c634 commit 37d9464

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/proxy/routes/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,20 @@ const teeAndValidate = async (req: Request, res: Response, next: NextFunction) =
7474
(req as any).body = buf;
7575
const verdict = await executeChain(req, res);
7676
console.log('action processed');
77-
7877
if (verdict.error || verdict.blocked) {
79-
const msg = verdict.error ? verdict.errorMessage! : verdict.blockedMessage!;
78+
let msg = '';
79+
80+
if (verdict.error) {
81+
msg = verdict.errorMessage!;
82+
console.error(msg);
83+
}
84+
if (verdict.blocked) {
85+
msg = verdict.blockedMessage!;
86+
}
87+
8088
res
8189
.set({
8290
'content-type': 'application/x-git-receive-pack-result',
83-
'transfer-encoding': 'chunked',
8491
expires: 'Fri, 01 Jan 1980 00:00:00 GMT',
8592
pragma: 'no-cache',
8693
'cache-control': 'no-cache, max-age=0, must-revalidate',

test/testProxyRoute.test.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ describe('proxy route filter middleware', () => {
4242

4343
const res = await chai
4444
.request(app)
45-
.get('/owner/repo.git/info/refs?service=git-upload-pack')
45+
.post('/owner/repo.git/git-upload-pack')
4646
.set('user-agent', 'git/2.42.0')
4747
.set('accept', 'application/x-git-upload-pack-request')
48+
.send(Buffer.from('0000'))
4849
.buffer();
4950

5051
expect(res.status).to.equal(200);
@@ -112,49 +113,49 @@ describe('proxy route helpers', () => {
112113
});
113114
expect(res).to.be.true;
114115
});
115-
116+
116117
it('should return true for /info/refs?service=git-receive-pack with valid user-agent', () => {
117118
const res = validGitRequest('/info/refs?service=git-receive-pack', {
118119
'user-agent': 'git/1.9.1',
119120
});
120121
expect(res).to.be.true;
121122
});
122-
123+
123124
it('should return false for /info/refs?service=git-upload-pack with missing user-agent', () => {
124125
const res = validGitRequest('/info/refs?service=git-upload-pack', {});
125126
expect(res).to.be.false;
126127
});
127-
128+
128129
it('should return false for /info/refs?service=git-upload-pack with non-git user-agent', () => {
129130
const res = validGitRequest('/info/refs?service=git-upload-pack', {
130131
'user-agent': 'curl/7.79.1',
131132
});
132133
expect(res).to.be.false;
133134
});
134-
135+
135136
it('should return true for /git-upload-pack with valid user-agent and accept', () => {
136137
const res = validGitRequest('/git-upload-pack', {
137138
'user-agent': 'git/2.40.0',
138139
accept: 'application/x-git-upload-pack-request',
139140
});
140141
expect(res).to.be.true;
141142
});
142-
143+
143144
it('should return false for /git-upload-pack with missing accept header', () => {
144145
const res = validGitRequest('/git-upload-pack', {
145146
'user-agent': 'git/2.40.0',
146147
});
147148
expect(res).to.be.false;
148149
});
149-
150+
150151
it('should return false for /git-upload-pack with wrong accept header', () => {
151152
const res = validGitRequest('/git-upload-pack', {
152153
'user-agent': 'git/2.40.0',
153154
accept: 'application/json',
154155
});
155156
expect(res).to.be.false;
156157
});
157-
158+
158159
it('should return false for unknown paths', () => {
159160
const res = validGitRequest('/not-a-valid-git-path', {
160161
'user-agent': 'git/2.40.0',
@@ -169,32 +170,32 @@ describe('proxy route helpers', () => {
169170
const res = stripGitHubFromGitPath('/foo/bar.git/info/refs');
170171
expect(res).to.equal('/info/refs');
171172
});
172-
173+
173174
it('should strip owner and repo from a valid GitHub-style path with 5 parts', () => {
174175
const res = stripGitHubFromGitPath('/foo/bar.git/git-upload-pack');
175176
expect(res).to.equal('/git-upload-pack');
176177
});
177-
178+
178179
it('should return undefined for malformed path with too few segments', () => {
179180
const res = stripGitHubFromGitPath('/foo/bar.git');
180181
expect(res).to.be.undefined;
181182
});
182-
183+
183184
it('should return undefined for malformed path with too many segments', () => {
184185
const res = stripGitHubFromGitPath('/foo/bar.git/extra/path/stuff');
185186
expect(res).to.be.undefined;
186187
});
187-
188+
188189
it('should handle repo names that include dots correctly', () => {
189190
const res = stripGitHubFromGitPath('/foo/some.repo.git/info/refs');
190191
expect(res).to.equal('/info/refs');
191192
});
192-
193+
193194
it('should not break if the path is just a slash', () => {
194195
const res = stripGitHubFromGitPath('/');
195196
expect(res).to.be.undefined;
196197
});
197-
198+
198199
it('should not break if the path is empty', () => {
199200
const res = stripGitHubFromGitPath('');
200201
expect(res).to.be.undefined;

0 commit comments

Comments
 (0)