@@ -267,3 +267,23 @@ func TestExecCommand(t *testing.T) {
267267 assert .Equal (t , buf .buf .String (), "hello" + SqlcmdEol , "echo output should be in sqlcmd output" )
268268 }
269269}
270+
271+ func TestDisableSysCommandBlocksExec (t * testing.T ) {
272+ s , buf := setupSqlCmdWithMemoryOutput (t )
273+ defer buf .Close ()
274+ s .Cmd .DisableSysCommands (false )
275+ c := []string {"set nocount on" , ":!! echo hello" , "select 100" , "go" }
276+ err := runSqlCmd (t , s , c )
277+ if assert .NoError (t , err , ":!! with warning should not raise error" ) {
278+ assert .Contains (t , buf .buf .String (), ErrCommandsDisabled .Error ()+ SqlcmdEol + "100" + SqlcmdEol )
279+ assert .Equal (t , 0 , s .Exitcode , "ExitCode after warning" )
280+ }
281+ buf .buf .Reset ()
282+ s .Cmd .DisableSysCommands (true )
283+ err = runSqlCmd (t , s , c )
284+ if assert .NoError (t , err , ":!! with error should not return error" ) {
285+ assert .Contains (t , buf .buf .String (), ErrCommandsDisabled .Error ()+ SqlcmdEol )
286+ assert .NotContains (t , buf .buf .String (), "100" , "query should not run when syscommand disabled" )
287+ assert .Equal (t , 1 , s .Exitcode , "ExitCode after error" )
288+ }
289+ }
0 commit comments