diff --git a/src/services/helpers/hash.js b/src/services/helpers/hash.js index ad933e48234..c978477058a 100644 --- a/src/services/helpers/hash.js +++ b/src/services/helpers/hash.js @@ -1,5 +1,4 @@ const bcrypt = require('bcryptjs'); -const { promisify } = require('es6-promisify'); const { BadRequest } = require('../../errors'); const { userModel } = require('../user/model'); const { getRandomInt } = require('../../utils/randomNumberGenerator'); @@ -43,21 +42,19 @@ const rndChar = () => { }; module.exports = function setup() { - const genSaltAsync = promisify(bcrypt.genSalt); - const genHashAsync = promisify(bcrypt.hash); class HashService { constructor(options) { this.options = options || {}; this.docs = {}; } - async create(data, params) { + async create(data) { if (data.toHash === undefined) { throw new BadRequest('Please set toHash key.'); } - const salt = await genSaltAsync(8); + const salt = await bcrypt.genSalt(8); - let hash = await genHashAsync(data.toHash, salt); + let hash = await bcrypt.hash(data.toHash, salt); if (data.save === true || data.save === 'true') { hash = hash.replace(/\/|\$|\./g, rndChar()); diff --git a/src/utils/redis.js b/src/utils/redis.js index 550a728415e..1a8d085fc09 100644 --- a/src/utils/redis.js +++ b/src/utils/redis.js @@ -1,4 +1,3 @@ -const { promisify } = require('util'); const Redis = require('ioredis'); const { Configuration } = require('@hpi-schul-cloud/commons'); @@ -32,19 +31,19 @@ function setRedisClient(client) { } const redisGetAsync = (...args) => { - if (redisClient) return promisify(redisClient.get).apply(redisClient, args); + if (redisClient) return redisClient.get(...args); throw new GeneralError('No redis connection. Check for this via getRedisClient().'); }; const redisSetAsync = (...args) => { - if (redisClient) return promisify(redisClient.set).apply(redisClient, args); + if (redisClient) return redisClient.set(...args); throw new GeneralError('No redis connection. Check for this via getRedisClient().'); }; const redisDelAsync = (...args) => { - if (redisClient) return promisify(redisClient.del).apply(redisClient, args); + if (redisClient) return redisClient.del(...args); throw new GeneralError('No redis connection. Check for this via getRedisClient().'); }; const redisTtlAsync = (...args) => { - if (redisClient) return promisify(redisClient.ttl).apply(redisClient, args); + if (redisClient) return redisClient.ttl(...args); throw new GeneralError('No redis connection. Check for this via getRedisClient().'); }; diff --git a/test/utils/redis/redisMock.js b/test/utils/redis/redisMock.js index f0e6c19d40f..8bc84ef4fff 100644 --- a/test/utils/redis/redisMock.js +++ b/test/utils/redis/redisMock.js @@ -2,10 +2,9 @@ const valueDict = {}; const ttlDict = {}; const RedisClientMock = class { - get(key, ...args) { + get(key) { const value = valueDict[key]; - const callback = args[args.length - 1]; - callback(null, value); + return Promise.resolve(value); } set(key, value, ...args) { @@ -14,21 +13,18 @@ const RedisClientMock = class { if (ex >= 0) { ttlDict[key] = args[ex + 1]; } - const callback = args[args.length - 1]; - callback(null, true); + return Promise.resolve(true); } - del(key, ...args) { + del(key) { delete valueDict[key]; delete ttlDict[key]; - const callback = args[args.length - 1]; - callback(null, true); + return Promise.resolve(true); } - ttl(key, ...args) { + ttl(key) { const ttl = ttlDict[key]; - const callback = args[args.length - 1]; - callback(null, ttl); + return Promise.resolve(ttl); } };