-
-
Notifications
You must be signed in to change notification settings - Fork 51
Compliance/fix scope #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Compliance/fix scope #267
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a2a54c4
fix: scope in body responses is always a string
jankapunkt 687b66e
fix: revert scope util to omit empty-string scope values
jankapunkt d5ae484
tests: remove randomness from compliance tests
jankapunkt 0d98453
fix: parseScope rejects Array values
jankapunkt 960a962
tests: reverse requests with scopes as Arrays
jankapunkt fcb567b
fix: parse scope in AuthenticateHandler impl
jankapunkt 77d00b2
fix: improved parsing of requested scopes
jankapunkt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.