Skip to content

Commit

Permalink
Merge pull request #7290 from taskcluster/fix/auth-pagination
Browse files Browse the repository at this point in the history
feat(auth): Fix error handling in continuation token
  • Loading branch information
lotas authored Sep 30, 2024
2 parents b272822 + 45f6e77 commit 1f50152
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog/a2Z3cBueQ22fD0s4BGC7bQ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
audience: users
level: patch
---
Fixes continuation token error handling
7 changes: 6 additions & 1 deletion services/auth/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ const rolesResponseBuilder = async (that, req, res) => {

// Assign the continuationToken
if (req.query.continuationToken) {
continuationToken = hashids.decode(req.query.continuationToken);
try {
continuationToken = hashids.decode(req.query.continuationToken);
} catch (err) {
// hashids.decode will throw an error if token contains invalid characters
return res.reportError('InputError', 'Invalid continuationToken', {});
}
// If continuationToken is invalid
if (continuationToken.length === 0) {
return res.reportError('InputError', 'Invalid continuationToken', {});
Expand Down
6 changes: 6 additions & 0 deletions services/auth/test/role_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ helper.secrets.mockSuite(testing.suiteName(), ['gcp'], function(mock, skipping)
await helper.apiClient.listRoleIds(query)
.then(() => assert(false, 'Expected error'),
err => assert(err.statusCode === 400, 'Expected 400'));

// testing unexpected characters that make hashids.decode throw error
query.continuationToken = '@@something##';
await helper.apiClient.listRoleIds(query)
.then(() => assert(false, 'Expected error'),
err => assert(err.statusCode === 400, 'Expected 400'));
});

test('listRoles2', async () => {
Expand Down

0 comments on commit 1f50152

Please sign in to comment.