Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions app-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ module.exports = (app) => {
}
})

if (def.forbiddenCountries) {
actions.push(async (req, res, next) => {
if (req.authUser.isMachine) {
next()
if (def.blockByIp) {
actions.push((req, res, next) => {
req.authUser.blockIP = _.find(req.authUser, (value, key) => {
return (key.indexOf('blockIP') !== -1)
})
if (req.authUser.blockIP) {
throw new errors.ForbiddenError('Access denied')
} else {
req.authUser.userId = String(req.authUser.userId)
const user = await helper.getMemberById(req.authUser.userId)
if (!user || _.intersection([user.homeCountryCode, user.competitionCountryCode], def.forbiddenCountries).length > 0) {
throw new errors.ForbiddenError('Access denied')
}
next()
}
})
Expand Down
22 changes: 1 addition & 21 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,5 @@ module.exports = {
RESOURCE_ROLE_CREATE_TOPIC: process.env.RESOURCE_ROLE_CREATE_TOPIC || 'challenge.action.resource.role.create',
RESOURCE_ROLE_UPDATE_TOPIC: process.env.RESOURCE_ROLE_UPDATE_TOPIC || 'challenge.action.resource.role.update',

AUTOMATED_TESTING_NAME_PREFIX: process.env.AUTOMATED_TESTING_NAME_PREFIX || 'POSTMANE2E-',

FORBIDDEN_COUNTRIES: [
'Iran',
'North Korea',
'Cuba',
'Sudan',
'Syria',
'Belarus',
'Russia',
'Russian Federation'
],
FORBIDDEN_COUNTRIES_ALPHA_3: [
'IRN',
'PRK',
'CUB',
'SDN', 'SSD', // (south sudan)
'SYR',
'BLR',
'RUS'
]
AUTOMATED_TESTING_NAME_PREFIX: process.env.AUTOMATED_TESTING_NAME_PREFIX || 'POSTMANE2E-'
}
9 changes: 7 additions & 2 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,13 @@ async function getMemberInfoById (id) {
* @returns {Promise<void>}
*/
async function getMemberById (id) {
const res = await getRequest(`${config.MEMBER_API_URL}?userId=${id}`)
return _.get(res, 'data[0]')
try {
const res = await getRequest(`${config.MEMBER_API_URL}`, { userId: id })
return _.get(res, 'body[0]')
} catch (e) {
logger.debug(e.message)
logger.debug(e)
}
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

const constants = require('../app-constants')
const {
SCOPES: { READ, CREATE, DELETE, UPDATE, ALL },
FORBIDDEN_COUNTRIES,
FORBIDDEN_COUNTRIES_ALPHA_3
SCOPES: { READ, CREATE, DELETE, UPDATE, ALL }
} = require('config')

module.exports = {
Expand All @@ -25,7 +23,7 @@ module.exports = {
auth: 'jwt',
access: [constants.UserRoles.Admin, constants.UserRoles.Copilot, constants.UserRoles.Manager, constants.UserRoles.User],
scopes: [CREATE, ALL],
forbiddenCountries: [...FORBIDDEN_COUNTRIES, ...FORBIDDEN_COUNTRIES_ALPHA_3]
blockByIp: true
},
delete: {
controller: 'ResourceController',
Expand Down