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

Alternate fix for env variable in lib/config.js #23

Merged
merged 2 commits into from
Feb 5, 2016

Conversation

shaunanoordin
Copy link
Member

Bugfix: 'env' variable in config.js was returning invalid values.

This PR (a whitelist+fail dangerous fix) is an alternative to PR #22 (a fallback+failsafe fix). Please close PR #22 if this PR is merged, or vice versa.

Symptoms:

Analysis:

  • We've detected that the env variable in lib/config.js doesn't always have one the valid values, i.e. 'production', 'staging' or 'cam'.

Actions:

  • Recommendation: add a value whitelist so the env var cannot be invalid; throw an error otherwise.

@brian-c , this is based on our discussion in #22 (comment) and is ready for yor review, arigato.

Expectiaton: the `env` variable can be one of three possible values:
'production', 'staging' or 'cam'.

Reality: Due to the nature of the environment the code runs in, this line...
```
var envFromShell = process.env.NODE_ENV;
```
...can return any number of different values, from 'staging' to 'development',
etc.

This will cause issues when we have...
```
var env = envFromBrowser || envFromShell || DEFAULT_ENV;
```
...as `env` will now take on an invalid value.

Fix: See the code.
@@ -37,6 +37,11 @@ var envFromShell = process.env.NODE_ENV;

var env = envFromBrowser || envFromShell || DEFAULT_ENV;

if (!env.match(/^(production|staging|cam)$/)) {
throw 'Panoptes Javascript Client Error: Invalid Environment; ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws a string, which is generally unexpected. Try throw new Error('...').

@shaunanoordin
Copy link
Member Author

Acknowledged; whitelist now updated to throw an Error instead of a string.

brian-c added a commit that referenced this pull request Feb 5, 2016
Alternate fix for `env` variable in lib/config.js
@brian-c brian-c merged commit 42b2107 into master Feb 5, 2016
@brian-c brian-c deleted the fix-env-var-on-config-mk2 branch February 5, 2016 18:02
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

Successfully merging this pull request may close these issues.

2 participants