-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Corrected handling of HTTP Basic edge cases
Previous implementation: empty user-pass -> error basic realm no " " separator -> error 400 no : separator -> error basic realm empty password -> error basic realm empty username -> error basic realm New implementation: empty user-pass -> error 400 no " " separator -> error 400 no : separator -> error 400 empty password -> success empty username -> success Also fixed passwords containing ':' being truncated. This fixes: - jaredhanson/passport-http#20 - jaredhanson/passport-http#41 - jaredhanson/passport-http#42 - jaredhanson/passport-http#63 - jaredhanson/passport-http#78 The new implemementation complies with https://tools.ietf.org/html/rfc2617#section-2.
- Loading branch information
1 parent
07fd716
commit 4cc025a
Showing
4 changed files
with
187 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
|
||
/** | ||
* Splits a string on the first occurrence of the provided separator. | ||
* Returns an array with one or two elements. | ||
* @param {String} string | ||
* @param {String} separator | ||
*/ | ||
splitFirst: (string, separator) => { | ||
const separatorIndex = string.indexOf(separator); | ||
|
||
if (separatorIndex < 0) { | ||
return [string]; | ||
} | ||
|
||
return [ | ||
string.substring(0, separatorIndex), | ||
string.substring(separatorIndex + 1), | ||
]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const vows = require('vows'); | ||
const assert = require('assert'); | ||
const stringUtils = require('../lib/string.util'); | ||
const {splitFirst} = stringUtils; | ||
|
||
vows.describe('string utils').addBatch({ | ||
|
||
'module': { | ||
'should export splitFirst': () => { | ||
assert.isFunction(stringUtils.splitFirst); | ||
}, | ||
}, | ||
|
||
'splitFirst': { | ||
'should split only first': () => { | ||
assert.deepStrictEqual(splitFirst('bob:secret:pw', ':'), ['bob', 'secret:pw']); | ||
assert.deepStrictEqual(splitFirst('a:bb:a:d', ':'), ['a', 'bb:a:d']); | ||
}, | ||
'should handle non-existing seperator': () => { | ||
assert.deepStrictEqual(splitFirst('abc', ':'), ['abc']); | ||
}, | ||
}, | ||
|
||
}).export(module); |