fix(ci): Fix lint errors thrown in CI
This commit is contained in:
committed by
mrugesh mohapatra
parent
3f25ed051d
commit
c0104faa38
@ -1,3 +1,4 @@
|
|||||||
|
/* global describe xdescribe it expect */
|
||||||
import { isWhiteListedPath } from './jwt-authorization';
|
import { isWhiteListedPath } from './jwt-authorization';
|
||||||
|
|
||||||
describe('jwt-authorization', () => {
|
describe('jwt-authorization', () => {
|
||||||
@ -25,5 +26,5 @@ describe('jwt-authorization', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
xdescribe('authorizeByJWT')
|
xdescribe('authorizeByJWT');
|
||||||
});
|
});
|
||||||
|
@ -12,21 +12,19 @@ const apiProxyRE = /^\/internal\/|^\/external\//;
|
|||||||
const newsShortLinksRE = /^\/internal\/n\/|^\/internal\/p\?/;
|
const newsShortLinksRE = /^\/internal\/n\/|^\/internal\/p\?/;
|
||||||
const loopbackAPIPathRE = /^\/internal\/api\//;
|
const loopbackAPIPathRE = /^\/internal\/api\//;
|
||||||
|
|
||||||
const _whiteListREs = [
|
const _whiteListREs = [newsShortLinksRE, loopbackAPIPathRE];
|
||||||
newsShortLinksRE,
|
|
||||||
loopbackAPIPathRE
|
|
||||||
];
|
|
||||||
|
|
||||||
export function isWhiteListedPath(path, whiteListREs= _whiteListREs) {
|
export function isWhiteListedPath(path, whiteListREs = _whiteListREs) {
|
||||||
return whiteListREs.some(re => re.test(path))
|
return whiteListREs.some(re => re.test(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default () =>
|
||||||
export default () => function authorizeByJWT(req, res, next) {
|
function authorizeByJWT(req, res, next) {
|
||||||
const { path } = req;
|
const { path } = req;
|
||||||
if (apiProxyRE.test(path) && !isWhiteListedPath(path)) {
|
if (apiProxyRE.test(path) && !isWhiteListedPath(path)) {
|
||||||
const cookie = req.signedCookies && req.signedCookies['jwt_access_token'] ||
|
const cookie =
|
||||||
req.cookie && req.cookie['jwt_access_token'];
|
(req.signedCookies && req.signedCookies['jwt_access_token']) ||
|
||||||
|
(req.cookie && req.cookie['jwt_access_token']);
|
||||||
|
|
||||||
if (!cookie) {
|
if (!cookie) {
|
||||||
throw wrapHandledError(
|
throw wrapHandledError(
|
||||||
@ -43,28 +41,24 @@ export default () => function authorizeByJWT(req, res, next) {
|
|||||||
try {
|
try {
|
||||||
token = jwt.verify(cookie, process.env.JWT_SECRET);
|
token = jwt.verify(cookie, process.env.JWT_SECRET);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw wrapHandledError(
|
throw wrapHandledError(new Error(err.message), {
|
||||||
new Error(err.message),
|
|
||||||
{
|
|
||||||
type: 'info',
|
type: 'info',
|
||||||
redirect: `${homeLocation}/signin`,
|
redirect: `${homeLocation}/signin`,
|
||||||
message: 'Your access token is invalid',
|
message: 'Your access token is invalid',
|
||||||
status: 403
|
status: 403
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
const {
|
||||||
}
|
accessToken: { created, ttl, userId }
|
||||||
const { accessToken: {created, ttl, userId }} = token;
|
} = token;
|
||||||
const valid = isBefore(Date.now(), Date.parse(created) + ttl);
|
const valid = isBefore(Date.now(), Date.parse(created) + ttl);
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
throw wrapHandledError(
|
throw wrapHandledError(new Error('Access token is no longer vaild'), {
|
||||||
new Error('Access token is no longer vaild'),
|
|
||||||
{
|
|
||||||
type: 'info',
|
type: 'info',
|
||||||
redirect: `${homeLocation}/signin`,
|
redirect: `${homeLocation}/signin`,
|
||||||
message: 'Access token is no longer vaild',
|
message: 'Access token is no longer vaild',
|
||||||
status: 403
|
status: 403
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
const User = loopback.getModelByType('User');
|
const User = loopback.getModelByType('User');
|
||||||
@ -83,4 +77,4 @@ export default () => function authorizeByJWT(req, res, next) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return next();
|
return next();
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
const base = `/internal`;
|
const base = '/internal';
|
||||||
|
|
||||||
function get(path) {
|
function get(path) {
|
||||||
return axios.get(`${base}${path}`);
|
return axios.get(`${base}${path}`);
|
||||||
@ -46,7 +46,6 @@ export function getArticleById(shortId) {
|
|||||||
|
|
||||||
/** POST **/
|
/** POST **/
|
||||||
|
|
||||||
|
|
||||||
export function postReportUser(body) {
|
export function postReportUser(body) {
|
||||||
return post('/user/report-user', body);
|
return post('/user/report-user', body);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user