Skip to content

Commit ff04394

Browse files
committed
Built out more automated tests. Updated deps.
1 parent 84da0c7 commit ff04394

File tree

76 files changed

+1230
-758
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1230
-758
lines changed

.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
assets/dependencies/**/*.js
21
views/**/*.ejs
32
test/coverage/**/*

.idea/dictionaries/neonexusdemortis.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Run_Tests.xml

-17
This file was deleted.

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Changelog
22

3+
## [v3.2.2](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v3.2.1...v3.2.2) (2022-11-16)
4+
5+
### Features
6+
7+
* Built out more automated tests for better coverage.
8+
* Updated dependencies.
9+
310
## [v3.2.1](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v3.2.0...v3.2.1) (2022-11-16)
411

512
### Features
613

7-
Downgraded SASS to prevent issues with deprecations.
14+
* Downgraded SASS to prevent issues with deprecations.
815

916
## [v3.2.0](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v3.1.1...v3.2.0) (2022-11-16)
1017

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module.exports.bootstrap = function(next) {
119119
## PwnedPasswords.com Integration
120120
When a new password is being created, it is checked with the [PwnedPasswords.com API](https://haveibeenpwned.com/API/v3#PwnedPasswords). This API uses a k-anonymity model, so the password that is searched for is never exposed to the API. Basically, the password is hashed, then the first 5 characters are sent to the API, and the API returns any hashes that start with those 5 characters, including the amount of times that hash (aka password) has been found in known security breaches.
121121

122-
This functionality is turned on by default, and can be shutoff per-use, or globally throughout the app. [`sails.helpers.isPasswordValid`](api/helpers/is-password-valid.js) can be used with `skipPwned` option set to `true`, to disable the check per use (see [`api/controllers/common/login.js`](api/controllers/common/login.js#L40) for example). Inside of [`config/security.js`](config/security.js), the variable `checkPwned` can be set to `false` to disable it globally.
122+
This functionality is turned on by default, and can be shutoff per-use, or globally throughout the app. [`sails.helpers.isPasswordValid`](api/helpers/is-password-valid.js) can be used with `skipPwned` option set to `true`, to disable the check per use (see [`api/controllers/common/login.js`](api/controllers/common/login.js#L40) for example). Inside of [`config/security.js`](config/security.js), the variable `checkPwnedPasswords` can be set to `false` to disable it globally.
123123

124124
## What about SEO?
125125
I recommend looking at [prerender.io](https://prerender.io). They offer a service (free up to 250 pages) that caches the end result of a JavaScript-rendered view (React, Vue, Angular), allowing search engines to crawl otherwise un-crawlable web views. You can use the service in a number of ways. One way, is to use the [prerender-node](https://www.npmjs.com/package/prerender-node) package. To use it with Sails, you'll have to add it to the [HTTP Middleware](https://sailsjs.com/documentation/concepts/middleware#?http-middleware). Here's a quick example:

api/helpers/create-log.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ module.exports = {
2828
request = (inputs.req.requestId) ? inputs.req.requestId : null;
2929

3030
const newLog = {
31+
id: 'c', // required, but auto-generated
3132
data: inputs.data,
3233
user,
3334
request,
3435
description: inputs.description
3536
};
3637

3738
sails.models.log.create(newLog).meta({fetch: true}).exec((err, newLog) => {
39+
/* istanbul ignore if */
3840
if (err) {
3941
console.error(err);
4042

4143
return exits.error(err);
4244
}
4345

44-
return exits.success({log: newLog});
46+
return exits.success(newLog);
4547
});
4648
}
4749
};

api/helpers/finalize-request-log.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ module.exports = {
3232

3333
fn: async function(inputs, exits) {
3434
if (inputs.req.requestId) {
35+
const bleep = '*******';
3536
let out = _.merge({}, inputs.body),
36-
headers = _.merge({}, inputs.res.getHeaders()), // copy the object
37-
bleep = '*******';
37+
headers = _.merge({}, inputs.res.getHeaders()); // copy the object
3838

3939
if (!sails.config.logSensitiveData) { // a custom configuration option, for the request logger hook
4040
if (out._csrf) {
@@ -60,8 +60,8 @@ module.exports = {
6060
out = stringify(out);
6161
}
6262

63-
const time = Number(process.hrtime.bigint() - inputs.req._requestStartTime) / 1000000, // convert the bigint nanoseconds into milliseconds
64-
totalTime = time.toFixed(4) + 'ms';
63+
const time = Number(process.hrtime.bigint() - inputs.req._requestStartTime) / 1000000; // convert the bigint nanoseconds into milliseconds
64+
const totalTime = time.toFixed(4) + 'ms';
6565

6666
let log = {
6767
responseCode: inputs.res.statusCode,
@@ -71,6 +71,7 @@ module.exports = {
7171
};
7272

7373
sails.models.requestlog.update(inputs.req.requestId, log, (err) => {
74+
/* istanbul ignore if */
7475
if (err) {
7576
console.log(err);
7677
}

api/helpers/generate-token.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ module.exports = {
1616
}
1717
},
1818

19-
exits: {},
20-
2119
fn: function(inputs, exits) {
2220
return exits.success(
2321
crypto.createHmac('sha256', sails.config.session.secret).update(
24-
crypto.randomBytes(21) // cryptographically-secure random characters
25-
+ moment(new Date()).format() // throw in the current time stamp
26-
+ 'I\'m a tea pot' // the best HTTP status code
27-
+ inputs.extra // an optional way to add a bit more randomness to the mix
28-
+ crypto.randomBytes(21)
22+
crypto.randomBytes(21) // cryptographically-secure random characters
23+
+ moment(new Date()).format() // throw in the current time stamp
24+
+ inputs.extra // an optional way to add a bit more randomness to the mix
25+
+ crypto.randomBytes(21) // cryptographically-secure random characters
2926
).digest('hex')
3027
);
3128
}

api/helpers/generate-uuid.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {v4: uuidv4} = require('uuid');
1+
const crypto = require('crypto');
22

33
module.exports = {
44
friendlyName: 'Generate UUID',
@@ -7,7 +7,17 @@ module.exports = {
77

88
sync: true, // not async
99

10+
inputs: {
11+
disableEntropyCache: {
12+
description: 'This will force the RNG to ignore the pre-generated values, in-turn will mean a performance hit.',
13+
type: 'bool',
14+
defaultsTo: false
15+
}
16+
},
17+
1018
fn: (inputs, exits) => {
11-
return exits.success(uuidv4());
19+
return exits.success(crypto.randomUUID({
20+
disableEntropyCache: inputs.disableEntropyCache
21+
}));
1222
}
1323
};

api/helpers/is-password-valid.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ module.exports = {
7777
}
7878

7979
if (!errors.length) {
80-
if (sails.config.security.checkPwned && !inputs.skipPwned) {
80+
if (sails.config.security.checkPwnedPasswords && !inputs.skipPwned) {
8181
const sha1pass = sha1(inputs.password).toUpperCase();
8282
const passChunk1 = sha1pass.substring(0, 5);
8383
const passChunk2 = sha1pass.substring(5);
8484

8585
superagent.get('https://api.pwnedpasswords.com/range/' + passChunk1).end((err, res) => {
86+
/* istanbul ignore if */
8687
if (err) {
8788
console.error(err);
8889

@@ -104,6 +105,7 @@ module.exports = {
104105
return exits.success(true);
105106
}
106107

108+
/* istanbul ignore next */
107109
return exits.success(['Unknown internal error']);
108110
});
109111
} else {

api/models/Log.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ module.exports = {
33

44
attributes: {
55
id: {
6-
type: 'number',
7-
autoIncrement: true
6+
type: 'string',
7+
columnType: 'varchar(36)',
8+
required: true
89
},
910

1011
user: {
@@ -31,5 +32,11 @@ module.exports = {
3132
},
3233

3334
updatedAt: false
35+
},
36+
37+
beforeCreate: async function(log, next) {
38+
log.id = sails.helpers.generateUuid();
39+
40+
return next();
3441
}
3542
};

config/env/production.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* > it to your .gitignore file. If your repository will be publicly viewable,
1616
* > don't add private/sensitive data (like API secrets / db passwords) to this file!
1717
*
18-
* For more best practices and tips, see:
18+
* For more best-practices and tips, see:
1919
* https://sailsjs.com/docs/concepts/deployment
2020
*/
2121

config/security.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ module.exports.security = {
6868
*
6969
* See this for more details: https://haveibeenpwned.com/API/v3#PwnedPasswords
7070
*/
71-
checkPwned: true
71+
checkPwnedPasswords: true
7272
};

0 commit comments

Comments
 (0)