fix: unquote environment variable passed to hook commands#410
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #410 +/- ##
==========================================
- Coverage 70.31% 70.29% -0.02%
==========================================
Files 220 220
Lines 18482 18484 +2
==========================================
- Hits 12996 12994 -2
- Misses 4314 4316 +2
- Partials 1172 1174 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
zimeg
left a comment
There was a problem hiding this comment.
💌 Notes on code for the amazing reviewers! I am also planning to follow up with testing notes before asking for particular review 🧪 ✨
| var cmdEnvVars = os.Environ() | ||
| cmdEnvVars = append(cmdEnvVars, goutils.MapToStringSlice(opts.Env, "")...) | ||
| for name, value := range opts.Env { | ||
| cmdEnvVars = append(cmdEnvVars, name+"="+value) |
There was a problem hiding this comment.
🔭 note: These values are set for both the default and message-boundaries protocols:
slack-cli/internal/hooks/shell.go
Lines 56 to 59 in 8056444
| // To avoid removing any environment variables that are set in the current environment, we first set the cmd.Env to the current environment. | ||
| // before adding any new environment variables. | ||
| var cmdEnvVars = os.Environ() | ||
| cmdEnvVars = append(cmdEnvVars, goutils.MapToStringSlice(sdkManagedConnectionStartHookOpts.Env, "")...) |
There was a problem hiding this comment.
🏁 note: I understand the MapToStringSlice utilities to be useful in escaping command line arguments but we might not need this with the direct environment variable value setting in commands.
🏆 ramble: This implementation in localserver is the other find of a direct call to the hooks command executor so shares the change!
|
🔬 More findings on the scope of this bug and confidence in a safe changes! 🐛 Hooks impacted This PR changes how environment variables are set for both hook scripts and the The slack-cli/internal/pkg/platform/localserver.go Lines 279 to 311 in e1bebf8 $ slack create asdf -t slack-samples/bolt-js-starter-template
$ cd asdf
$ vim app.jsconst app = new App({
...
socketMode: true,
appToken: process.env.SLACK_CLI_XAPP, // Change this from SLACK_APP_TOKEN to SLACK_CLI_XAPP
});$ slack run
...
[ERROR] bolt-app Failed to start the app Error: An API error occurred: invalid_authWith the changes of this branch, the token is passed as the expected string! The common slack-cli/internal/pkg/apps/install.go Lines 844 to 873 in e1bebf8 The slack-cli/internal/pkg/platform/run.go Lines 103 to 130 in e1bebf8 slack-cli/internal/pkg/platform/localserver.go Lines 197 to 221 in e1bebf8 Overall I'm feeling alright that this change is a fix for unnoticed bugs in our hook implementation and we'll match specs closer more 🤓 📣 Please do callout misunderstandings in these scopes! I'm hoping these findings can be useful in testing too! |
| "BATMAN": "robin hood", | ||
| "YIN": "yang", |
There was a problem hiding this comment.
note: I think we want to keep it as Batman and Robin (the duo/sidekick to Batman), not Batman and Robinhood (two separate fictional characters).
There was a problem hiding this comment.
@mwbrooks I didn't want to take from the fun! 😉
I'll follow up with an update to add another example that includes a space elsewhere, which is the intention of initial change I meant!
Co-authored-by: Michael Brooks <michael@michaelbrooks.ca>
|
@mwbrooks Thanks for reviewing this and searches prior! 🔍 ✨ I'll merge this with the kind improvements to tests. This unblocks a lot more for environment variables ahead that I'm excited for 🌲 |
Changelog
Summary
This PR fixes an issue where environment variables were set with double quotes surrounding values:
slack-cli/internal/goutils/map.go
Lines 23 to 39 in 8056444
📚 Reference: https://pkg.go.dev/os/exec#Cmd
Requirements