@@ -205,11 +205,11 @@ func TestGetDownloadCommand(t *testing.T) {
205205 "oauth2" ,
206206 "activate" ,
207207 "--auth-params" ,
208- "' auth-params'" ,
208+ shellQuoteLiteral ( " auth-params" ) ,
209209 "|| true ) &&" ,
210210 PulsarctlExecutableFile ,
211211 "--auth-plugin" , "auth-plugin" ,
212- "--auth-params" , "' auth-params'" ,
212+ "--auth-params" , shellQuoteLiteral ( " auth-params" ) ,
213213 "--admin-service-url" , "$webServiceURL" ,
214214 "--tls-allow-insecure=true" ,
215215 "--tls-enable-hostname-verification=false" ,
@@ -239,7 +239,7 @@ func TestGetDownloadCommand(t *testing.T) {
239239 PulsarAdminExecutableFile ,
240240 "--admin-url" , "$webServiceURL" ,
241241 "--auth-plugin" , OAuth2AuthenticationPlugin ,
242- "--auth-params" , testOauth2 .AuthenticationParameters (),
242+ "--auth-params" , shellQuoteLiteral ( testOauth2 .AuthenticationParameters () ),
243243 "packages" , "download" , "function://public/default/test@v1" , "--path" , "function-package.jar" ,
244244 },
245245 false ,
@@ -252,7 +252,7 @@ func TestGetDownloadCommand(t *testing.T) {
252252 PulsarAdminExecutableFile ,
253253 "--admin-url" , "$webServiceURL" ,
254254 "--auth-plugin" , "auth-plugin" ,
255- "--auth-params" , "' auth-params'" ,
255+ "--auth-params" , shellQuoteLiteral ( " auth-params" ) ,
256256 "packages" , "download" , "sink://public/default/test@v1" , "--path" , "sink-package.jar" ,
257257 },
258258 false ,
@@ -335,6 +335,67 @@ func TestGetDownloadCommand(t *testing.T) {
335335 }
336336}
337337
338+ func TestShellQuoteLiteral (t * testing.T ) {
339+ testCases := []struct {
340+ name string
341+ input string
342+ expected string
343+ }{
344+ {
345+ name : "empty" ,
346+ input : "" ,
347+ expected : "''" ,
348+ },
349+ {
350+ name : "plain" ,
351+ input : "auth-params" ,
352+ expected : "'auth-params'" ,
353+ },
354+ {
355+ name : "embedded single quote" ,
356+ input : "a'b" ,
357+ expected : `'a'"'"'b'` ,
358+ },
359+ {
360+ name : "time partition pattern" ,
361+ input : "yyyy-MM-dd/HH'h'-mm'm'" ,
362+ expected : `'yyyy-MM-dd/HH'"'"'h'"'"'-mm'"'"'m'"'"''` ,
363+ },
364+ }
365+
366+ for _ , tc := range testCases {
367+ t .Run (tc .name , func (t * testing.T ) {
368+ assert .Equal (t , tc .expected , shellQuoteLiteral (tc .input ))
369+ })
370+ }
371+ }
372+
373+ func TestGetPulsarAdminCommandWithQuotedAuthParams (t * testing.T ) {
374+ authConfig := & v1alpha1.AuthConfig {
375+ GenericAuth : & v1alpha1.GenericAuth {
376+ ClientAuthenticationPlugin : "auth-plugin" ,
377+ ClientAuthenticationParameters : `{"token":"a'b"}` ,
378+ },
379+ }
380+
381+ command := getPulsarAdminCommand (false , false , nil , authConfig )
382+ assert .Equal (t , "auth-plugin" , command [4 ])
383+ assert .Equal (t , shellQuoteLiteral (`{"token":"a'b"}` ), command [6 ])
384+ }
385+
386+ func TestGetPulsarctlCommandWithQuotedAuthParams (t * testing.T ) {
387+ authConfig := & v1alpha1.AuthConfig {
388+ GenericAuth : & v1alpha1.GenericAuth {
389+ ClientAuthenticationPlugin : "auth-plugin" ,
390+ ClientAuthenticationParameters : `{"token":"a'b"}` ,
391+ },
392+ }
393+
394+ command := getPulsarctlCommand (false , false , nil , authConfig )
395+ assert .Equal (t , shellQuoteLiteral (`{"token":"a'b"}` ), command [5 ])
396+ assert .Equal (t , shellQuoteLiteral (`{"token":"a'b"}` ), command [11 ])
397+ }
398+
338399func TestGetFunctionRunnerImage (t * testing.T ) {
339400 javaRuntime := v1alpha1.Runtime {Java : & v1alpha1.JavaRuntime {
340401 Jar : "test.jar" ,
0 commit comments