-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from node-oauth/compliance/fix-scope
Compliance/fix scope
- Loading branch information
Showing
12 changed files
with
94 additions
and
113 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
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 |
---|---|---|
@@ -1,16 +1,25 @@ | ||
const isFormat = require('@node-oauth/formats'); | ||
const InvalidScopeError = require('../errors/invalid-scope-error'); | ||
const whiteSpace = /\s+/g; | ||
|
||
module.exports = { | ||
parseScope: function (requestedScope) { | ||
if (!isFormat.nqschar(requestedScope)) { | ||
if (requestedScope == null) { | ||
return undefined; | ||
} | ||
|
||
if (typeof requestedScope !== 'string') { | ||
throw new InvalidScopeError('Invalid parameter: `scope`'); | ||
} | ||
|
||
if (requestedScope == null) { | ||
return undefined; | ||
// XXX: this prevents spaced-only strings to become | ||
// treated as valid nqchar by making them empty strings | ||
requestedScope = requestedScope.trim(); | ||
|
||
if(!isFormat.nqschar(requestedScope)) { | ||
throw new InvalidScopeError('Invalid parameter: `scope`'); | ||
} | ||
|
||
return requestedScope.split(' '); | ||
return requestedScope.split(whiteSpace); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
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
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
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
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,45 @@ | ||
const { parseScope } = require('../../../lib/utils/scope-util'); | ||
const should = require('chai').should(); | ||
|
||
describe(parseScope.name, () => { | ||
it('should return undefined on nullish values', () => { | ||
const values = [undefined, null]; | ||
values.forEach(str => { | ||
const compare = parseScope(str) === undefined; | ||
compare.should.equal(true); | ||
}); | ||
}); | ||
it('should throw on non-string values', () => { | ||
const invalid = [1, -1, true, false, {}, ['foo'], [], () => {}, Symbol('foo')]; | ||
invalid.forEach(str => { | ||
try { | ||
parseScope(str); | ||
should.fail(); | ||
} catch (e) { | ||
e.message.should.eql('Invalid parameter: `scope`'); | ||
} | ||
}); | ||
}); | ||
it('should throw on empty strings', () => { | ||
const invalid = ['', ' ', ' ', '\n', '\t', '\r']; | ||
invalid.forEach(str => { | ||
try { | ||
parseScope(str); | ||
should.fail(); | ||
} catch (e) { | ||
e.message.should.eql('Invalid parameter: `scope`'); | ||
} | ||
}); | ||
}); | ||
it('should split space-delimited strings into arrays', () => { | ||
const values = [ | ||
['foo', ['foo']], | ||
['foo bar', ['foo', 'bar']], | ||
['foo bar', ['foo', 'bar']], | ||
]; | ||
values.forEach(([str, compare]) => { | ||
const parsed = parseScope(str); | ||
parsed.should.deep.equal(compare); | ||
}); | ||
}); | ||
}); |