|
1 |
| -const { handleMessage, validGitRequest } = require('../src/proxy/routes'); |
| 1 | +const { handleMessage, validGitRequest, stripGitHubFromGitPath } = require('../src/proxy/routes'); |
2 | 2 | const chai = require('chai');
|
3 | 3 |
|
4 | 4 | const expect = chai.expect;
|
@@ -74,4 +74,41 @@ describe('proxy route helpers', () => {
|
74 | 74 | expect(res).to.be.false;
|
75 | 75 | });
|
76 | 76 | });
|
| 77 | + |
| 78 | + describe('stripGitHubFromGitPath', () => { |
| 79 | + it('should strip owner and repo from a valid GitHub-style path with 4 parts', () => { |
| 80 | + const res = stripGitHubFromGitPath('/foo/bar.git/info/refs'); |
| 81 | + expect(res).to.equal('/info/refs'); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should strip owner and repo from a valid GitHub-style path with 5 parts', () => { |
| 85 | + const res = stripGitHubFromGitPath('/foo/bar.git/git-upload-pack'); |
| 86 | + expect(res).to.equal('/git-upload-pack'); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should return undefined for malformed path with too few segments', () => { |
| 90 | + const res = stripGitHubFromGitPath('/foo/bar.git'); |
| 91 | + expect(res).to.be.undefined; |
| 92 | + }); |
| 93 | + |
| 94 | + it('should return undefined for malformed path with too many segments', () => { |
| 95 | + const res = stripGitHubFromGitPath('/foo/bar.git/extra/path/stuff'); |
| 96 | + expect(res).to.be.undefined; |
| 97 | + }); |
| 98 | + |
| 99 | + it('should handle repo names that include dots correctly', () => { |
| 100 | + const res = stripGitHubFromGitPath('/foo/some.repo.git/info/refs'); |
| 101 | + expect(res).to.equal('/info/refs'); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should not break if the path is just a slash', () => { |
| 105 | + const res = stripGitHubFromGitPath('/'); |
| 106 | + expect(res).to.be.undefined; |
| 107 | + }); |
| 108 | + |
| 109 | + it('should not break if the path is empty', () => { |
| 110 | + const res = stripGitHubFromGitPath(''); |
| 111 | + expect(res).to.be.undefined; |
| 112 | + }); |
| 113 | + }); |
77 | 114 | });
|
0 commit comments