11import { promiseError } from '@kwsites/promise-result' ;
2- import {
3- assertExecutedCommands ,
4- assertGitError ,
5- closeWithSuccess ,
6- newSimpleGit ,
7- } from '../__fixtures__' ;
2+ import { assertExecutedCommands , assertGitError , closeWithSuccess , newSimpleGit } from '../__fixtures__' ;
83
94describe ( 'blockUnsafeOperationsPlugin' , ( ) => {
105 it . each ( [
@@ -13,12 +8,12 @@ describe('blockUnsafeOperationsPlugin', () => {
138 [ 'Protocol.Allow=always' ] ,
149 [ 'PROTOCOL.allow=always' ] ,
1510 [ 'protocol.ALLOW=always' ] ,
16- ] ) ( 'blocks protocol overide in format %s' , async ( cmd ) => {
11+ ] ) ( 'blocks protocol override in format %s' , async ( cmd ) => {
1712 const task = [ 'config' , '-c' , cmd , 'config' , '--list' ] ;
1813
1914 assertGitError (
2015 await promiseError ( newSimpleGit ( ) . raw ( ...task ) ) ,
21- 'allowUnsafeExtProtocol'
16+ 'allowUnsafeProtocolOverride' ,
2217 ) ;
2318
2419 const err = promiseError (
@@ -38,18 +33,44 @@ describe('blockUnsafeOperationsPlugin', () => {
3833 ] ) ( 'allows %s %s only when using override' , async ( cmd , option ) => {
3934 assertGitError (
4035 await promiseError ( newSimpleGit ( { unsafe : { } } ) . raw ( cmd , option ) ) ,
41- 'allowUnsafePack'
36+ 'allowUnsafePack' ,
4237 ) ;
4338
4439 const err = promiseError (
45- newSimpleGit ( { unsafe : { allowUnsafePack : true } } ) . raw ( cmd , option )
40+ newSimpleGit ( { unsafe : { allowUnsafePack : true } } ) . raw ( cmd , option ) ,
4641 ) ;
4742
4843 await closeWithSuccess ( ) ;
4944 expect ( await err ) . toBeUndefined ( ) ;
5045 assertExecutedCommands ( cmd , option ) ;
5146 } ) ;
5247
48+ describe . each ( [
49+ [ 'allowUnsafeSshCommand' , `core.sshCommand=sh -c 'id > pwned'` ] ,
50+ [ 'allowUnsafeGitProxy' , `core.gitProxy=sh -c 'id > pwned'` ] ,
51+ [ 'allowUnsafeHooksPath' , `core.hooksPath=sh -c 'id > pwned'` ] ,
52+ [ 'allowUnsafeDiffExternal' , `diff.external=sh -c 'id > pwned'` ] ,
53+ ] ) ( 'unsafe config option - %s' , ( setting , command ) => {
54+
55+ it ( 'blocks by default' , async ( ) => {
56+ const err = promiseError (
57+ newSimpleGit ( ) . clone ( 'remote' , 'local' , [ '-c' , command ] ) ,
58+ ) ;
59+ await promiseError ( closeWithSuccess ( ) ) ;
60+
61+ assertGitError ( await err , setting ) ;
62+ } ) ;
63+
64+ it ( 'allows with override' , async ( ) => {
65+ const err = promiseError (
66+ newSimpleGit ( { unsafe : { [ setting ] : true } } ) . clone ( 'remote' , 'local' , [ '-c' , command ] ) ,
67+ ) ;
68+ await closeWithSuccess ( ) ;
69+
70+ expect ( await err ) . toBeUndefined ( ) ;
71+ } ) ;
72+ } ) ;
73+
5374 it ( 'allows -u for non-clone commands' , async ( ) => {
5475 const git = newSimpleGit ( { unsafe : { } } ) ;
5576 const err = promiseError ( git . raw ( 'push' , '-u' , 'origin/main' ) ) ;
0 commit comments