Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAILDEV_OUTGOING_SECURE is not honored #315

Open
jtudelag opened this issue Jul 16, 2020 · 5 comments
Open

MAILDEV_OUTGOING_SECURE is not honored #315

jtudelag opened this issue Jul 16, 2020 · 5 comments

Comments

@jtudelag
Copy link

Hey!!

Awesome project!!

I just notice that no matter whether MAILDEV_OUTGOING_SECURE is set or not, it is not honored, defaults to unsecure always.
Code "compiled" from master.

bin/maildev 

MailDev outgoing SMTP Server smtp.com:25 (user:undefined, pass:undefined, secure:no)
MailDev webapp running at http://0.0.0.0:1080
MailDev SMTP Server running at 0.0.0.0:1025
env | grep -i MAILDEV
MAILDEV_OUTGOING_SECURE=true
MAILDEV_OUTGOING_HOST=smtp.com

Thanks!

@jtudelag
Copy link
Author

Also, I investigated a bit further, and it seems that all the "booleans" input args are not being processed well when using env vars.

@bburky
Copy link

bburky commented Aug 11, 2021

I'm not sure what the desired behavior is, but this change to options.js would allow the following to work:

FOO=false
FOO=true
FOO=bar
# Uses the default value
FOO=
diff --git a/lib/options.js b/lib/options.js
index 3e67bc9..f487eed 100644
--- a/lib/options.js
+++ b/lib/options.js
@@ -39,7 +39,11 @@ module.exports.appendOptions = function (program, options) {
     const flag = option[0]
     const envVariable = option[1]
     const description = option[2]
-    const defaultValue = process.env[envVariable] || option[3]
+    const envValue = process.env[envVariable] || ""
+    // If the env value is "true" or "false", parse it as a boolean
+    // Else, if it is a non-falsy value, use it
+    // Else, use the default value
+    const defaultValue = envValue.toLowerCase() == "false" ? false : envValue.toLowerCase() == "true" || envValue || option[3]
     const fn = option[4]
     if (fn) {
       return chain.option(flag, description, fn, defaultValue)

I can submit this as a PR, but I don't know if you want a more capable options parser that would also allow 0 and 1 which are often accepted in environment variables.

@bburky
Copy link

bburky commented Aug 11, 2021

Commander may need to be updated to 3.0.0+ too, I didn't test this.
tj/commander.js#987

@reischlfranz
Copy link

I'm not sure what the desired behavior is, but this change to options.js would allow the following to work:
[...]

I can confirm that this change from @bburky fixes the issue with boolean environment variables. Can we have this code merged?

@dada051
Copy link

dada051 commented Jul 9, 2022

Don't know wich one of the solution is better than the other, but it should be great to have one quickly :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants