Skip to content

Commit 68ba89c

Browse files
Fix issue where new users, that did not get the Topcoder User role, could not update their preferences
1 parent e024795 commit 68ba89c

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

app-routes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ function checkIfExists (source, term) {
3232
throw new Error('Term argument should be either a string or an array')
3333
}
3434

35+
if (source.length === 0) {
36+
// Source is empty. No need to check term
37+
return true
38+
} else if (terms.length === 0) {
39+
if (source.length === 0) {
40+
// Source is empty. Term thus qualifies
41+
return true
42+
}
43+
}
44+
3545
for (let i = 0; i < terms.length; i++) {
3646
if (source.includes(terms[i])) {
3747
return true

config/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
PORT: process.env.PORT || 3000,
88
API_VERSION: process.env.API_VERSION || '/v5',
99
AUTH_SECRET: process.env.AUTH_SECRET || 'mysecret',
10-
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '') : '["https://api.topcoder-dev.com"]',
10+
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '') : '["https://api.topcoder-dev.com", "https://topcoder-dev.auth0.com"]',
1111

1212
// used to get M2M token
1313
AUTH0_URL: process.env.AUTH0_URL,

src/routes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ module.exports = {
1212
controller: 'PreferenceController',
1313
method: 'getUserPreferencesHead',
1414
auth: 'jwt',
15-
access: [constants.UserRoles.Admin, constants.UserRoles.User],
15+
access: [],
1616
scopes: [constants.Scopes.ReadPreference, constants.Scopes.AllPreference]
1717
},
1818
get: {
1919
controller: 'PreferenceController',
2020
method: 'getUserPreferences',
2121
auth: 'jwt',
22-
access: [constants.UserRoles.Admin, constants.UserRoles.User],
22+
access: [],
2323
scopes: [constants.Scopes.ReadPreference, constants.Scopes.AllPreference]
2424
},
2525
put: {
2626
controller: 'PreferenceController',
2727
method: 'updateUserPreferences',
2828
auth: 'jwt',
29-
access: [constants.UserRoles.Admin, constants.UserRoles.User],
29+
access: [],
3030
scopes: [constants.Scopes.UpdatePreference, constants.Scopes.AllPreference]
3131
}
3232
},

test/e2e/PreferenceService.test.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,6 @@ describe('Topcoder - MemberPreferences API E2E Test', () => {
134134
expect(res.body.message).to.equal('You are not authorized to perform this action')
135135
})
136136

137-
it('Get user preferences user role is not allowed, return 403', async () => {
138-
const res = await chai.request(app)
139-
.get(`${config.API_VERSION}/users/${userId.user1}/preferences`)
140-
.set('Authorization', `Bearer ${token.invalidRole}`)
141-
expect(res.status).to.equal(403)
142-
expect(res.body.message).to.equal('You are not allowed to perform this action!')
143-
})
144-
145137
it('Get user preferences using incorrect m2m token, return 403', async () => {
146138
const res = await chai.request(app)
147139
.get(`${config.API_VERSION}/users/${userId.user1}/preferences`)
@@ -348,13 +340,13 @@ describe('Topcoder - MemberPreferences API E2E Test', () => {
348340
expect(res.body.message).to.equal('You are not authorized to perform this action')
349341
})
350342

351-
it('Update user preferences user role is not allowed, return 403', async () => {
343+
it('Update user preferences, non admin user cannot update another users preferences, return 400', async () => {
352344
const res = await chai.request(app)
353345
.put(`${config.API_VERSION}/users/${userId.user1}/preferences`)
354346
.set('Authorization', `Bearer ${token.invalidRole}`)
355347
.send(reqBody.data)
356-
expect(res.status).to.equal(403)
357-
expect(res.body.message).to.equal('You are not allowed to perform this action!')
348+
expect(res.status).to.equal(400)
349+
expect(res.body.message).to.equal('The userId 305384 does not match the objectId 12345.')
358350
})
359351

360352
it('Update user preferences using incorrect m2m token, return 403', async () => {

0 commit comments

Comments
 (0)