Skip to content

Commit

Permalink
Allow empty values in Upload-Metadata header
Browse files Browse the repository at this point in the history
Fixes tus#117

Squashed commit of the following:

commit 1ddbd46abd80d1c39a4e2425b5a9bb002e9609ac
Author: Acconut <[email protected]>
Date:   Mon Aug 6 14:50:44 2018 +0200

    Cleanup code

commit b0a8d2b
Author: hedj <[email protected]>
Date:   Tue Jul 31 18:47:26 2018 +0800

    remove trailing space

commit 5796865
Author: hedj <[email protected]>
Date:   Tue Jul 31 18:41:40 2018 +0800

    brace style error

commit 58fd9c8
Author: hedj <[email protected]>
Date:   Tue Jul 31 18:32:54 2018 +0800

    if metadata is empty, or only contains spaces, \t, \n, invalid

commit a9abcc2
Author: hedj <[email protected]>
Date:   Tue Jul 31 18:29:01 2018 +0800

    if metadata is empty, or only contains spaces, \t, \n, invalid

commit 2f2fc0d
Author: hedj <[email protected]>
Date:   Tue Jul 31 18:21:39 2018 +0800

    if metadata is empty, return true; if only contains spaces, \t, \n, return true

commit a819acb
Author: hedj <[email protected]>
Date:   Tue Jul 31 17:46:49 2018 +0800

    get back my changes

commit 12cb2f2
Author: hedj <[email protected]>
Date:   Tue Jul 31 17:23:28 2018 +0800

    try original code to see if my changes led to the travis CI error

commit fcb895f
Author: hedj <[email protected]>
Date:   Tue Jul 31 17:14:52 2018 +0800

    try original code to see if my changes led to the travis CI error

commit 45f30a4
Author: hedj <[email protected]>
Date:   Tue Jul 31 17:03:26 2018 +0800

    change test case 3 in line 85 to false since we allow empty metadata

commit f4be763
Author: hedj <[email protected]>
Date:   Tue Jul 31 16:59:15 2018 +0800

    change test case 1 in line 83 to false

commit 2749283
Author: hedj <[email protected]>
Date:   Tue Jul 31 16:55:36 2018 +0800

    change test case 2 in line 84 to false

commit bbefa75
Author: hedj <[email protected]>
Date:   Tue Jul 31 16:41:10 2018 +0800

    bug in if statemetn

commit a428919
Author: hedj <[email protected]>
Date:   Tue Jul 31 16:39:45 2018 +0800

    syntax error in if statemetn

commit db394d9
Author: hedj <[email protected]>
Date:   Tue Jul 31 16:35:05 2018 +0800

    bug: RequestValidator _invalidUploadMetadataHeader should fail on non comma separated list

commit 07068d2
Author: hedj <[email protected]>
Date:   Tue Jul 31 16:14:26 2018 +0800

    fix compiling error: should be 'let i' instead of 'const i'

commit 95c516b
Author: hedj <[email protected]>
Date:   Tue Jul 31 16:02:37 2018 +0800

    fix lint errors

commit 324def5
Author: hedj <[email protected]>
Date:   Tue Jul 31 12:46:34 2018 +0800

    allowing empty metadata values in RequestValidator
  • Loading branch information
Acconut committed Aug 6, 2018
1 parent 6d571cb commit b5ca5c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/validators/RequestValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @author Ben Stahl <[email protected]>
*/


const CONSTANTS = require('../constants');

class RequestValidator {
Expand All @@ -33,9 +32,11 @@ class RequestValidator {
// be Base64 encoded. All keys MUST be unique.
static _invalidUploadMetadataHeader(value) {
const keypairs = value.split(',')
.map((keypair) => keypair.trim());
.map((keypair) => keypair.trim().split(' '));

return keypairs.some((keypair) => keypair.split(' ').length !== 2);
return keypairs.some(
(keypair) => keypair[0] === '' || (keypair.length !== 2 && keypair.length !== 1)
);
}

static _invalidXRequestedWithHeader() {
Expand Down
10 changes: 8 additions & 2 deletions test/Test-RequestValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ describe('RequestValidator', () => {
done();
});

it('should validate keys without a value', (done) => {
assert.equal(RequestValidator._invalidUploadMetadataHeader('hello'), false);
assert.equal(RequestValidator._invalidUploadMetadataHeader('hello world, tusrules'), false);
done();
});

it('should fail on non comma separated list', (done) => {
assert.equal(RequestValidator._invalidUploadMetadataHeader('hello'), true);
assert.equal(RequestValidator._invalidUploadMetadataHeader('hello world, tusrules'), true);
assert.equal(RequestValidator._invalidUploadMetadataHeader('too-many spaces'), true);
assert.equal(RequestValidator._invalidUploadMetadataHeader(''), true);
assert.equal(RequestValidator._invalidUploadMetadataHeader(' \t\n'), true);
done();
});
});
Expand Down

0 comments on commit b5ca5c2

Please sign in to comment.