Skip to content

Commit 7349650

Browse files
committed
PR 375: Suggested changes
- `buildOptions` now throws an error if `hashAlgorithm` is not defined, instead of resetting to the default value of 'md5' - Moved + symbol for a string concatination to the beginning of the next line - Updated the README.md with information on the new hashAlgorithm option, and how the `md5` property is defined in the new version - Iterated the version in package.json from 1.5.0 -> 1.5.1 ref: #375
1 parent a230423 commit 7349650

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ The **req.files.foo** object will contain the following:
5050

5151
* Before 1.0.0, `md5` is an MD5 checksum of the uploaded file.
5252
* From 1.0.0 until 1.1.1, `md5` is a function to compute an MD5 hash ([Read about it here.](https://github.com/richardgirges/express-fileupload/releases/tag/v1.0.0-alpha.1)).
53-
* From 1.1.1 onward, `md5` is reverted back to MD5 checksum value and also added full MD5 support in case you are using temporary files.
53+
* From 1.1.1 until 1.5.1, `md5` is reverted back to MD5 checksum value and also added full MD5 support in case you are using temporary files.
54+
* From 1.5.1 onward, `md5` still holds the checksum value, but the checksum is generated with the provided `hashAlgorithm` option. The property name remains `md5` for backwards compatibility.
5455

5556

5657
### Examples
@@ -124,6 +125,7 @@ parseNested | <ul><li><code>false</code>&nbsp;**(default)**</li><li><code>true</
124125
debug | <ul><li><code>false</code>&nbsp;**(default)**</li><li><code>true</code></ul> | Turn on/off upload process logging. Can be useful for troubleshooting.
125126
logger | <ul><li><code>console</code>&nbsp;**(default)**</li><li><code>{log: function(msg: string)}</code></li></ul> | Customizable logger to write debug messages to. Console is default.
126127
uploadTimeout | <ul><li><code>60000</code>&nbsp;**(default)**</li><li><code>Integer</code></ul> | This defines how long to wait for data before aborting. Set to 0 if you want to turn off timeout checks.
128+
hashAlgorithm | <ul><li><code>md5</code>&nbsp;**(default)**</li><li><code>String</code></li></ul> | Allows the usage of alternative hashing algorithms for file integrity checks. This option must be an algorithm that is supported on the running system's installed OpenSSL version. On recent releases of OpenSSL, <code>openssl list -digest-algorithms</code> will display the available digest algorithms.
127129

128130
# Help Wanted
129131
Looking for additional maintainers. Please contact `richardgirges [ at ] gmail.com` if you're interested. Pull Requests are welcome!

lib/utilities.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const promiseCallback = (resolve, reject) => {
6969
/**
7070
* Builds instance options from arguments objects(can't be arrow function).
7171
* @returns {Object} - result options.
72+
* @throws {Error} - when a valid hashAlgorithm option is not provided.
7273
*/
7374
const buildOptions = function() {
7475
const result = {};
@@ -77,16 +78,11 @@ const buildOptions = function() {
7778
Object.keys(options).forEach(i => result[i] = options[i]);
7879
});
7980

80-
// Ensure a hashAlgorithm option exists.
81-
if (!result.hashAlgorithm) {
82-
result.hashAlgorithm = 'md5';
83-
}
84-
8581
// Ensure the configured hashAlgorithm is available on the system
8682
if (crypto.getHashes().find(h => result.hashAlgorithm === h) === undefined) {
8783
throw Error(
88-
`Hashing algorithm '${result.hashAlgorithm}' is not supported by this system's OpenSSL ` +
89-
`version`
84+
`Hashing algorithm '${result.hashAlgorithm}' is not supported by this system's OpenSSL `
85+
+ `version`
9086
);
9187
}
9288

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-fileupload",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"author": "Richard Girges <[email protected]>",
55
"description": "Simple express file upload middleware that wraps around Busboy",
66
"main": "./lib/index",

test/utilities.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,15 @@ describe('utilities: Test of the utilities functions', function() {
198198
//buildOptions tests
199199
describe('Test buildOptions function', () => {
200200

201-
const source = { option1: '1', option2: '2' };
201+
const source = { option1: '1', option2: '2', hashAlgorithm: 'md5' };
202202
const sourceAddon = { option3: '3', hashAlgorithm: 'sha256'};
203203
const expected = { option1: '1', option2: '2', hashAlgorithm: 'md5' };
204204
const expectedAddon = { option1: '1', option2: '2', option3: '3', hashAlgorithm: 'sha256'};
205205

206-
it(
207-
'buildOptions returns an equal object to the object which was passed + hashAlgorithm '
208-
+ 'property',
209-
() => {
210-
let result = buildOptions(source);
211-
assert.deepStrictEqual(result, expected);
212-
}
213-
);
206+
it('buildOptions returns an equal object to the object which was passed', () => {
207+
let result = buildOptions(source);
208+
assert.deepStrictEqual(result, source);
209+
});
214210

215211
it('buildOptions doesnt add non object or null arguments to the result', () => {
216212
let result = buildOptions(source, 2, '3', null);
@@ -222,6 +218,10 @@ describe('utilities: Test of the utilities functions', function() {
222218
assert.deepStrictEqual(result, expectedAddon);
223219
});
224220

221+
it('buildOptions throws an error when not provided a supported hashAlgorithm', () => {
222+
assert.throws(() => buildOptions({}));
223+
});
224+
225225
it('buildOptions throws an error when given an unsupported hashAlgorithm', () => {
226226
assert.throws(() => buildOptions({ hashAlgorithm: 'not-actual-algo' }));
227227
});

0 commit comments

Comments
 (0)