Skip to content

Commit 0339f09

Browse files
committed
Added defaults to environment variables.
1 parent a63afd2 commit 0339f09

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ This repo is not installable via `npm`. Instead, Github provides a handy "Use th
3131
|npm run coverage | Runs [NYC](https://www.npmjs.com/package/nyc) coverage reporting of the Mocha tests, which generates HTML in `test/coverage`.
3232

3333
### Environment Variables used for remote servers:
34-
| Variable | Description
35-
|---------------|----------------------
36-
| ASSETS_URL | Webpack is configured to modify static asset URLs to point to a CDN, like CloudFront. MUST end with a slash " / ".
37-
| BASE_URL | The address of the Sails instance.
38-
| DB_HOST | The hostname of the datastore.
39-
| DB_USER | Username for the datastore.
40-
| DB_PASS | Password for the datastore.
41-
| DB_NAME | The name of the database inside the datastore.
42-
| DB_PORT | The port number for datastore.
43-
| DB_SSL | If the datastore requires SSL, set this to "true".
34+
| Variable | DEV default | PROD default | Description
35+
|------------|----------------------|-------------------------|----------------------
36+
| ASSETS_URL | "" (empty string) | "" (empty string) | Webpack is configured to modify static asset URLs to point to a CDN, like CloudFront. MUST end with a slash " / ".
37+
| BASE_URL | raw:https://my‑api.app | raw:https://my‑api.app | The address of the Sails instance.
38+
| DB_HOST | localhost | localhost | The hostname of the datastore.
39+
| DB_USER | root | produser | Username for the datastore.
40+
| DB_PASS | mypass | myprodpassword | Password for the datastore.
41+
| DB_NAME | myapp | proddatabase | The name of the database inside the datastore.
42+
| DB_PORT | 3306 | 3306 | The port number for datastore.
43+
| DB_SSL | false | false | If the datastore requires SSL, set this to "true".
4444

4545
## Request Logging
4646
Automatic incoming request logging, is a 2 part process. First, the [`request-logger` hook](api/hooks/request-logger.js) gathers info from the request, and creates a new [`RequestLog` record](api/models/RequestLog.js), making sure to mask anything that may be sensitive, such as passwords. Then, a custom response gathers information from the response, again, scrubbing sensitive data (using the [customToJSON](https://sailsjs.com/documentation/concepts/models-and-orm/model-settings?identity=#customtojson) feature of Sails models) to prevent leaking of password hashes, or anything else that should never be publicly accessible. The [`keepModelsSafe` helper](api/helpers/keep-models-safe.js) and the custom responses (such as [ok](api/responses/ok.js) or [serverError](api/responses/serverError.js)) are responsible for the final leg of request logs.
@@ -85,7 +85,7 @@ module.exports.bootstrap = function(next) {
8585
+ [Sails Professional / Enterprise Options](https://sailsjs.com/enterprise)
8686
+ [`react-bootstrap` Documentation](https://react-bootstrap.netlify.app/)
8787
+ [Webpack Documentation](https://webpack.js.org/)
88-
+ [Simple data fixtures for testing Sails.js](https://www.npmjs.com/package/fixted)
88+
+ [Simple data fixtures for testing Sails.js (the npm package `fixted`)](https://www.npmjs.com/package/fixted)
8989

9090

9191
### Version info

test/unit/hooks/request-logger.test.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ describe('Request Logger', function() {
77
before( function() {
88
logger = requestLogger(sails);
99

10+
// sanity check
11+
sails.models.should.have.property('requestlog');
12+
1013
hook = logger.routes.before['*'];
1114
hook.should.be.a('function');
1215
});
@@ -73,11 +76,40 @@ describe('Request Logger', function() {
7376
const defaultReq = {
7477
method: 'GET',
7578
path: '/',
76-
body: {},
77-
query: {},
78-
headers: {}
79+
hostname: 'localtest',
80+
body: {
81+
password: 'password1',
82+
password2: 'password2',
83+
currentPassword: 'currentPassword',
84+
newPassword: 'newPassword',
85+
newPassword2: 'newPassword2',
86+
pass: 'lamepassword'
87+
},
88+
query: {
89+
securityToken: 'somelongsecuritytoken'
90+
},
91+
headers: {
92+
securityToken: 'somelongsecuritytokenintheheaders'
93+
}
7994
};
95+
const defaultRes = {};
96+
const defaultCb = chai.spy();
97+
98+
before(function() {
99+
// force this, just in-case
100+
sails.config.logSensitiveData = false;
101+
});
80102

103+
it('Not log sensitive information', function() {
104+
let thisReq = _.merge({}, defaultReq);
81105

106+
hook = hook.bind(this);
107+
hook(thisReq, defaultRes, defaultCb);
108+
109+
defaultCb.should.have.been.called();
110+
111+
thisReq.should.have.property('requestId');
112+
thisReq.should.have.property('_customStartTime');
113+
});
82114
});
83115
});

0 commit comments

Comments
 (0)