Skip to content

Commit 0584c8b

Browse files
author
Andrew Isherwood
committed
Run Prettier across project
Prettier got disabled sometime recently, I have re-enabled it and run it across the project
1 parent 72071a4 commit 0584c8b

35 files changed

+422
-344
lines changed

api/v1.0/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,14 @@ const withoutJwt = [
3838
{ path: 'authtypes', router: authTypesRouter }
3939
];
4040

41-
withJwt.forEach(
42-
(aRoute) => router.use(
41+
withJwt.forEach((aRoute) =>
42+
router.use(
4343
`/${aRoute.path}`,
4444
(req, res, next) => postJwtAuth(req, res, next),
4545
aRoute.router
4646
)
4747
);
4848

49-
withoutJwt.forEach(
50-
(uRoute) => router.use(
51-
`/${uRoute.path}`,
52-
uRoute.router
53-
)
54-
);
49+
withoutJwt.forEach((uRoute) => router.use(`/${uRoute.path}`, uRoute.router));
5550

5651
module.exports = router;

api/v1.0/routes/authtypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ const authtypes = require('../../../controllers/authtypes');
44

55
router.get('/', authtypes.getAuthtypes);
66

7-
module.exports = router;
7+
module.exports = router;

api/v1.0/routes/messages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ router.put(
2727
queriesSideEffects.updatedQueriesToClients,
2828
foldersSideEffects.folderCountsToClients
2929
);
30-
router.delete('/:id',
30+
router.delete(
31+
'/:id',
3132
checkIsInRole('STAFF', 'CUSTOMER'),
3233
messages.deleteMessage,
3334
messagesSideEffects.deletedMessageToClients,

api/v1.0/routes/queries.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ router.delete(
5050
router.post(
5151
'/:query_id/label/:label_id',
5252
checkIsInRole('STAFF'),
53-
(req, res, next) =>
54-
querylabel.addRemove(req, res, next, 'addLabelToQuery'),
53+
(req, res, next) => querylabel.addRemove(req, res, next, 'addLabelToQuery'),
5554
queriesSideEffects.updatedQueriesToClients,
5655
labelsSideEffects.labelCountsToClients
5756
);

api/v1.0/routes/queryuser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ router.put(
1515
foldersSideEffects.folderCountsToClients
1616
);
1717

18-
module.exports = router;
18+
module.exports = router;

app.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ module.exports = {
4141
// We should only need CORS when in development, we want to not allow CORS
4242
// when in production as a partial mitigation against CSRF
4343
if (process.env.NODE_ENV === 'development') {
44-
app.use(cors((req, cb) => cb(null, {
45-
exposedHeaders: 'Authorization',
46-
credentials: true,
47-
origin: `${process.env.CLIENT_HOST}:${process.env.CLIENT_PORT}`
48-
})));
44+
app.use(
45+
cors((req, cb) =>
46+
cb(null, {
47+
exposedHeaders: 'Authorization',
48+
credentials: true,
49+
origin: `${process.env.CLIENT_HOST}:${process.env.CLIENT_PORT}`
50+
})
51+
)
52+
);
4953
}
5054
app.use(helmet());
5155
app.use(cookieParser());
@@ -57,12 +61,13 @@ module.exports = {
5761
// Configure how we are storing our file uploads
5862
const storage = multer.diskStorage({
5963
destination: (req, file, cb) => {
60-
cb(null, 'uploads')
64+
cb(null, 'uploads');
6165
},
6266
filename: (req, file, cb) => {
6367
const ext = path.extname(file.originalname);
6468
const filename = path.basename(file.originalname, ext);
65-
const suffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
69+
const suffix =
70+
Date.now() + '-' + Math.round(Math.random() * 1e9);
6671
cb(null, filename + '-' + suffix + ext);
6772
}
6873
});

auth/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ const strategies = require('./strategies');
55
// to consecutively pass 'app' to each of the strategies
66
// passed into 'functions'
77
const pipe = (...functions) => (args) =>
8-
functions.reduce((arg, fn) => fn(arg), args);
8+
functions.reduce((arg, fn) => fn(arg), args);
99

1010
// A wrapper middleware that applies each strategy that we will
1111
// need
1212
const initialiseAuthentication = (app) => {
13-
utils.setup()
14-
pipe(strategies.Google, strategies.Saml, strategies.Jwt)(app)
15-
}
13+
utils.setup();
14+
pipe(strategies.Google, strategies.Saml, strategies.Jwt)(app);
15+
};
1616

17-
module.exports = { utils, initialiseAuthentication, strategies }
17+
module.exports = { utils, initialiseAuthentication, strategies };

auth/strategies/google.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ const Google = (app) => {
3838
if (result.rowCount === 1) {
3939
done(null, result.rows[0]);
4040
} else {
41-
done('Error adding / updating user record in database', null);
41+
done(
42+
'Error adding / updating user record in database',
43+
null
44+
);
4245
}
4346
})
4447
.catch((err) => done(err, null));
@@ -49,31 +52,26 @@ const Google = (app) => {
4952
// Add our routes for forwarding to Google...
5053
app.get(
5154
'/auth/google',
52-
passport.authenticate(
53-
'google',
54-
{
55-
scope: [
56-
'https://www.googleapis.com/auth/userinfo.profile'
57-
]
58-
},
59-
)
55+
passport.authenticate('google', {
56+
scope: ['https://www.googleapis.com/auth/userinfo.profile']
57+
})
6058
);
6159

6260
// ...and returning from Google
6361
app.get(
6462
`/auth/google/callback`,
65-
passport.authenticate(
66-
'google',
67-
{
68-
failureRedirect: '/login',
69-
}
70-
),
63+
passport.authenticate('google', {
64+
failureRedirect: '/login'
65+
}),
7166
(req, res) => {
7267
// Generate a refresh token and redirect the useragent back to the client,
7368
// at which point they will use the refresh token to obtain a JWT
7469
const token = generateRefresh(req.user);
7570
addRefreshToken(res, token);
76-
const port = process.env.CLIENT_PORT.length > 0 ? `:${process.env.CLIENT_PORT}` : '';
71+
const port =
72+
process.env.CLIENT_PORT.length > 0
73+
? `:${process.env.CLIENT_PORT}`
74+
: '';
7775
return res.redirect(302, `${process.env.CLIENT_HOST}${port}`);
7876
}
7977
);

auth/strategies/jwt.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Jwt = () => {
99
const strategyOptions = {
1010
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
1111
secretOrKey: process.env.JWT_SECRET,
12-
passReqToCallback: true,
12+
passReqToCallback: true
1313
};
1414

1515
// The callback that passport-jwt calls once it has SUCCESSFULLY
@@ -22,9 +22,9 @@ const Jwt = () => {
2222
const jwtToken = getTokenFromRequest(req);
2323
try {
2424
verifyJwt(jwtToken);
25-
const user = await db.resolvers.users.getUser(
26-
{ params: { id: jwtPayload.sub } }
27-
);
25+
const user = await db.resolvers.users.getUser({
26+
params: { id: jwtPayload.sub }
27+
});
2828
if (user.rowCount === 1) {
2929
return done(null, user.rows[0]);
3030
} else {
@@ -35,7 +35,7 @@ const Jwt = () => {
3535
}
3636
};
3737

38-
passport.use(new JwtStrategy(strategyOptions, verifyCallback))
39-
}
38+
passport.use(new JwtStrategy(strategyOptions, verifyCallback));
39+
};
4040

41-
module.exports = Jwt;
41+
module.exports = Jwt;

auth/strategies/saml.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const { generateRefresh, addRefreshToken } = require('../../helpers/token');
77
const { samlConfig } = require('../utils');
88

99
const Saml = (app) => {
10-
1110
// Get the details we need from the config for creating
1211
// our strategy
1312
const { hasSaml, ENTRY_POINT, ISSUER_STRING, LOGOUT_URL } = samlConfig();
@@ -43,8 +42,8 @@ const Saml = (app) => {
4342
// to the async approach discussed in the bcrypt module's docs if this
4443
// becomes problematic. However, since this only gets called when a user
4544
// logs in, it's not going to be heavily hit
46-
const found = allUsers.rows.find(
47-
(user) => bcrypt.compareSync(uid, user.provider_id)
45+
const found = allUsers.rows.find((user) =>
46+
bcrypt.compareSync(uid, user.provider_id)
4847
);
4948

5049
// SAML can provide sensitive information as an identifier
@@ -72,33 +71,31 @@ const Saml = (app) => {
7271
})
7372
.catch((err) => done(err, null));
7473
});
75-
76-
}
74+
};
7775

7876
passport.use(new SamlStrategy(strategyOptions, verifyCallback));
7977

8078
// Add our routes for forwarding to the IdP...
81-
app.get('/auth/saml',
82-
passport.authenticate('saml')
83-
);
79+
app.get('/auth/saml', passport.authenticate('saml'));
8480

8581
// ...and returning from the IdP
86-
app.post('/auth/saml/callback',
87-
passport.authenticate(
88-
'saml',
89-
{
90-
failureRedirect: '/login'
91-
}
92-
),
82+
app.post(
83+
'/auth/saml/callback',
84+
passport.authenticate('saml', {
85+
failureRedirect: '/login'
86+
}),
9387
(req, res) => {
9488
// Generate a refresh token and redirect the useragent back to the client,
9589
// at which point they will use the refresh token to obtain a JWT
9690
const token = generateRefresh(req.user);
9791
addRefreshToken(res, token);
98-
const port = process.env.CLIENT_PORT.length > 0 ? `:${process.env.CLIENT_PORT}` : '';
92+
const port =
93+
process.env.CLIENT_PORT.length > 0
94+
? `:${process.env.CLIENT_PORT}`
95+
: '';
9996
return res.redirect(302, `${process.env.CLIENT_HOST}${port}`);
10097
}
10198
);
102-
}
99+
};
103100

104-
module.exports = Saml;
101+
module.exports = Saml;

auth/utils.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ const serializeCallback = (user, done) => done(null, user.provider_id);
66

77
const deserializeCallback = async ({ id }, done) => {
88
try {
9-
const user = await db.resolvers.users
10-
.getUser({ params: { id } });
11-
return done(null, user)
9+
const user = await db.resolvers.users.getUser({ params: { id } });
10+
return done(null, user);
1211
} catch (err) {
13-
return done(err, null)
12+
return done(err, null);
1413
}
1514
};
1615

@@ -29,7 +28,11 @@ const getAvailableAuthtypes = () => {
2928

3029
const { hasSaml, NAME: samlName, LOGOUT_ENDPOINT } = samlConfig();
3130
if (hasSaml) {
32-
availableMethods.push({ id: 'saml', name: samlName, logoutUrl: LOGOUT_ENDPOINT });
31+
availableMethods.push({
32+
id: 'saml',
33+
name: samlName,
34+
logoutUrl: LOGOUT_ENDPOINT
35+
});
3336
}
3437

3538
return availableMethods;
@@ -43,8 +46,8 @@ const googleConfig = () => {
4346
};
4447
return {
4548
...config,
46-
hasGoogle: (config.CLIENT_ID && config.CLIENT_SECRET) ? true : false
47-
}
49+
hasGoogle: config.CLIENT_ID && config.CLIENT_SECRET ? true : false
50+
};
4851
};
4952

5053
const samlConfig = () => {
@@ -56,17 +59,17 @@ const samlConfig = () => {
5659
};
5760

5861
const hasSaml = () => {
59-
return (
60-
config.ENTRY_POINT &&
62+
return config.ENTRY_POINT &&
6163
config.ISSUER_STRING &&
6264
config.LOGOUT_ENDPOINT
63-
) ? true : false;
65+
? true
66+
: false;
6467
};
6568

6669
return {
6770
...config,
6871
hasSaml: hasSaml()
69-
}
72+
};
7073
};
7174

7275
const checkIsInRole = (...roles) => (req, res, next) => {
@@ -75,7 +78,7 @@ const checkIsInRole = (...roles) => (req, res, next) => {
7578
res.send('User not found');
7679
return next();
7780
}
78-
const hasRole = roles.find(role => req.user.role_code === role);
81+
const hasRole = roles.find((role) => req.user.role_code === role);
7982
if (!hasRole) {
8083
res.status(401);
8184
res.send('Role not found');
@@ -93,4 +96,4 @@ module.exports = {
9396
samlConfig,
9497
getAvailableAuthtypes,
9598
checkIsInRole
96-
};
99+
};

classes/AuthCache.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ class AuthCache {
3131
// becomes problematic. However, since this only gets called when a user
3232
// logs out or refreshes their token, it's not going to be heavily hit
3333
findByToken(token) {
34-
return Object.keys(this.cache)
35-
.find((key) => bcrypt.compareSync(token, this.cache[key].token));
34+
return Object.keys(this.cache).find((key) =>
35+
bcrypt.compareSync(token, this.cache[key].token)
36+
);
3637
}
3738
}
3839

classes/WebsocketServer.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,24 @@ class WebsocketServer {
2525
// to the client object, this will enable us to
2626
// target messages
2727
socketClient.userId = sub;
28-
console.log(`WS client connected, ${this.socketServer.clients.size} clients connected`);
28+
console.log(
29+
`WS client connected, ${this.socketServer.clients.size} clients connected`
30+
);
2931
socketClient.on('close', () => {
30-
console.log(`WS client disconnected, ${this.socketServer.clients.size} clients connected`);
32+
console.log(
33+
`WS client disconnected, ${this.socketServer.clients.size} clients connected`
34+
);
3135
});
3236
} catch (err) {
3337
console.log('WS client unauthorised, closing connection');
3438
socketClient.close();
3539
}
36-
})
40+
});
3741
}
3842
// Return an array of all connected client user IDs
3943
connectedClientUserIds() {
4044
const ids = [];
41-
this.socketServer.clients.forEach(
42-
(client) => ids.push(client.userId)
43-
);
45+
this.socketServer.clients.forEach((client) => ids.push(client.userId));
4446
return ids;
4547
}
4648
// Send a message to all available clients
@@ -95,4 +97,4 @@ class WebsocketServer {
9597

9698
const singleton = new WebsocketServer();
9799

98-
module.exports = singleton;
100+
module.exports = singleton;

0 commit comments

Comments
 (0)