forked from finos/git-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: filter non-git HTTP requests being proxied Fixes finos#410 * feat: refactor to one validation function - Accept is only set for certain git actions so refactored into one validation function - pass routes correctly to express (fix TypeError on startup) * feat: separate url stripping into its own function - separate out the HTTP git filtering logic from the URL parsing, which includes stripping the GitHub repo owner/name.
- Loading branch information
1 parent
834bd9e
commit 46002d6
Showing
3 changed files
with
150 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* eslint-disable max-len */ | ||
const chai = require('chai'); | ||
const validGitRequest = require('../src/proxy/routes').validGitRequest; | ||
const stripGitHubFromGitPath = | ||
require('../src/proxy/routes').stripGitHubFromGitPath; | ||
|
||
chai.should(); | ||
|
||
const expect = chai.expect; | ||
|
||
describe('url filters for proxying ', function () { | ||
it('stripGitHubFromGitPath should return the sanitized URL with owner & repo removed', function () { | ||
expect( | ||
stripGitHubFromGitPath( | ||
'/octocat/hello-world.git/info/refs?service=git-upload-pack', | ||
), | ||
).eq('/info/refs?service=git-upload-pack'); | ||
}); | ||
|
||
it('stripGitHubFromGitPath should return undefined if the url', function () { | ||
expect(stripGitHubFromGitPath('/octocat/hello-world')).undefined; | ||
}); | ||
|
||
it('validGitRequest should return true for safe requests on expected URLs', function () { | ||
[ | ||
'/info/refs?service=git-upload-pack', | ||
'/info/refs?service=git-receive-pack', | ||
'/git-upload-pack', | ||
'/git-receive-pack', | ||
].forEach((url) => { | ||
expect( | ||
validGitRequest(url, { | ||
'user-agent': 'git/2.30.0', | ||
accept: 'application/x-git-upload-pack-request', | ||
}), | ||
).true; | ||
}); | ||
}); | ||
|
||
it('validGitRequest should return false for unsafe URLs', function () { | ||
['/', '/foo'].forEach((url) => { | ||
expect( | ||
validGitRequest(url, { | ||
'user-agent': 'git/2.30.0', | ||
accept: 'application/x-git-upload-pack-request', | ||
}), | ||
).false; | ||
}); | ||
}); | ||
|
||
it('validGitRequest should return false for a browser request', function () { | ||
expect( | ||
validGitRequest('/', { | ||
'user-agent': 'Mozilla/5.0', | ||
accept: '*/*', | ||
}), | ||
).false; | ||
}); | ||
|
||
it('validGitRequest should return false for unexpected combinations of headers & URLs', function () { | ||
// expected Accept=application/x-git-upload-pack | ||
expect( | ||
validGitRequest('/git-upload-pack', { | ||
'user-agent': 'git/2.30.0', | ||
accept: '*/*', | ||
}), | ||
).false; | ||
|
||
// expected User-Agent=git/* | ||
expect( | ||
validGitRequest('/info/refs?service=git-upload-pack', { | ||
'user-agent': 'Mozilla/5.0', | ||
accept: '*/*', | ||
}), | ||
).false; | ||
}); | ||
|
||
it('validGitRequest should return false for unexpected content-type on certain URLs', function () { | ||
['application/json', 'text/html', '*/*'].map((accept) => { | ||
expect( | ||
validGitRequest('/git-upload-pack', { | ||
'user-agent': 'git/2.30.0', | ||
accept: accept, | ||
}), | ||
).false; | ||
}); | ||
}); | ||
}); |