|
| 1 | +import { promiseError, promiseResult } from '@kwsites/promise-result'; |
| 2 | +import { |
| 3 | + assertGitError, |
| 4 | + createTestContext, |
| 5 | + newSimpleGit, |
| 6 | + SimpleGitTestContext, |
| 7 | +} from '@simple-git/test-utils'; |
| 8 | + |
| 9 | +import { GitPluginError } from '../..'; |
| 10 | + |
| 11 | +describe('add', () => { |
| 12 | + let context: SimpleGitTestContext; |
| 13 | + |
| 14 | + beforeEach(async () => (context = await createTestContext())); |
| 15 | + |
| 16 | + it('allows overriding protocol when opting in to unsafe practices', async () => { |
| 17 | + const { threw } = await promiseResult( |
| 18 | + newSimpleGit(context.root, { unsafe: { allowUnsafeProtocolOverride: true } }).raw( |
| 19 | + '-c', |
| 20 | + 'protocol.ext.allow=always', |
| 21 | + 'init' |
| 22 | + ) |
| 23 | + ); |
| 24 | + |
| 25 | + expect(threw).toBe(false); |
| 26 | + }); |
| 27 | + |
| 28 | + it('prevents overriding protocol.ext.allow before the method of a command', async () => { |
| 29 | + assertGitError( |
| 30 | + await promiseError(context.git.raw('-c', 'protocol.ext.allow=always', 'init')), |
| 31 | + 'Configuring protocol.allow is not permitted', |
| 32 | + GitPluginError |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + it('prevents overriding protocol.ext.allow after the method of a command', async () => { |
| 37 | + assertGitError( |
| 38 | + await promiseError(context.git.raw('init', '-c', 'protocol.ext.allow=always')), |
| 39 | + 'Configuring protocol.allow is not permitted', |
| 40 | + GitPluginError |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + it('prevents adding a remote with vulnerable ext transport', async () => { |
| 45 | + assertGitError( |
| 46 | + await promiseError( |
| 47 | + context.git.clone(`ext::sh -c touch% /tmp/pwn% >&2`, '/tmp/example-new-repo', [ |
| 48 | + '-c', |
| 49 | + 'protocol.ext.allow=always', |
| 50 | + ]) |
| 51 | + ), |
| 52 | + 'Configuring protocol.allow is not permitted', |
| 53 | + GitPluginError |
| 54 | + ); |
| 55 | + }); |
| 56 | +}); |
0 commit comments