|
| 1 | +const { handleMessage, validGitRequest } = require('../src/proxy/routes'); |
| 2 | +const chai = require('chai'); |
| 3 | + |
| 4 | +const expect = chai.expect; |
| 5 | + |
| 6 | +describe('proxy route helpers', () => { |
| 7 | + describe('handleMessage', async () => { |
| 8 | + it('should handle short messages', async function () { |
| 9 | + const res = await handleMessage('one'); |
| 10 | + expect(res).to.contain('one'); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should handle emoji messages', async function () { |
| 14 | + const res = await handleMessage('❌ push failed: too many errors'); |
| 15 | + expect(res).to.contain('❌'); |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + describe('validGitRequest', () => { |
| 20 | + it('should return true for /info/refs?service=git-upload-pack with valid user-agent', () => { |
| 21 | + const res = validGitRequest('/info/refs?service=git-upload-pack', { |
| 22 | + 'user-agent': 'git/2.30.1', |
| 23 | + }); |
| 24 | + expect(res).to.be.true; |
| 25 | + }); |
| 26 | + |
| 27 | + it('should return true for /info/refs?service=git-receive-pack with valid user-agent', () => { |
| 28 | + const res = validGitRequest('/info/refs?service=git-receive-pack', { |
| 29 | + 'user-agent': 'git/1.9.1', |
| 30 | + }); |
| 31 | + expect(res).to.be.true; |
| 32 | + }); |
| 33 | + |
| 34 | + it('should return false for /info/refs?service=git-upload-pack with missing user-agent', () => { |
| 35 | + const res = validGitRequest('/info/refs?service=git-upload-pack', {}); |
| 36 | + expect(res).to.be.false; |
| 37 | + }); |
| 38 | + |
| 39 | + it('should return false for /info/refs?service=git-upload-pack with non-git user-agent', () => { |
| 40 | + const res = validGitRequest('/info/refs?service=git-upload-pack', { |
| 41 | + 'user-agent': 'curl/7.79.1', |
| 42 | + }); |
| 43 | + expect(res).to.be.false; |
| 44 | + }); |
| 45 | + |
| 46 | + it('should return true for /git-upload-pack with valid user-agent and accept', () => { |
| 47 | + const res = validGitRequest('/git-upload-pack', { |
| 48 | + 'user-agent': 'git/2.40.0', |
| 49 | + accept: 'application/x-git-upload-pack-request', |
| 50 | + }); |
| 51 | + expect(res).to.be.true; |
| 52 | + }); |
| 53 | + |
| 54 | + it('should return false for /git-upload-pack with missing accept header', () => { |
| 55 | + const res = validGitRequest('/git-upload-pack', { |
| 56 | + 'user-agent': 'git/2.40.0', |
| 57 | + }); |
| 58 | + expect(res).to.be.false; |
| 59 | + }); |
| 60 | + |
| 61 | + it('should return false for /git-upload-pack with wrong accept header', () => { |
| 62 | + const res = validGitRequest('/git-upload-pack', { |
| 63 | + 'user-agent': 'git/2.40.0', |
| 64 | + accept: 'application/json', |
| 65 | + }); |
| 66 | + expect(res).to.be.false; |
| 67 | + }); |
| 68 | + |
| 69 | + it('should return false for unknown paths', () => { |
| 70 | + const res = validGitRequest('/not-a-valid-git-path', { |
| 71 | + 'user-agent': 'git/2.40.0', |
| 72 | + accept: 'application/x-git-upload-pack-request', |
| 73 | + }); |
| 74 | + expect(res).to.be.false; |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments